Пример #1
0
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)
Пример #2
0
def test_unset_prop6():
    """Should unset prop since conditions are met for multiple condition
       props"""
    action = "unset"
    prop = "_id"
    condition = "hathi_exclude"
    condition_prop = "dataProvider%2CsourceResource%2Ftype"

    INPUT = {
        "_id": "12345",
        "dataProvider": ["Hathitrust", "University of Minnesota"],
        "sourceResource": {
            "type": "image"
        }
    }
    EXPECTED = {
        "dataProvider": ["Hathitrust", "University of Minnesota"],
        "sourceResource": {
            "type": "image"
        }
    }

    resp, content = _get_server_response(json.dumps(INPUT), action=action,
        prop=prop, condition=condition, condition_prop=condition_prop)
    print_error_log()
    assert resp.status == 200
    assert json.loads(content) == EXPECTED
Пример #3
0
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)
Пример #4
0
def test_year_month():
    """Should recognize YYYY-MM and not YYYY-YY"""
    INPUT = [
        "1940/2",
        "1940/02",
        "1940 / 2",
        "1940 / 02",
        "1940-2",
        "1940-02",
        "1940 - 2",
        "1940 - 02",
        "2/1940",
        "02/1940",
        "2 / 1940",
        "02 / 1940",
        "2-1940",
        "02-1940",
        "2 - 1940",
        "02 - 1940",
    ]

    url = server() + "enrich_earliest_date?prop=date"
    for date in INPUT:
        d = "1940-02"
        input = {"date": date}
        expected = {"date": {"begin": d, "end": d, "displayDate": date}}

        resp, content = H.request(url, "POST", body=json.dumps(input))
        print_error_log()
        assert str(resp.status).startswith("2")
        assert_same_jsons(expected, 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)
Пример #6
0
def test_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_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)
Пример #8
0
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)
Пример #9
0
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_contentdm_identify_object_without_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": 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)
Пример #11
0
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)
Пример #12
0
def test_unset_prop6():
    """Should unset prop since conditions are met for multiple condition
       props"""
    action = "unset"
    prop = "_id"
    condition = "hathi_exclude"
    condition_prop = "dataProvider%2CsourceResource%2Ftype"

    INPUT = {
        "_id": "12345",
        "dataProvider": ["Hathitrust", "University of Minnesota"],
        "sourceResource": {
            "type": "image"
        }
    }
    EXPECTED = {
        "dataProvider": ["Hathitrust", "University of Minnesota"],
        "sourceResource": {
            "type": "image"
        }
    }

    resp, content = _get_server_response(json.dumps(INPUT),
                                         action=action,
                                         prop=prop,
                                         condition=condition,
                                         condition_prop=condition_prop)
    print_error_log()
    assert resp.status == 200
    assert json.loads(content) == EXPECTED
Пример #13
0
def test_unset_prop2():
    """Should unset prop since condition is met"""
    action = "unset"
    prop = "sourceResource/rights"
    condition = "is_digit"

    INPUT = {
        "_id": "12345",
        "key1": "value1",
        "sourceResource": {
            "key1": "value1",
            "rights": "20010983784"
        },
        "key2": "value2"
    }
    EXPECTED = {
        "_id": "12345",
        "key1": "value1",
        "sourceResource": {
            "key1": "value1"
        },
        "key2": "value2"
    }

    resp, content = _get_server_response(json.dumps(INPUT),
                                         action=action,
                                         prop=prop,
                                         condition=condition)
    assert resp.status == 200
    print_error_log()
    assert json.loads(content) == EXPECTED
