def test_files_below_items_per_page(self): mock_api = Mock() mock_api.list_channel_files.side_effect = [{ 'next_page_token': None, 'files': [{ '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': '20180601T052244-250482c0-d361-4c5b-a0f9-e796af1a5f0d', 'download_uri': 'http://example/dummy/donwload_url', 'content_type': 'image/jpeg' }] }] channel = Channel(mock_api, ORGANIZATION_ID, CHANNEL_ID) self.assertIsInstance(channel, Channel) files = list(channel.list_files()) for file in files: self.assertIsInstance(file, DatalakeFile) self.assertEqual(mock_api.list_channel_files.call_count, 1) self.assertEqual(mock_api.list_channel_files.call_args[0][0], CHANNEL_ID) self.assertEqual(len(files), 1)
def test_files_with_empty_items(self): mock_api = Mock() mock_api.list_channel_files.side_effect = [{ 'next_page_token': None, 'files': [] }] channel = Channel(mock_api, ORGANIZATION_ID, CHANNEL_ID) self.assertIsInstance(channel, Channel) files = list(channel.list_files()) self.assertEqual(len(files), 0)
def test_files_with_both_items_per_page_and_next_page_token(self): mock_api = Mock() mock_api.list_channel_files.side_effect = [{ 'next_page_token': 'dummy', 'files': [{ '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': '20180601T052244-250482c0-d361-4c5b-a0f9-e796af1a5f0d', 'download_uri': 'http://example/dummy/donwload_url', 'content_type': 'image/jpeg' }] }, { 'next_page_token': None, 'files': [{ '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': '20180601T052244-250482c0-d361-4c5b-a0f9-e796af1a5f0d', 'download_uri': 'http://example/dummy/donwload_url', 'content_type': 'image/jpeg' }] }] channel = Channel(mock_api, ORGANIZATION_ID, CHANNEL_ID) self.assertIsInstance(channel, Channel) files = list(channel.list_files(limit=1)) for file in files: self.assertIsInstance(file, DatalakeFile) self.assertEqual(mock_api.list_channel_files.call_count, 2) call_args_1 = mock_api.list_channel_files.call_args_list[0] self.assertTupleEqual(call_args_1[0], (CHANNEL_ID, )) self.assertDictEqual(call_args_1[1], {'items_per_page': 1}) call_args_2 = mock_api.list_channel_files.call_args_list[1] self.assertTupleEqual(call_args_2[0], (CHANNEL_ID, )) # items_per_page should not be passed as query parameter self.assertDictEqual(call_args_2[1], {'next_page_token': 'dummy'}) self.assertEqual(len(files), 2)