diff options
Diffstat (limited to 'python/tests')
| -rw-r--r-- | python/tests/api_releases.py | 49 | ||||
| -rw-r--r-- | python/tests/api_webcaptures.py | 70 | 
2 files changed, 114 insertions, 5 deletions
| diff --git a/python/tests/api_releases.py b/python/tests/api_releases.py index 23b01fb2..264bea8f 100644 --- a/python/tests/api_releases.py +++ b/python/tests/api_releases.py @@ -16,11 +16,15 @@ def test_release(api):      # all the fields!      r1 = ReleaseEntity(          title="some title", +        subtitle="son of some title",          original_title="оригинальное название",          release_type="post-weblog",          release_stage="submitted",          release_date=datetime.datetime.utcnow().date(),          release_year=2015, +        withdrawn_status="withdrawn", +        withdrawn_year=2017, +        withdrawn_date="2017-04-10",          ext_ids=ReleaseEntityExtIds(              doi="10.5555/12345678",              pmid="12345", @@ -30,15 +34,29 @@ def test_release(api):              core="187348",              arxiv="aslkdjfh",              jstor="8328424", +            mag="9439328", +            ark="ark:/12025/654xz321",          ),          volume="84", +        number="RFC1234", +        version="v4",          issue="XII",          pages="4-99",          publisher="some publisher",          language="en",          license_slug="CC-0",          extra=dict(a=1, b=2), -        contribs=[], +        contribs=[ +            ReleaseContrib( +                given_name="Paul", +                surname="Otlet"), +            ReleaseContrib( +                raw_name="Cindy Sherman", +                given_name="Cindy", +                surname="Sherman"), +            ReleaseContrib( +                raw_name="Andy Warhol"), +        ],          refs=[],          abstracts=[              ReleaseEntityAbstracts( @@ -51,6 +69,7 @@ def test_release(api):                  lang="de"),          ],      ) +    r1.bogus = "asdf"      r1edit = api.create_release(r1, editgroup_id=eg.editgroup_id)      api.accept_editgroup(eg.editgroup_id) @@ -64,10 +83,15 @@ def test_release(api):      # check that fields match      assert r1.title == r2.title +    assert r1.subtitle == r2.subtitle      assert r1.original_title == r2.original_title      assert r1.release_type == r2.release_type +    assert r1.release_stage == r2.release_stage      assert r1.release_date == r2.release_date      assert r1.release_year == r2.release_year +    assert r1.withdrawn_status == r2.withdrawn_status +    assert r1.withdrawn_date == r2.withdrawn_date +    assert r1.withdrawn_year == r2.withdrawn_year      assert r1.ext_ids.doi == r2.ext_ids.doi      assert r1.ext_ids.pmid == r2.ext_ids.pmid      assert r1.ext_ids.pmcid == r2.ext_ids.pmcid @@ -76,6 +100,10 @@ def test_release(api):      assert r1.ext_ids.core == r2.ext_ids.core      assert r1.ext_ids.arxiv == r2.ext_ids.arxiv      assert r1.ext_ids.jstor == r2.ext_ids.jstor +    assert r1.ext_ids.ark == r2.ext_ids.ark +    assert r1.ext_ids.mag == r2.ext_ids.mag +    assert r1.number == r2.number +    assert r1.version == r2.version      assert r1.volume == r2.volume      assert r1.issue == r2.issue      assert r1.pages == r2.pages @@ -111,7 +139,26 @@ def test_release(api):  def test_release_examples(api):      api.lookup_release(pmid='54321') +    api.lookup_release(doi='10.123/abc')      api.lookup_release(isbn13='978-3-16-148410-0') +    api.lookup_release(arxiv='1905.03769v1') +    api.lookup_release(jstor='1819117828') +    api.lookup_release(ark='ark:/asdf/924') +    api.lookup_release(mag='992489213') + +    # failed lookup exception type +    try: +        api.lookup_release(pmid='5432100') +    except fatcat_client.rest.ApiException as ae: +        assert ae.status == 404 +        assert "DatabaseRowNotFound" in ae.body + +    # failed lookup formatting +    try: +        api.lookup_release(doi='blah') +    except fatcat_client.rest.ApiException as ae: +        assert ae.status == 400 +        assert "MalformedExternalId" in ae.body      r1 = api.get_release('aaaaaaaaaaaaarceaaaaaaaaai')      assert r1.title.startswith("A bigger example") diff --git a/python/tests/api_webcaptures.py b/python/tests/api_webcaptures.py index 1bba5747..e5c516d1 100644 --- a/python/tests/api_webcaptures.py +++ b/python/tests/api_webcaptures.py @@ -27,6 +27,7 @@ def test_webcapture(api):                  url="http://example.site/data/thing.tar.gz",                  mimetype="application/gzip",                  status_code=200, +                size_bytes=1234,                  sha1="455face3598611458efe1f072e58624790a67266",                  sha256="c7b49f3e84cd1b7cb0b0e3e9f632b7be7e21b4dc229df23331f880a8a7dfa75a",              ), @@ -37,6 +38,7 @@ def test_webcapture(api):                  url="http://example.site/README.md",                  mimetype="text/markdown",                  status_code=200, +                size_bytes=4321,                  sha1="455face3598611458efe1f072e58624790a67266",                  sha256="429bcafa4d3d0072d5b2511e12c85c1aac1d304011d1c406da14707f7b9cd905",              ), @@ -64,6 +66,8 @@ def test_webcapture(api):      #assert wc1.archive_urls == wc2.archive_urls      assert wc1.archive_urls[0].rel == wc2.archive_urls[0].rel      assert wc1.archive_urls[0].url == wc2.archive_urls[0].url +    assert wc1.cdx[0] == wc2.cdx[0] +    assert wc1.cdx[0].size_bytes == wc2.cdx[0].size_bytes      assert wc1.cdx == wc2.cdx      assert wc1.release_ids == wc2.release_ids      assert wc1.timestamp == wc2.timestamp @@ -96,17 +100,75 @@ def test_bad_webcapture(api):      eg = quick_eg(api) +    # good (as a template) +    good = WebcaptureEntity( +        original_url="http://example.site/123.jpg", +        timestamp="2012-01-02T03:04:05Z", +        cdx=[WebcaptureEntityCdx( +            surt="site,example,)/123.jpg", +            url="http://example.site/123.jpg", +            sha1="455face3598611458efe1f072e58624790a67266", +            timestamp="2012-01-02T03:04:05Z")]) +      bad_list = [ -        # good (for testing test itself) -        WebcaptureEntity(cdx=[ -            WebcaptureEntityCdx( +        # uncomment to "test the test" +        #good, +        # CDX timestamp format +        WebcaptureEntity( +            original_url="http://example.site/123.jpg", +            timestamp="2012-01-02T03:04:05Z", +            cdx=[WebcaptureEntityCdx( +                surt="site,example,)/123.jpg", +                url="http://example.site/123.jpg", +                sha1="455face3598611458efe1f072e58624790a67266", +                size_bytes=123, +                timestamp="20120102030405")]), +        # CDX timestamp format (int) +        WebcaptureEntity( +            original_url="http://example.site/123.jpg", +            timestamp="2012-01-02T03:04:05Z", +            cdx=[WebcaptureEntityCdx( +                surt="site,example,)/123.jpg", +                url="http://example.site/123.jpg", +                sha1="455face3598611458efe1f072e58624790a67266", +                timestamp=20120102030405)]), +        # negative size +        WebcaptureEntity( +            original_url="http://example.site/123.jpg", +            timestamp="2012-01-02T03:04:05Z", +            cdx=[WebcaptureEntityCdx(                  surt="site,example,)/123.jpg",                  url="http://example.site/123.jpg",                  sha1="455face3598611458efe1f072e58624790a67266", -                timestamp=201506071122)]), +                size_bytes=-123, +                timestamp="20120102030405")]),      ] +    api.create_webcapture(good, editgroup_id=eg.editgroup_id)      for b in bad_list:          with pytest.raises(fatcat_client.rest.ApiException):              api.create_webcapture(b, editgroup_id=eg.editgroup_id) +    with pytest.raises(ValueError): +        # missing/empty CDX url +        WebcaptureEntity( +            original_url="http://example.site/123.jpg", +            timestamp="2012-01-02T03:04:05Z", +            cdx=[WebcaptureEntityCdx( +                #url="http://example.site/123.jpg", +                surt="site,example,)/123.jpg", +                sha1="455face3598611458efe1f072e58624790a67266", +                timestamp="2012-01-02T03:04:05Z", +            )]) + +    with pytest.raises(ValueError): +        # missing/empty CDX timestamp +        WebcaptureEntity( +            original_url="http://example.site/123.jpg", +            timestamp="2012-01-02T03:04:05Z", +            cdx=[WebcaptureEntityCdx( +                url="http://example.site/123.jpg", +                surt="site,example,)/123.jpg", +                sha1="455face3598611458efe1f072e58624790a67266", +                #timestamp="2012-01-02T03:04:05Z", +            )]) | 
