You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/02 17:13:25 UTC

[GitHub] [airflow] JavierLopezT commented on issue #6670: [AIRFLOW-4816]MySqlToS3Operator

JavierLopezT commented on issue #6670: [AIRFLOW-4816]MySqlToS3Operator
URL: https://github.com/apache/airflow/pull/6670#issuecomment-593511992
 
 
   I am stucked again with the test. Could you help me please? Sorry for bothering again
    ```
   AssertionError: Expected call: load_file(bucket_name='bucket', filename=<MagicMock name='NamedTemporaryFile.__enter__.name' id='140026932181872'>, key='key')
   Actual call: load_file(bucket_name='bucket', filename=<MagicMock name='NamedTemporaryFile().__enter__().name' id='140026915240536'>, key='key')
   ```
   The code in the operator is:
   ```
   with tempfile.NamedTemporaryFile(mode='r+', suffix='.csv') as tmp_csv:
               tmp_csv.file.write(data_df.to_csv(index=self.index, header=self.header))
               tmp_csv.file.seek(0)
               s3_conn.load_file(filename=tmp_csv.name,
                                 key=self.s3_key,
                                 bucket_name=self.s3_bucket)
   ```
   And the testing code (its latest version) is:
   @mock.patch("airflow.operators.mysql_to_s3_operator.tempfile.NamedTemporaryFile")
   ...
   ```
   temp_mock.assert_called_once_with(mode='r+', suffix=".csv")
           temp_mock.return_value.__enter__.return_value.name = "file"
           mock_s3_hook.return_value.load_file.assert_called_once_with(filename=temp_mock.__enter__.name,
                                                                       key=s3_key,
                                                                       bucket_name=s3_bucket)
   ```
   I have tried also with:
   ```
   mock_s3_hook.return_value.load_file.assert_called_once_with(filename="file",
                                                                       key=s3_key,
                                                                       bucket_name=s3_bucket)
   ```
   and
   ```
   mock_s3_hook.return_value.load_file.assert_called_once_with(filename=temp_mock.name,
                                                                       key=s3_key,
                                                                       bucket_name=s3_bucket)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services