def test_description_transform2(): INPUT = {"metadata": {"mods": {"note": {"#text": "A description"}}}} EXPECTED = {"description": "A description"} resp, content = _get_server_response(json.dumps(INPUT), provider="HARVARD") assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content)["sourceResource"])
def test_geocode_set_name_by_feature(): """Should set the name property to the smallest available feature value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "country": "Canada", "city": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ 'coordinates': '62.8329086304, -95.9133224487', 'country': 'Canada', 'name': 'Bananas', 'state': 'Nunavut', "city": "Bananas" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_contentdm_identify_object_usc(): """ Should add a thumbnail URL made of the source URL. """ INPUT = { u"something": "x", u"somethink": "y", u"originalRecord": {"handle": ["aaa", "http://some.url/cdm/ref/12345"] }, u"left": "right now!" } EXPECTED = { u"something": "x", u"somethink": "y", u"originalRecord": { "handle": ["aaa", "http://some.url/cdm/ref/12345"] }, u"object": ("http://some.url/utils/getthumbnail/12345"), u"admin": {u"object_status": 0}, u"left": "right now!" } url = contentdm_url("False") resp, content = H.request(url, "POST", body=json.dumps(INPUT)) print_error_log() assert str(resp.status).startswith("2") result = json.loads(content) assert_same_jsons(EXPECTED, result)
def test_remove_type(): """Should remove type""" INPUT = {"id": "123", "sourceResource": {"type": "bananas"}} EXPECTED = {"id": "123", "sourceResource": {}} resp, content = _get_server_response(json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_not_remove_valid_date_dict(): INPUT = { "sourceResource": { "date": { "begin": "1959-01-01", "end": "1959-01-01", "displayDate": "1959-01-01" }, } } EXPECTED_OUTPUT = { "sourceResource": { "date": { "begin": "1959-01-01", "end": "1959-01-01", "displayDate": "1959-01-01" }, } } resp, content = _get_server_response(INPUT) print_error_log() assert resp["status"].startswith("2") assert_same_jsons(EXPECTED_OUTPUT, content)
def test_prop_doesnt_exist(): """Should return original JSON when prop doesn't exist.""" x = {"aaa": "BBB"} r, c = _get_server_response(json.dumps(x), 'aaa%2Fddd') pinfo(x, r, c) print_error_log() assert_same_jsons(c, x)
def test_geocode_do_not_skip_united_states(): """Should geocode when name value is 'United States' is followed by a '-' """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": {"name": "United States--California"} } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "coordinates": "37.25022, -119.75126", "country": "United States", "name": "United States--California", "state": "California" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_unicode(): """Should handle unicode values """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": u"États-Unis" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": u"États-Unis" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_state(): """Should set the name property to the state value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "state": "California" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ 'coordinates': '37.25022, -119.75126', "country": "United States", "state": "California", "name": "California" }] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_by_feature(): """Should set the name property to the smallest available feature value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "country": "Canada", "city": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ 'coordinates': '62.8329086304, -95.9133224487', 'country': 'Canada', 'name': 'Bananas', 'state': 'Nunavut', "city": "Bananas" }] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_region(): """Should set the name property to the region value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "region": "Ecuador" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "region": "Ecuador", "name": "Ecuador", "country": "Ecuador" } ] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_county(): """Should set the name property to the county value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "county": "Los Angeles County", "country": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "county": "Los Angeles County", "country": "Bananas", "name": "Los Angeles County", "state": "California", #uses bing because geonames wants to match country values "coordinates": "33.9934997559, -118.29750824" } ] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_city(): """Should set the name property to the city value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "city": "Los Angeles", "state": "California" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "coordinates": '34.05223, -118.24368', "city": "Los Angeles", 'county': 'Los Angeles County', "state": "California", "country": "United States", "name": "Los Angeles" } ] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_exclude_coordinates_from_countries(): """Should not include coordinates or smaller administrative units in country enhancements """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "Greece" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "country": "Greece", "name": "Greece" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_exclude_coordinates_from_countries(): """Should not include coordinates or smaller administrative units in country enhancements """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": {"name": "Greece"} } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "country": "Greece", "name": "Greece" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_geonames_name_search_context(): """Should find a place name, only if matching other data. """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "Portland", "state": "Maine" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "county": "Cumberland County", "country": "United States", "state": "Maine", "name": "Portland", "coordinates": "43.66147, -70.25533" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_geonames_name_search(): """Should find a place name. """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": {"name": "Portland, OR"} } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "county": "Multnomah County", "country": "United States", "state": "Oregon", "name": "Portland, OR", "coordinates": "45.52345, -122.67621" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_cleanup_enrich_then_lookup1(): """Should produce both name and iso639_3 language fields""" INPUT = ["en", "English", ["eng"], ["English"], ["en", "English"]] EXPECTED = { "sourceResource": { "language": [{ "name": "English", "iso639_3": "eng" }] } } for i in range(len(INPUT)): input = {"sourceResource": {"language": INPUT[i]}} url = server() + "cleanup_language" resp, content = H.request(url, "POST", json.dumps(input)) assert resp.status == 200 url = server() + "enrich_language" resp, content = H.request(url, "POST", content) assert resp.status == 200 url = server() + "lookup?prop=sourceResource%2Flanguage%2Fname" + \ "&target=sourceResource%2Flanguage%2Fname&substitution=iso639_3" resp, content = H.request(url, "POST", content) assert resp.status == 200 url = server() + "lookup?prop=sourceResource%2Flanguage%2Fname" + \ "&target=sourceResource%2Flanguage%2Fiso639_3" + \ "&substitution=iso639_3&inverse=True" resp, content = H.request(url, "POST", content) assert resp.status == 200 assert_same_jsons(content, EXPECTED)
def test_geocode_geonames_name_search_context(): """Should find a place name, only if matching other data. """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "Portland", "state": "Maine" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "county": "Cumberland County", "country": "United States", "state": "Maine", "name": "Portland", "coordinates": "43.66147, -70.25533" } ]} } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_uiuc_cleanup_spatial_name1(): INPUT = { "sourceResource": { "spatial": [{ "state": "US-CA", "name": "California" }, { "state": "US-CA", "name": "\n\n\n \nCalifornia" }] } } EXPECTED = { "sourceResource": { "spatial": [{ "state": "US-CA", "name": "California" }, { "state": "US-CA", "name": "California" }] } } resp, content = _get_server_response(json.dumps(INPUT)) assert resp["status"] == "200" assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_geonames_name_search_failure(): """Shouldn't fall down when nothing is returned. """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "1234567" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": "1234567" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_set_type_from_physical_format3(): """Should not set type""" INPUT = {"sourceResource": {"format": ["format"]}} resp, content = _get_server_response(json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(INPUT, content)
def test_suppress_creator_value_for_string(): """Should remove creator value if the is 'creator'.""" INPUT = { "sourceResource": { "creator": "creator", "aaa": [ "Fisker, Kay--Architect--Danish--Male", "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc" ] } } EXPECTED_OUTPUT = { "sourceResource": { "aaa": [ "Fisker, Kay--Architect--Danish--Male", "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc" ] } } resp, content = _get_server_response(json.dumps(INPUT)) print_error_log() assert resp["status"].startswith("2") assert_same_jsons(EXPECTED_OUTPUT, content)
def test_georgia_set_spec_type(): """Should set the specType to include Book, Government Document, and Serial """ INPUT = { "sourceResource": { "type": [ "something Books", " GOVERNMENT something", " Something periodicals", " Another periodicals" ] } } EXPECTED = { "sourceResource": { "type": [ "something Books", " GOVERNMENT something", " Something periodicals", " Another periodicals" ], "specType": [ "Book", "Government Document", "Serial" ] } } resp, content = _get_server_response(json.dumps(INPUT)) print_error_log() assert resp["status"] == "200" assert_same_jsons(EXPECTED, json.loads(content))
def test_strip_html(): """'strip_html' strips HTML tags and entities recursively""" request_data = { 'a': { 'b': [' <i>string</i> <b>one</b> \n \t', 'string < two '] }, 'c': ' \n <p>string three</p>', 'd': {}, 'e': 1, 'f': '1 film negative: b&w ;' } expected_result = { 'a': { 'b': [u'string one', u'string < two'] }, 'c': u'string three', 'd': {}, # unaltered 'e': 1, # unaltered 'f': '1 film negative: b&w ;' #unaltered } url = server() + 'strip_html' resp_meta, resp_body = H.request(url, 'POST', body=json.dumps(request_data)) assert resp_meta.status == 200 assert_same_jsons(expected_result, resp_body)
def test_populating_publisher_field(): INPUT = { "freetext": { "publisher": [ { "#text": "Glossary of Coins and Currency Terms", "@label": "Publication title" }, { "#text": "http://americanhistory.si.edu/coins/glossary.cfm", "@label": "Publication URL" }, { "#text": "xx", "@label": "Publisher" } ], } } EXPECTED_PUBLISHER = { "publisher": ["xx"] } resp, content = _get_server_response(INPUT) print_error_log() assert resp["status"].startswith("2") CONTENT = json.loads(content) pinfo(content) assert_same_jsons(EXPECTED_PUBLISHER, CONTENT["sourceResource"])
def test_geocode_set_name_coordinates(): """Should set the name property to the lowest hierarchy value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "coordinates": "37.7771186829, -122.419639587", "city": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "coordinates": "37.7771186829, -122.419639587", "city": "Bananas", "state": "California", "name": "Bananas", "county": "San Francisco County", "country": "United States" } ] } } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_type_has_priority(): INPUT = { "id": "123", "sourceResource": { "type": [{ "text": "text", "attrib": {} }, { "text": "text", "attrib": { "q": "mods" } }, { "text": "postcards", "attrib": { "q": "genreform" } }], "format": "postcard" } } EXPECTED = { "id": "123", "sourceResource": { "type": "text", "format": "postcard" } } resp, content = _get_server_response(json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_do_not_skip_united_states(): """Should geocode when name value is 'United States' is followed by a '-' """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "United States--California" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "coordinates": "37.25022, -119.75126", "country": "United States", "name": "United States--California", "state": "California" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_geonames_name_search(): """Should find a place name. """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "name": "Portland, OR" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "county": "Multnomah County", "country": "United States", "state": "Oregon", "name": "Portland, OR", "coordinates": "45.52345, -122.67621" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_default_type(): """Should set type to default value""" INPUT = {"id": "123", "sourceResource": {"type": "bananas"}} EXPECTED = {"id": "123", "sourceResource": {"type": "image"}} resp, content = _get_server_response(json.dumps(INPUT), default="image") assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_iso639_3_substitution(): """ Should add "name" to language """ INPUT = { "sourceResource": { "language": [ {"iso639_3": "eng"}, {"iso639_3": "ara"} ] } } EXPECTED = { "sourceResource": { "language": [ {"iso639_3": "eng", "name": "English"}, {"iso639_3": "ara", "name": "Arabic"} ] } } prop = "sourceResource%2Flanguage%2Fiso639_3" targ = "sourceResource%2Flanguage%2Fname" subs = "iso639_3" resp, content = _get_server_response(json.dumps(INPUT), prop, targ, subs) print_error_log() assert resp.status == 200 assert_same_jsons(content, EXPECTED)
def test_substitute_with_list_of_dictionaries(): """ Should convert all dicts in a list. """ data = { "xxx": "yyy", "aaa": { "bbb": "ccc", "xxx": [ {"eee": "aaa"}, {"xxx": "eee"}, {"eee": "bbb"} ] } } INPUT = json.dumps(data) data["aaa"]["xxx"] = [ {"eee": "AAA222"}, {"xxx": "eee"}, {"eee": "BBB222"}, ] EXPECTED_OUTPUT = json.dumps(data) resp, content = _get_server_response(INPUT, "aaa/xxx/eee", "aaa/xxx/eee", "test2") print_error_log() pinfo(resp, content) assert resp.status == 200 assert_same_jsons(content, EXPECTED_OUTPUT)
def test_substitution_with_deleting_missing_values(): data = { "xxx": "yyy", "aaa": { "bbb": "ccc", "xxx": [ {"eee": "aaa"}, {"xxx": "eee"}, {"eee": "bbb"}, {"eee": "doesnt exist"}, {"eee": "doesnt exist"} ] }, } INPUT = json.dumps(data) data["aaa"]["xxx"] = [ {"eee": "AAA222"}, {"xxx": "eee"}, {"eee": "BBB222"}, { }, { } ] EXPECTED_OUTPUT = json.dumps(data) resp, content = _get_server_response(INPUT, "aaa/xxx/eee", "aaa/xxx/eee", "test2", None, True) assert resp.status == 200 assert_same_jsons(content, EXPECTED_OUTPUT)
def test_geocode_coordinate_provided(): INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "name": "42.358631134, -71.0567016602" } ] }, "creator": "David" } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [ { "state": "Massachusetts", "country": "United States", "name": "42.358631134, -71.0567016602", "coordinates": "42.358631134, -71.0567016602" } ] }, "creator": "David" } url = server() + "geocode" resp,content = H.request(url,"POST",body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(json.loads(content), EXPECTED)
def test_substitution_using_scdl_format_dict(): formats = \ ("Pamphlets", "Pamphlets"), \ ("Pamphlet", "Pamphlets"), \ ("pamphlets", "Pamphlets"), \ ("Manuscripts", "Manuscripts"), \ ("Manuscript", "Manuscripts"), \ ("manuscripts", "Manuscripts"), \ ("Photograph", "Photographs"), \ ("Photographs", "Photographs"), \ ("Photograph", "Photographs") \ data = { "xxx": "yyy", "aaa": "" } for f in formats: data["aaa"] = f[0] INPUT = json.dumps(data) data["aaa"] = f[1] EXPECTED_OUTPUT = json.dumps(data) print "Checking: %s" + repr(f) resp, content = _get_server_response(INPUT, "aaa", "aaa", "scdl_fix_format", None, False) print_error_log() assert resp.status == 200 assert_same_jsons(EXPECTED_OUTPUT, content)
def test_removing_multiple_invalid_date_dicts(): INPUT = { "sourceResource": { "date": [ { "begin": "1959-01-01", "end": "1959-01-01", "displayDate": "1959-01-01" }, { "begin": "2008-11-18", "end": "2008-11-18", "displayDate": "2008-11-18" }, { "begin": "1959-01-01", "end": None, "displayDate": "1959-01-01" }, { "begin": "2008-11-18", "end": "", "displayDate": "2008-11-18" }, { "begin": None, "end": "1959-01-01", "displayDate": "1959-01-01" }, { "begin": "", "end": "2008-11-18", "displayDate": "2008-11-18" }, "aaa", "bbb", "ccc", ] } } EXPECTED_OUTPUT = { "sourceResource": { "date": [ { "begin": "1959-01-01", "end": "1959-01-01", "displayDate": "1959-01-01", }, { "begin": "2008-11-18", "end": "2008-11-18", "displayDate": "2008-11-18" }, ] } } resp, content = _get_server_response(INPUT, "sourceResource/date") print_error_log() assert resp["status"].startswith("2") assert_same_jsons(EXPECTED_OUTPUT, content)
def test_geocode(): """ Simple geocode """ INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": "Bakersfield, CA" }] }, "creator": "David" } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": "Bakersfield, CA", "state": "California", "county": "Kern County", "country": "United States", "coordinates": "35.37329, -119.01871" }] }, "creator": "David" } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_changing_values(): INPUT = [ "hello there", "123", ". hi ", ". hi", " . hi there ", "a banana", "''.more complicated....", '""""....even more complicated....."\'""""', "hello there;;", ";;hello there;;", "aaa--bbb", "aaa --bbb", "aaa-- bbb", "aaa -- bbb", "aaa -- bbb -- ccc - - ddd -- ", ["aaa", "bbb"], [" - aaa", " bbb -- "], "aaa bbb -- ccc", "...,,,;;;;..,;'''\t\t\t aaa -- bbb ccc ddd;;;..;,,,,,;;;..... \t ", "aaa -- bbb ccc\t\t\t\t\tddd", " aaa -- bbb\t\t \t\t ccc\t\t\t ", "\t\taaa\tbbb\t\t", """.. \t\t sss ddd \t\t .. """ ] EXPECTED = [ "hello there", "123", "hi", "hi", "hi there", "a banana", "more complicated", 'even more complicated', "hello there", "hello there", "aaa--bbb", "aaa--bbb", "aaa--bbb", "aaa--bbb", "aaa--bbb--ccc - - ddd--", ["aaa", "bbb"], ["- aaa", "bbb--"], "aaa bbb--ccc", "aaa--bbb ccc ddd", "aaa--bbb ccc ddd", "aaa--bbb ccc", "aaa\tbbb", """sss ddd""" ] for i in xrange(0, len(INPUT)): data = {} data["aaa"] = {"bbb": INPUT[i]} r, c = _get_server_response(json.dumps(data), 'aaa%2Fbbb') exp = {} exp["aaa"] = {"bbb": EXPECTED[i]} print_error_log() assert_same_jsons(exp, c)
def test_geocode_coordinate_provided2(): """Should use coordinates provided in the coordinates property""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": "United States--Massachussetts", "coordinates": "42.358631134, -71.0567016602" }] }, "creator": "David" } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "state": "Massachusetts", "country": "United States", "name": "United States--Massachussetts", "coordinates": "42.358631134, -71.0567016602" }] }, "creator": "David" } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_list_of_properties(): """Should process all properties.""" props = ["aaa", "bbb/ccc", "ddd/eee/fff"] INPUT = { "aaa": "....a -- b....", "bbb": { "ccc": ["aaa", "bbb", "'''''x''''"] }, "ddd": { "eee": { "fff": ["a", "b", "...d..."] } } } EXPECTED = { "aaa": "a--b", "bbb": { "ccc": ["aaa", "bbb", "x"] }, "ddd": { "eee": { "fff": ["a", "b", "d"] } } } r, c = _get_server_response(json.dumps(INPUT), props) assert r['status'] == '200' assert_same_jsons(EXPECTED, c)
def test_geocode_with_existing_props(): """Should not update existing fields since "state" value exists""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "name": "United States--Massachussetts", "coordinates": "42.358631134, -71.0567016602", "country": "Bananas", "state": "Apples" }] }, "creator": "David" } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "state": "Apples", "country": "Bananas", "name": "United States--Massachussetts", "coordinates": "42.358631134, -71.0567016602" }] }, "creator": "David" } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_set_type_from_physical_format4(): """Should set type""" INPUT = { "sourceResource": { "format": [ "Textile", "frame", "Photographs", "still image", "prints", "magazines", "letters", "Sound Recording", "Audio", "online Collections", "finding aid", "Online Exhibit" ] } } EXPECTED = { "sourceResource": { "format": [ "Textile", "frame", "Photographs", "still image", "prints", "magazines", "letters", "Sound Recording", "Audio", "online Collections", "finding aid", "Online Exhibit" ], "type": [ "physical object", "image", "text", "sound", "collection", "interactive resource" ] } } resp, content = _get_server_response(json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, content)
def test_geocode_set_name_coordinates(): """Should set the name property to the lowest hierarchy value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "coordinates": "37.7771186829, -122.419639587", "city": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "coordinates": "37.7771186829, -122.419639587", "city": "Bananas", "state": "California", "name": "Bananas", "county": "San Francisco County", "country": "United States" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_contentdm_identify_object_with_download(): """ Should add a thumbnail URL made of the source URL. """ INPUT = { u"something": "x", u"somethink": "y", u"originalRecord": { "handle": ["aaa", "http://repository.clemson.edu/u?/scp,104"] }, u"left": "right now!" } EXPECTED = { u"something": "x", u"somethink": "y", u"originalRecord": { "handle": ["aaa", "http://repository.clemson.edu/u?/scp,104"] }, u"object": ("http://repository.clemson.edu/cgi-bin/" + "thumbnail.exe?CISOROOT=/scp&CISOPTR=104"), u"admin": {u"object_status": 1}, u"left": "right now!" } url = contentdm_url("True") resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert str(resp.status).startswith("2") result = json.loads(content) assert_same_jsons(EXPECTED, result)
def test_geocode_set_name_city(): """Should set the name property to the city value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "city": "Los Angeles", "state": "California" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "coordinates": '34.05223, -118.24368', "city": "Los Angeles", 'county': 'Los Angeles County', "state": "California", "country": "United States", "name": "Los Angeles" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_cleanup_value_for_list(): INPUT = { "aaa": { "bbb": [ "Fisker, Kay--Architect--Danish--Male", "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc" ] } } EXPECTED_OUTPUT = { "aaa": { "bbb": [ "Fisker, Kay", "Fisker, Kay", "bbb", "ccc" ] } } resp, content = _get_server_response(json.dumps(INPUT), "aaa/bbb") print_error_log() assert resp["status"].startswith("2") assert_same_jsons(EXPECTED_OUTPUT, content)
def test_geocode_set_name_county(): """Should set the name property to the county value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "county": "Los Angeles County", "country": "Bananas" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "county": "Los Angeles County", "country": "Bananas", "name": "Los Angeles County", "state": "California", #uses bing because geonames wants to match country values "coordinates": "33.9934997559, -118.29750824" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_geocode_set_name_region(): """Should set the name property to the region value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "region": "Ecuador" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ "region": "Ecuador", "name": "Ecuador", "country": "Ecuador" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_range_with_brackets(): """Should transform date range with brackets.""" ranges = [ ("1960-05-01 - 1960-05-15", "1960-05-01 - 1960-05-15"), ("[ 1960-05-01 - 1960-05-15 ]", "1960-05-01 - 1960-05-15"), ("[1960-05-01 - 1960-05-15]", "1960-05-01 - 1960-05-15"), ("[1960-05-01 / 1960-05-15]", "1960-05-01 / 1960-05-15"), ("[1960-05-01/1960-05-15]", "1960-05-01/1960-05-15"), ] for r in ranges: INPUT = {"date": r[0]} EXPECTED = { u'date': { u'begin': u'1960-05-01', u'end': u'1960-05-15', "displayDate": r[1] } } url = server() + "enrich_earliest_date?prop=date" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert str(resp.status).startswith("2") print_error_log() assert_same_jsons(EXPECTED, content)
def test_geocode_set_name_state(): """Should set the name property to the state value""" INPUT = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": { "state": "California" } } } EXPECTED = { "id": "12345", "_id": "12345", "sourceResource": { "spatial": [{ 'coordinates': '37.25022, -119.75126', "country": "United States", "state": "California", "name": "California" }] } } url = server() + "geocode" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert resp.status == 200 assert_same_jsons(EXPECTED, json.loads(content))
def test_dedup_value1(): """Should remove duplicate values""" props = "subject,spatial,description" INPUT = { "subject": [ "This is a subject", "This is a subject.", " this is a SuBject . ", "This is another subject (1780).", "This is another subject 1780", " thiS IS anOther subject (1780)" ], "spatial": ["North Carolina", "New York"], "description": "A description" } EXPECTED = { "subject": [ "This is a subject", "This is another subject (1780)." ], "spatial": ["North Carolina", "New York"], "description": "A description" } resp, content = _get_server_response(json.dumps(INPUT), props) assert resp.status == 200 assert_same_jsons(EXPECTED, content)
def test_range_with_brackets(): """Should transform date range with brackets.""" ranges = [ ("1960-05-01 - 1960-05-15", "1960-05-01 - 1960-05-15"), ("[ 1960-05-01 - 1960-05-15 ]", "1960-05-01 - 1960-05-15"), ("[1960-05-01 - 1960-05-15]", "1960-05-01 - 1960-05-15"), ("[1960-05-01 / 1960-05-15]", "1960-05-01 / 1960-05-15"), ("[1960-05-01/1960-05-15]", "1960-05-01/1960-05-15"), ] for r in ranges: INPUT = {"date": r[0]} EXPECTED = { u'date' : { u'begin' : u'1960-05-01', u'end' : u'1960-05-15', "displayDate" : r[1] } } url = server() + "enrich_earliest_date?prop=date" resp, content = H.request(url, "POST", body=json.dumps(INPUT)) assert str(resp.status).startswith("2") print_error_log() assert_same_jsons(EXPECTED, content)