Skip to content
Browse files

Added data provider for DC.

  • Loading branch information...
1 parent e8b4f07 commit 6a52b3f8dfda2e33f74faa5c3080e94967908afd @szymonlipinski szymonlipinski committed Mar 20, 2013
Showing with 262 additions and 32 deletions.
  1. +2 −1 akara.conf
  2. +225 −1 lib/akamod/lookup.py
  3. +2 −1 profiles/digital-commonwealth.pjs
  4. +2 −1 test/server_support.py
  5. +31 −28 test/test_lookup.py
View
3 akara.conf
@@ -167,7 +167,8 @@ class lookup:
# Value is name of the dictionary from lookup module.
lookup_mapping = {
'test': 'test_subst',
- 'test2': 'test_2_subst'
+ 'test2': 'test_2_subst',
+ 'dc_data_provider': 'DC_DATA_PROVIDER'
}
class identify_object:
View
226 lib/akamod/lookup.py
@@ -42,6 +42,7 @@ def convert_last(data, path, name, conv):
return
value = data[path]
+
if isinstance(value, list):
out = []
for el in value:
@@ -51,7 +52,8 @@ def convert_last(data, path, name, conv):
out.append(el)
data[name] = out
else:
- data[name] = conv[value]
+ if value in conv:
+ data[name] = conv[value]
def convert(data, path, name, conv, path_delim="/"):
@@ -372,3 +374,225 @@ def log_json():
"ccc": "CCC",
"ddd": "DDD",
}
+
+DC_DATA_PROVIDER = {
+"Beverly High School Digital Collection": "Beverly High School",
+
+"Brookline Photograph Collection": "Brookline Public Library",
+"Amherst Collection": "C/W MARS",
+"Athol Collection": "C/W MARS",
+"Baystate Medical Center Collection": "C/W MARS",
+"Blackstone Collection": "C/W MARS",
+"Buckland Collection": "C/W MARS",
+"C/W MARS State Library of Massachusetts Collection": "C/W MARS",
+"Chicopee Collection": "C/W MARS",
+"Clark University Collection": "C/W MARS",
+"East Longmeadow Collection": "C/W MARS",
+"Elms College Collection": "C/W MARS",
+"Erving Collection": "C/W MARS",
+"Greenfield Collection": "C/W MARS",
+"Holyoke Collection": "C/W MARS",
+"Hopedale Collection": "C/W MARS",
+"Hopkinton Collection": "C/W MARS",
+"Hudson Collection": "C/W MARS",
+"Lancaster Collection": "C/W MARS",
+"Ludlow Collection": "C/W MARS",
+"Mt. Wachusett Community College Collection": "C/W MARS",
+"National Guard Museum Collection": "C/W MARS",
+"Nichols College Collection": "C/W MARS",
+"North Brookfield Collection": "C/W MARS",
+"Northampton Collection": "C/W MARS",
+"Orange Collection": "C/W MARS",
+"Oxford Collection": "C/W MARS",
+"Palmer Collection": "C/W MARS",
+"Princeton Collection": "C/W MARS",
+"Shrewsbury Collection": "C/W MARS",
+"South Hadley Collection": "C/W MARS",
+"Southbridge Collection": "C/W MARS",
+"Spencer Collection": "C/W MARS",
+"Springfield College Collection": "C/W MARS",
+"Sturbridge Collection": "C/W MARS",
+"Uxbridge Collection": "C/W MARS",
+"Webster Collection": "C/W MARS",
+"West Boylston Collection": "C/W MARS",
+"Westborough Collection": "C/W MARS",
+"Westfield Collection": "C/W MARS",
+"Wilbraham Collection": "C/W MARS",
+"Williamsburg Collection": "C/W MARS",
+"Worcester Collection": "C/W MARS",
+"WPI Collection": "C/W MARS",
+
+"Essex Aggie Digital Collection": "Essex Agricultural and Technical High School",
+
+"Henry Whittemore Library": "Framingham State University",
+
+
+"John W. Ragle Archives Room": "Governor’s Academy",
+
+"Oral History Projects": "Jewish Women's Archive",
+"Lawrence Public Libary": "Jewish Women's Archive",
+"Lawrence Public Library Digital Collection": "Jewish Women's Archive",
+"Lincoln Public Library": "Jewish Women's Archive",
+"Farrar Book": "Jewish Women's Archive",
+
+"City of Lowell Images Collection": "Lowell National Historical Park",
+
+
+"Mass. Historical Finding Aids": "Massachusetts Historical Society",
+"Mass. Historical Online Collections": "Massachusetts Historical Society",
+
+"1878 Map of Newton Center": "Newton Free Public Library",
+"Allen House Oversized Photos": "Newton Free Public Library",
+"Assessed Polls": "Newton Free Public Library",
+"Auburndale Tradecards": "Newton Free Public Library",
+"Biographical Pamphlet (Fields)": "Newton Free Public Library",
+"Biographical Pamphlet (Livermore)": "Newton Free Public Library",
+"Blue Books of Newton": "Newton Free Public Library",
+"Class Statistics NHS Class of 1890": "Newton Free Public Library",
+"Diary and Account Book, 1859-1862": "Newton Free Public Library",
+"Diary of Edgar W. Warren": "Newton Free Public Library",
+"Eliot Church Annual 1845-1887": "Newton Free Public Library",
+"For the Dinner of the First City Government": "Newton Free Public Library",
+"Glass Plate Negatives": "Newton Free Public Library",
+"History of the Newton Fire Department": "Newton Free Public Library",
+"Hunnewell Club": "Newton Free Public Library",
+"Jersey Stock Club": "Newton Free Public Library",
+"Journal of Edward Jackson": "Newton Free Public Library",
+"Lantern Slides": "Newton Free Public Library",
+"Metal Plate Negative": "Newton Free Public Library",
+"Newell Family Album": "Newton Free Public Library",
+"Newell Family Misc": "Newton Free Public Library",
+"Newton Engineering Dept. Photos": "Newton Free Public Library",
+"Newton Forestry Dept. Photos": "Newton Free Public Library",
+"Newton High School Class of 1885 Photographs": "Newton Free Public Library",
+"Newton High School, class of 1890 photographs": "Newton Free Public Library",
+"Newton High School, class of 1895 photographs": "Newton Free Public Library",
+"Newton High School, class of 1900 photographs": "Newton Free Public Library",
+"Newton Illustrated": "Newton Free Public Library",
+"Newton Oversized: Misc": "Newton Free Public Library",
+"Newton Street Directory": "Newton Free Public Library",
+"Newton Tradecards": "Newton Free Public Library",
+"Newton Village Shops": "Newton Free Public Library",
+"Pictures of Newton Corner/Nonantum Square": "Newton Free Public Library",
+"Plan of Proctor Map": "Newton Free Public Library",
+"Samuel Smith Manuscript": "Newton Free Public Library",
+"Seth Davis Notebook": "Newton Free Public Library",
+"Some Newtonville Homes": "Newton Free Public Library",
+"Sparrows, Finches, Etc. of New England": "Newton Free Public Library",
+"Waban (Newton, Mass.)": "Newton Free Public Library",
+"Waban Historical Col. Glass Plates": "Newton Free Public Library",
+"Waban Historical Col. Lantern Slides": "Newton Free Public Library",
+
+"Alumni Project: Andover History in Photographs and Stories": "Noble",
+"Beverly Picture Collection": "Noble",
+"Beverly Postcard Collection": "Noble",
+"Boston Mat Leather Company, Peabody, Mass.": "Noble",
+"Current Images of Wakefield": "Noble",
+"Danvers Mass. Memories Road Show": "Noble",
+"Gloucester Oral History Collection": "Noble",
+"Gloucester Postcard Collection": "Noble",
+"Helen Cutter Slides": "Noble",
+"History of the Academy": "Noble",
+"Humphrey Street, Swampscott, Mass.": "Noble",
+"List of Vessels Belonging to the District of Gloucester": "Noble",
+"Lucius Beebe Memorial Library Artwork Collection": "Noble",
+"Lynn Historic Images : Getting around in Lynn": "Noble",
+"Lynn Historic Images : Buildings": "Noble",
+"Lynn Historic Images : Churches": "Noble",
+"Lynn Historic Images : Lynn's Great Outdoors": "Noble",
+"Lynn Historic Images : Memorials and Cemeteries": "Noble",
+"Lynn Historic Images : Parades and Events": "Noble",
+"Lynn Historic Images : People": "Noble",
+"Lynn Historic Images : Streets": "Noble",
+"Lynn Historic Images : World War I": "Noble",
+"Murphy Postcard Collection": "Noble",
+"Old Photographs of Wakefield": "Noble",
+"Peabody Glass Plate Photographs": "Noble",
+"Peabody Oak Hill Estate": "Noble",
+"Phillips Academy Athletics Images": "Noble",
+"Reading Historical Images": "Noble",
+"Saugus Glass Slides": "Noble",
+"Stoneham Historic Images": "Noble",
+"Swampscott Buildings": "Noble",
+"Swampscott Schools": "Noble",
+"Swampscott Through the Years: A pictorial history": "Noble",
+"Swampscott Town Departments": "Noble",
+"Swampscott's Neighboring Towns": "Noble",
+"Wakefield Municipal Gas": "Noble",
+"Wakefield Postcards": "Noble",
+"Wakefield Then": "Noble",
+"Walkable Reading": "Noble",
+
+"Ambrose F. Keeley Library (Durfee High School, Fall River) Local History Collection": "SAILS Digital History Collection",
+"Ambrose F. Keeley Library (Durfee High School, Fall River) Yearbooks": "SAILS Digital History Collection",
+"Carver Public Library, Carver Cemetery Records": "SAILS Digital History Collection",
+"East Bridgewater High School Yearbooks": "SAILS Digital History Collection",
+"East Bridgewater Public Library Historical Photographs": "SAILS Digital History Collection",
+"Fiske Public Library (Wrentham) Helen Keller Collection": "SAILS Digital History Collection",
+"Hanson Public Library , Hanson History": "SAILS Digital History Collection",
+"Holmes Public Library (Halifax) Halifax Historical Society": "SAILS Digital History Collection",
+"Holmes Public Library (Halifax) Halifax History": "SAILS Digital History Collection",
+"Holmes Public Library (Halifax) Silver Lake Yearbooks": "SAILS Digital History Collection",
+"Joseph Plumb Memorial Library (Rochester) Architectural Survey": "SAILS Digital History Collection",
+"Middleborough Public Library Cranberry Collection": "SAILS Digital History Collection",
+"Plainville Public Library": "SAILS Digital History Collection",
+"West Bridgewater Public Library Historical Postcards": "SAILS Digital History Collection",
+
+
+"College Archives Digital Collections": "Springfield College",
+"State Library of Massachusetts Collection": "Springfield College",
+"Attorney General Annual Reports": "Springfield College",
+"Bird’s Eye Maps": "Springfield College",
+"Broadsides": "Springfield College",
+"Canal Maps": "Springfield College",
+"Executive Orders": "Springfield College",
+"Highway Department Annual Reports": "Springfield College",
+"Highway Department Maps": "Springfield College",
+"Highway Department Photographs": "Springfield College",
+"Hoosac Tunnel Photographs": "Springfield College",
+"Land and Harbor Commissioner Atlases": "Springfield College",
+"Land and Harbor Commissioner Maps": "Springfield College",
+"Legislative Maps": "Springfield College",
+"Other Historical Maps": "Springfield College",
+"Railroad Commission Annual Reports": "Springfield College",
+"Railroad Commission Manuscripts": "Springfield College",
+"Railroad Commission Maps": "Springfield College",
+
+"State of the Commonwealth Addresses": "State Library Publications",
+
+"Postcard Collection": "Stephen Phillips Trust House",
+
+"Digitized Materials from the Library's Rare Book Collection":"Sterling and Francine Clark Art Institute Library",
+"Mary Ann Beinecke Decorative Art Collection":"Sterling and Francine Clark Art Institute Library",
+"Sterling and Francine Clark Art Institute Library Exhibition Files":"Sterling and Francine Clark Art Institute Library",
+
+"Lowell Cultural Resources Inventory":"University of Massachusetts Lowell Libraries",
+"Lowell Massachusetts: Building Surveys Overview Reports":"University of Massachusetts Lowell Libraries",
+"Lowell Neighborhoods: Historical and Architectural Survey":"University of Massachusetts Lowell Libraries",
+"Stereoview Collection":"University of Massachusetts Lowell Libraries",
+
+"Convers Francis, 1795–1863":"Watertown Free Public Library",
+"Watertown Arsenal":"Watertown Free Public Library",
+"Watertown Businesses":"Watertown Free Public Library",
+"Watertown Cemeteries":"Watertown Free Public Library",
+"Watertown Charles River":"Watertown Free Public Library",
+"Watertown Churches":"Watertown Free Public Library",
+"Watertown Graves":"Watertown Free Public Library",
+"Watertown Historic Buildings Gallery":"Watertown Free Public Library",
+"Watertown Houses":"Watertown Free Public Library",
+"Watertown Library Branch":"Watertown Free Public Library",
+"Watertown Main Library":"Watertown Free Public Library",
+"Watertown Miscellaneous":"Watertown Free Public Library",
+"Watertown Monuments and Historical Markers":"Watertown Free Public Library",
+"Watertown People":"Watertown Free Public Library",
+"Watertown Public Celebrations":"Watertown Free Public Library",
+"Watertown Railroads":"Watertown Free Public Library",
+"Watertown Schools":"Watertown Free Public Library",
+"Watertown Square":"Watertown Free Public Library",
+"Watertown Street Views":"Watertown Free Public Library",
+"Watertown Town Hall":"Watertown Free Public Library",
+
+"WGBH OpenVault":"WGBH",
+"Home Contact FAQs Items Member Resources Collection Tree":"WGBH",
+"Proudly powered by Omeka. © Digital Commonwealth 2013":"WGBH"
+}
View
3 profiles/digital-commonwealth.pjs
@@ -21,7 +21,8 @@
"http://localhost:8881/enrich-type",
"http://localhost:8881/enrich-format",
"http://localhost:8881/enrich_location",
- "http://localhost:8881/contentdm_identify_object"
+ "http://localhost:8881/contentdm_identify_object",
+ "http://localhost:8881/lookup?prop=collection%2Ftitle&target=aataProvider&subst=dc_data_provider"
],
"blacklist": ["3","5","6","8","13","18","19","20","27","41","177"],
"contributor": {
View
3 test/server_support.py
@@ -136,7 +136,8 @@ class download_preview:
class lookup:
lookup_mapping = {
'test': 'test_subst',
- 'test2': 'test_2_subst'
+ 'test2': 'test_2_subst',
+ 'dc_data_provider': 'DC_DATA_PROVIDER'
}
class identify_object:
View
59 test/test_lookup.py
@@ -30,8 +30,6 @@ def _get_server_response(body, prop=None, target=None, subst=None):
return H.request(url, "POST", body=body)
-
-
def test_bad_INPUT_json():
"""
Should return 500 when getting bad JSON.
@@ -41,9 +39,6 @@ def test_bad_INPUT_json():
assert resp.status == 500
-
-
-
def test_no_params():
"""
Should return 500 for no params.
@@ -53,8 +48,6 @@ def test_no_params():
assert resp.status == 500
-
-
def test_missing_input_field():
"""
Should return 500 for no param.
@@ -64,8 +57,6 @@ def test_missing_input_field():
assert resp.status == 500
-
-
def test_missing_field_in_json():
"""
Should return the same json for missing INPUT field in json.
@@ -76,8 +67,6 @@ def test_missing_field_in_json():
assert_same_jsons(INPUT, INPUT)
-
-
def test_missing_output_field():
"""
Should return 500 when the OUTPUT field is missing from URL.
@@ -87,8 +76,6 @@ def test_missing_output_field():
assert resp.status == 500
-
-
def test_substitution_with_missing_subst_dict():
"""
Should return the same JSON when the key is missing from substitution.
@@ -101,8 +88,6 @@ def test_substitution_with_missing_subst_dict():
assert content == "Missing substitution dictionary [aaa]"
-
-
def test_substitution_with_missing_key():
"""
Should return the same JSON when the key is missing from substitution.
@@ -116,8 +101,6 @@ def test_substitution_with_missing_key():
assert_same_jsons(INPUT, content)
-
-
def test_simple_substitute_for_the_same_field():
"""
Should return substituted same json field.
@@ -131,8 +114,6 @@ def test_simple_substitute_for_the_same_field():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
-
def test_simple_substitute_for_different_field():
"""
Should return substituted another json field.
@@ -145,7 +126,6 @@ def test_simple_substitute_for_different_field():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
def test_substitution_for_the_same_field_and_array():
"""
Should return substituted json when original json is array.
@@ -160,7 +140,6 @@ def test_substitution_for_the_same_field_and_array():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
def test_substitution_for_different_fields_and_array():
"""
Should return json when original json is array.
@@ -175,7 +154,6 @@ def test_substitution_for_different_fields_and_array():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
def test_dictionary_subsitution():
"""
Should substitute when there is dictionary field.
@@ -190,7 +168,6 @@ def test_dictionary_subsitution():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
def test_deeper_dictionary_subsitution():
"""
Should substitute when there is dictionary field.
@@ -213,7 +190,6 @@ def test_deeper_dictionary_subsitution():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
def test_dict_substitution_in_different_field():
"""
Should add another field when prop is dictionary field.
@@ -236,8 +212,6 @@ def test_dict_substitution_in_different_field():
assert_same_jsons(content, EXPECTED_OUTPUT)
-
-
def test_substitute_with_list_of_dictionaries():
"""
Should convert all dicts in a list.
@@ -269,8 +243,37 @@ def test_substitute_with_list_of_dictionaries():
assert resp.status == 200
assert_same_jsons(content, EXPECTED_OUTPUT)
-# TODO Add test with list of dictionaries
-# TODO add test with dictionary with list
+
+def test_missing_value_in_dict():
+ """Should do nothing when there is no such value in dictionary."""
+ INPUT = {"a": "b"}
+ resp, content = _get_server_response(json.dumps(INPUT), "a", "x", "test")
+ print_error_log()
+ pinfo(resp, content)
+
+ assert resp.status == 200
+ assert_same_jsons(content, INPUT)
+
+
+def test_dc_data_provider():
+ """Should convert data providers for Digital Commonwealth."""
+ data = [
+ ("Beverly High School", "Beverly High School Digital Collection"),
+ ("Brookline Public Library", "Brookline Photograph Collection"),
+ ("C/W MARS", "Amherst Collection"),
+ ("Essex Agricultural and Technical High School", "Essex Aggie Digital Collection"),
+ ("Framingham State University", "Henry Whittemore Library"),
+ ]
+ for d in data:
+ INPUT = {"a": d[1]}
+ EXPECTED_OUTPUT = {"a": d[1], "b": d[0]}
+ resp, content = _get_server_response(json.dumps(INPUT), "a", "b", "dc_data_provider")
+ print_error_log()
+ pinfo(resp, content)
+
+ assert resp.status == 200
+ assert_same_jsons(content, EXPECTED_OUTPUT)
+
if __name__ == "__main__":
raise SystemExit("Use nosetest")

0 comments on commit 6a52b3f

Please sign in to comment.
Something went wrong with that request. Please try again.