Пример #14
0
def test_unset_prop2():
    """Should unset prop since condition is met"""
    action = "unset"
    prop = "sourceResource/rights"
    condition = "is_digit"

    INPUT = {
        "_id": "12345",
        "key1": "value1",
        "sourceResource": {
            "key1" : "value1",
            "rights": "20010983784"
        },
        "key2": "value2"
    }
    EXPECTED = {
        "_id": "12345",
        "key1": "value1",
        "sourceResource": {
            "key1" : "value1"
        },
        "key2": "value2"
    }

    resp,content = _get_server_response(json.dumps(INPUT), action=action,
        prop=prop, condition=condition)
    assert resp.status == 200
    print_error_log()
    assert json.loads(content) == EXPECTED
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)
Пример #16
0
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)
Пример #17
0
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_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_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)
Пример #20
0
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)
Пример #21
0
def test_default_prop_value():
    """Should convert default field only."""
    INPUT = {
        "sourceResource": {
            "creator": [
                "Fisker, Kay--Architect--Danish--Male",
                "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc"
            ],
            "aaa": [
                "Fisker, Kay--Architect--Danish--Male",
                "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc"
            ]
        }
    }
    EXPECTED_OUTPUT = {
        "sourceResource": {
            "creator": ["Fisker, Kay", "Fisker, Kay", "bbb", "ccc"],
            "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)
Пример #22
0
def test_suppress_creator_value_for_list():
    """Should remove creator value if the is 'creator'."""
    INPUT = {
        "sourceResource": {
            "creator": [
                "creator", "Fisker, Kay--Architect--Danish--Male",
                "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc"
            ],
            "aaa": [
                "Fisker, Kay--Architect--Danish--Male",
                "Fisker, Kay--Architect--Danish--Male", "bbb", "ccc"
            ]
        }
    }
    EXPECTED_OUTPUT = {
        "sourceResource": {
            "creator": ["Fisker, Kay", "Fisker, Kay", "bbb", "ccc"],
            "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)
Пример #23
0
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)
Пример #24
0
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)
Пример #25
0
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_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)
Пример #27
0
def test_description_transform1():
    INPUT = {"metadata": {"mods": {"note": "A description"}}}
    EXPECTED = {"description": "A description"}

    resp, content = _get_server_response(json.dumps(INPUT))
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(EXPECTED, json.loads(content)["sourceResource"])
def test_description_transform1():
    INPUT = {"metadata": {"mods": {"note": "A description"}}}
    EXPECTED = {"description": "A description"}

    resp, content = _get_server_response(json.dumps(INPUT), provider="HARVARD")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(EXPECTED, json.loads(content)["sourceResource"])
Пример #29
0
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)
Пример #30
0
def test_thumbnail_url_prefix_NJP1():
    hathi_record = hathi_records["njp1"]
    thumbnail_url = "http://bks4.books.google.com/books?id=GswtcRL0tZ0C&printsec=frontcover&img=1&zoom=5"
    thumbnail_urls = [thumbnail_url, thumbnail_url + "&edge=curl"]

    resp, content = _get_server_response(json.dumps(hathi_record))
    print_error_log()
    assert resp.status == 200
    assert json.loads(content).get("object") in thumbnail_urls
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)
Пример #32
0
def test_thumbnail_url_prefix_UC1_UCSC3():
    hathi_record = hathi_records["uc1_ucsc3"]
    thumbnail_url = "http://bks7.books.google.com/books?id=66C4AAAAIAAJ&printsec=frontcover&img=1&zoom=5"
    thumbnail_urls = [thumbnail_url, thumbnail_url + "&edge=curl"]

    resp, content = _get_server_response(json.dumps(hathi_record))
    print_error_log()
    assert resp.status == 200
    assert json.loads(content).get("object") in thumbnail_urls
