def test_commit_failed_in_updating_lifetime(self): mock_api = MagicMock() datalake_file = DatalakeFile( mock_api, uri=self.uri, type=type, metadata={'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg'}) file_info = { 'url_expires_on': '2018-06-04T05:04:46+00:00', 'uploaded_at': '2018-06-01T05:22:44+00:00', 'metadata': { 'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg' }, 'file_id': self.file_id, 'download_uri': 'https://example.com/dummy_download_uri', 'content_type': 'image/jpeg' } datalake_file.get_file_info = MagicMock(return_value=file_info) mock_api.put_channel_file_lifetime.side_effect = HttpError( error='bad_request', error_description='bad request', status_code=400, url='dummy') datalake_file.metadata['label'] = 'cat' datalake_file.lifetime = '1week' with self.assertRaises(HttpError): datalake_file.commit() mock_api.put_channel_file_lifetime.assert_called_once_with( self.channel_id, self.file_id, lifetime='1week') self.assertEqual(mock_api.put_channel_file_metadata.call_count, 2) call_args = mock_api.put_channel_file_metadata.call_args_list expected_metadata = { 'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg', 'x-abeja-meta-label': 'cat' } self.assertListEqual(list(call_args[0]), [(self.channel_id, self.file_id), { 'metadata': expected_metadata }]) expected_metadata = {'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg'} self.assertListEqual(list(call_args[1]), [(self.channel_id, self.file_id), { 'metadata': expected_metadata }])
def test_commit_without_changes(self): mock_api = MagicMock() datalake_file = DatalakeFile( mock_api, uri=self.uri, type=type, metadata={'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg'}) file_info = { 'url_expires_on': '2018-06-04T05:04:46+00:00', 'uploaded_at': '2018-06-01T05:22:44+00:00', 'metadata': { 'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg' }, 'file_id': self.file_id, 'download_uri': 'https://example.com/dummy_download_uri', 'content_type': 'image/jpeg' } datalake_file.get_file_info = MagicMock(return_value=file_info) self.assertTrue(datalake_file.commit()) expected_metadata = { 'x-abeja-meta-filename': 'DcZzLGkV4AA8FQc.jpg', } mock_api.put_channel_file_metadata.assert_called_once_with( self.channel_id, self.file_id, metadata=expected_metadata) mock_api.put_channel_file_lifetime.assert_not_called()