def test_create_tsv_row_non_none_if_req_fields( default_image_args, get_good, setup_env, ): image_store = image.ImageStore() test_image = image.Image(**default_image_args) actual_row = image_store._create_tsv_row(test_image) assert actual_row is not None
def test_create_tsv_row_returns_none_if_missing_image_url( default_image_args, setup_env, ): image_store = image.ImageStore() image_args = default_image_args image_args['image_url'] = None test_image = image.Image(**image_args) expect_row = None actual_row = image_store._create_tsv_row(test_image) assert expect_row == actual_row
def test_create_tsv_row_none_if_no_license_version( default_image_args, setup_env, ): image_store = image.ImageStore() image_args = default_image_args image_args['license_version'] = None test_image = image.Image(**image_args) expect_row = None actual_row = image_store._create_tsv_row(test_image) assert expect_row == actual_row
def test_create_tsv_row_none_if_no_foreign_landing_url( default_image_args, setup_env, ): image_store = image.ImageStore() image_args = default_image_args image_args['foreign_landing_url'] = None test_image = image.Image(**image_args) expect_row = None actual_row = image_store._create_tsv_row(test_image) assert expect_row == actual_row
def test_create_tsv_row_turns_empty_into_nullchar( default_image_args, setup_env, ): image_store = image.ImageStore() image_args = default_image_args test_image = image.Image(**image_args) actual_row = image_store._create_tsv_row(test_image).split('\t') assert all([ actual_row[i] == '\\N' for i in [0, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15] ]) is True assert actual_row[-1] == '\\N\n'
def test_ImageStore_get_image_places_given_args(monkeypatch, setup_env): image_store = image.ImageStore(provider='testing_provider') args_dict = { 'foreign_landing_url': 'https://landing_page.com', 'image_url': 'http://imageurl.com', 'license_': 'testlicense', 'license_version': '1.0', 'license_url': None, 'foreign_identifier': 'foreign_id', 'thumbnail_url': 'http://thumbnail.com', 'width': 200, 'height': 500, 'creator': 'tyler', 'creator_url': 'https://creatorurl.com', 'title': 'agreatpicture', 'meta_data': { 'description': 'cat picture' }, 'raw_tags': [{ 'name': 'tag1', 'provider': 'testing' }], 'watermarked': 'f', 'source': 'testing_source' } def mock_license_chooser(license_url, license_, license_version): return image.licenses.LicenseInfo(license_, license_version, license_url) monkeypatch.setattr(image.licenses, 'get_license_info', mock_license_chooser) def mock_get_source(source, provider): return source monkeypatch.setattr(image.util, 'get_source', mock_get_source) def mock_enrich_tags(tags): return tags monkeypatch.setattr(image_store, '_enrich_tags', mock_enrich_tags) actual_image = image_store._get_image(**args_dict) args_dict['tags'] = args_dict.pop('raw_tags') args_dict.pop('license_url') args_dict['provider'] = 'testing_provider' args_dict['filesize'] = None assert actual_image == image.Image(**args_dict)
def test_create_tsv_row_properly_places_entries(setup_env, monkeypatch): def mock_validate_url(url_string): return url_string monkeypatch.setattr(image.columns.urls, 'validate_url_string', mock_validate_url) image_store = image.ImageStore() req_args_dict = { 'foreign_landing_url': 'https://landing_page.com', 'image_url': 'http://imageurl.com', 'license_': 'testlicense', 'license_version': '1.0', } args_dict = { 'foreign_identifier': 'foreign_id', 'thumbnail_url': 'http://thumbnail.com', 'width': 200, 'height': 500, 'filesize': None, 'creator': 'tyler', 'creator_url': 'https://creatorurl.com', 'title': 'agreatpicture', 'meta_data': { 'description': 'cat picture' }, 'tags': [{ 'name': 'tag1', 'provider': 'testing' }], 'watermarked': 'f', 'provider': 'testing_provider', 'source': 'testing_source' } args_dict.update(req_args_dict) test_image = image.Image(**args_dict) actual_row = image_store._create_tsv_row(test_image) expect_row = '\t'.join([ 'foreign_id', 'https://landing_page.com', 'http://imageurl.com', 'http://thumbnail.com', '200', '500', '\\N', 'testlicense', '1.0', 'tyler', 'https://creatorurl.com', 'agreatpicture', '{"description": "cat picture"}', '[{"name": "tag1", "provider": "testing"}]', 'f', 'testing_provider', 'testing_source' ]) + '\n' assert expect_row == actual_row
def test_create_tsv_row_handles_empty_dict_and_tags( default_image_args, setup_env, ): image_store = image.ImageStore() meta_data = {} tags = [] image_args = default_image_args image_args['meta_data'] = meta_data image_args['tags'] = tags test_image = image.Image(**image_args) actual_row = image_store._create_tsv_row(test_image).split('\t') actual_meta_data, actual_tags = actual_row[12], actual_row[13] expect_meta_data, expect_tags = '\\N', '\\N' assert expect_meta_data == actual_meta_data assert expect_tags == actual_tags