Exemplo n.º 1
0
 def test_execute(self, mock_hook):
     mock_instance = mock_hook.return_value
     operator = LocalFilesystemToGCSOperator(task_id='gcs_to_file_sensor',
                                             dag=self.dag,
                                             **self._config)
     operator.execute(None)
     mock_instance.upload.assert_called_once_with(
         bucket_name=self._config['bucket'],
         filename=self._config['src'],
         gzip=self._config['gzip'],
         mime_type=self._config['mime_type'],
         object_name=self._config['dst'])
Exemplo n.º 2
0
 def test_execute_negative(self, mock_hook):
     mock_instance = mock_hook.return_value
     operator = LocalFilesystemToGCSOperator(
         task_id='gcs_to_file_sensor',
         dag=self.dag,
         src='/tmp/fake*.csv',
         dst='test/test1.csv',
         **self._config,
     )
     print(glob('/tmp/fake*.csv'))
     with pytest.raises(ValueError):
         operator.execute(None)
     mock_instance.assert_not_called()
 def test_execute_wildcard(self, mock_hook):
     mock_instance = mock_hook.return_value
     operator = LocalFilesystemToGCSOperator(
         task_id='gcs_to_file_sensor', dag=self.dag, src='/tmp/fake*.csv', dst='test/', **self._config
     )
     operator.execute(None)
     object_names = ['test/' + os.path.basename(fp) for fp in glob('/tmp/fake*.csv')]
     files_objects = zip(glob('/tmp/fake*.csv'), object_names)
     calls = [
         mock.call(
             bucket_name=self._config['bucket'],
             filename=filepath,
             gzip=self._config['gzip'],
             mime_type=self._config['mime_type'],
             object_name=object_name,
         )
         for filepath, object_name in files_objects
     ]
     mock_instance.upload.assert_has_calls(calls)
 def test_execute_multiple(self, mock_hook):
     mock_instance = mock_hook.return_value
     operator = LocalFilesystemToGCSOperator(
         task_id='gcs_to_file_sensor', dag=self.dag, src=self.testfiles, dst='test/', **self._config
     )
     operator.execute(None)
     files_objects = zip(
         self.testfiles, ['test/' + os.path.basename(testfile) for testfile in self.testfiles]
     )
     calls = [
         mock.call(
             bucket_name=self._config['bucket'],
             filename=filepath,
             gzip=self._config['gzip'],
             mime_type=self._config['mime_type'],
             object_name=object_name,
         )
         for filepath, object_name in files_objects
     ]
     mock_instance.upload.assert_has_calls(calls)