Пример #33
0
def test_substitution_with_missing_value_and_the_same_field():
    """Should remove the field if value is missing from dict."""
    data = {"xxx": "yyy", "aaa": {"bbb": "ccc", "xxx": "doesnt exist"}}
    INPUT = json.dumps(data)
    data = {"xxx": "yyy", "aaa": {"bbb": "ccc"}}
    EXPECTED_OUTPUT = json.dumps(data)
    resp, content = _get_server_response(INPUT, "aaa/xxx", "aaa/xxx", "test2", None, True)
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #34
0
def test_no_params_with_languages():
    """
Should return converted JSON for no param.
"""
    INPUT = {"sourceResource": {"language": "aaa"}}
    resp, content = _get_server_response(json.dumps(INPUT))
    INPUT["sourceResource"]["language"] = {"name": "aaa"}
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(INPUT, content)
def test_simple_substitute_for_different_field():
    """
    Should return substituted another json field.
    """
    INPUT = '{"aaa":"bbb"}'
    EXPECTED_OUTPUT = '{"aaa":"bbb", "xxx":"BBB"}'
    resp, content = _get_server_response(INPUT, "aaa", "xxx", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #36
0
def test_substitution_with_missing_subst_dict():
    """
    Should return the same JSON when the key is missing from substitution.
    """
    INPUT = '{"aaa":"bbb"}'
    resp, content = _get_server_response(INPUT, "aaa", "aaa", "aaa")
    print (content)
    print_error_log()
    assert resp.status == 500
    assert content == "Missing substitution dictionary [aaa]"
def test_substitution_with_missing_subst_dict():
    """
    Should return the same JSON when the key is missing from substitution.
    """
    INPUT = '{"aaa":"bbb"}'
    resp, content = _get_server_response(INPUT, "aaa", "aaa", "aaa")
    print(content)
    print_error_log()
    assert resp.status == 500
    assert content == "Missing substitution dictionary [aaa]"
Пример #38
0
def test_simple_substitute_for_different_field():
    """
    Should return substituted another json field.
    """
    INPUT = '{"aaa":"bbb"}'
    EXPECTED_OUTPUT = '{"aaa":"bbb", "xxx":"BBB"}'
    resp, content = _get_server_response(INPUT, "aaa", "xxx", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #39
0
def test_iso_match():
    """
    Should return ISO 639-3 codes
    """
    INPUT = {"language": ["ger", "jpn", "en-US", "fr/FR", "af", "afr"]}
    EXPECTED = {"language": ["ger", "jpn", "eng", "fra", "afr"]}

    resp, content = _get_server_response(json.dumps(INPUT), prop="language")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED)
def test_substitution_with_missing_key():
    """
    Should return the same JSON when the key is missing from substitution.
    """
    INPUT = '{"aaa":"bbb"}'
    resp, content = _get_server_response(INPUT, "bbb", "bbb", "test")

    print_error_log()
    pinfo(content)
    assert resp.status == 200
    assert_same_jsons(INPUT, content)
Пример #41
0
def test_substitution_with_missing_key():
    """
    Should return the same JSON when the key is missing from substitution.
    """
    INPUT = '{"aaa":"bbb"}'
    resp, content = _get_server_response(INPUT, "bbb", "bbb", "test")

    print_error_log()
    pinfo(content)
    assert resp.status == 200
    assert_same_jsons(INPUT, content)
Пример #42
0
def test_date_with_parentheses_and_question_mark():
    """Should handle date like 1928 (?)"""
    INPUT = {"date": "1928 (?)"}
    EXPECTED = {"date": {"begin": "1928", "end": "1928", "displayDate": "1928 (?)"}}

    url = server() + "enrich_earliest_date?prop=date"

    resp, content = H.request(url, "POST", body=json.dumps(INPUT))
    print_error_log()
    assert str(resp.status).startswith("2")
    assert_same_jsons(EXPECTED, content)
Пример #43
0
def test_wordy_date():
    """Should handle very wordy dates"""
    INPUT = {"date": "mid 11th century AH/AD 17th century (Mughal)"}
    EXPECTED = {"date": {"begin": None, "end": None, "displayDate": INPUT["date"]}}

    url = server() + "enrich_earliest_date?prop=date"

    resp, content = H.request(url, "POST", body=json.dumps(INPUT))
    print_error_log()
    assert str(resp.status).startswith("2")
    assert_same_jsons(EXPECTED, content)
Пример #44
0
def test_reversed_date_range():
    """Should handle reversed date range"""
    INPUT = {"date": "1911/0140"}
    EXPECTED = {"date": {"begin": "0140", "end": "1911", "displayDate": INPUT["date"]}}

    url = server() + "enrich_earliest_date?prop=date"

    resp, content = H.request(url, "POST", body=json.dumps(INPUT))
    print_error_log()
    assert str(resp.status).startswith("2")
    assert_same_jsons(EXPECTED, content)
Пример #45
0
def test_removing_date_string():
    INPUT = {
        "sourceResource": {
            "date": "aaa",
        }
    }
    EXPECTED_OUTPUT = {"sourceResource": {}}
    resp, content = _get_server_response(INPUT, "sourceResource/date")
    print_error_log()
    assert resp["status"].startswith("2")
    assert_same_jsons(EXPECTED_OUTPUT, content)
def test_substitution_for_different_fields_and_array():
    """
    Should return json when original json is array.
    """
    data = {"xxx": "yyy", "aaa": ["aa", "bbb", "ccc", "ddd"]}
    INPUT = json.dumps(data)
    data["zzz"] = ["aa", "BBB", "CCC", "DDD"]
    EXPECTED_OUTPUT = json.dumps(data)
    resp, content = _get_server_response(INPUT, "aaa", "zzz", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
def test_dictionary_subsitution():
    """
    Should substitute when there is dictionary field.
    """
    data = {"xxx": "yyy", "aaa": {"bbb": "ccc"}}
    INPUT = json.dumps(data)
    data["aaa"] = {"bbb": "CCC"}
    EXPECTED_OUTPUT = json.dumps(data)
    resp, content = _get_server_response(INPUT, "aaa/bbb", "aaa/bbb", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #48
0
def test_populating_data_provider_field():
    INPUT = {
            "descriptiveNonRepeating": {
                "data_source": "Smithsonian Institution Archives",
                }
            }
    resp, content = _get_server_response(INPUT)
    pinfo(content)
    print_error_log()
    assert resp["status"].startswith("2")
    CONTENT = json.loads(content)
    assert CONTENT["dataProvider"] == "Smithsonian Institution Archives"
Пример #49
0
def test_substitution_for_different_fields_and_array():
    """
    Should return json when original json is array.
    """
    data = {"xxx": "yyy", "aaa": ["aa", "bbb", "ccc", "ddd"]}
    INPUT = json.dumps(data)
    data["zzz"] = ["aa", "BBB", "CCC", "DDD"]
    EXPECTED_OUTPUT = json.dumps(data)
    resp, content = _get_server_response(INPUT, "aaa", "zzz", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #50
0
def test_dictionary_subsitution():
    """
    Should substitute when there is dictionary field.
    """
    data = {"xxx": "yyy", "aaa": {"bbb": "ccc"}}
    INPUT = json.dumps(data)
    data["aaa"] = {"bbb": "CCC"}
    EXPECTED_OUTPUT = json.dumps(data)
    resp, content = _get_server_response(INPUT, "aaa/bbb", "aaa/bbb", "test")
    print_error_log()
    assert resp.status == 200
    assert_same_jsons(content, EXPECTED_OUTPUT)
Пример #51
0
def test_cleanup_value_for_string():
    INPUT = {
        "aaa": {
            "bbb": "Fisker, Kay--Architect--Danish--Male",
        }
    }
    EXPECTED_OUTPUT = {
        "aaa": {
            "bbb": "Fisker, Kay",
        }
    }
    resp, content = _get_server_response(json.dumps(INPUT), "aaa/bbb")
    print_error_log()
    assert resp["status"].startswith("2")
    assert_same_jsons(EXPECTED_OUTPUT, content)