From 282c38de521da379a2ea6407c6ff72e21f09c65c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 5 Nov 2021 14:40:07 -0700 Subject: python tests: verify array sort order In a couple cases (eg, filesets), had made tests agnostic to sort order, because the sort order was not stable. In other cases, simply small cleanups and comment improvements. --- python/tests/api_containers.py | 1 + python/tests/api_files.py | 4 ++++ python/tests/api_filesets.py | 8 ++------ python/tests/api_webcaptures.py | 25 +++++++++++-------------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/python/tests/api_containers.py b/python/tests/api_containers.py index d6fd421a..f185fdb2 100644 --- a/python/tests/api_containers.py +++ b/python/tests/api_containers.py @@ -11,6 +11,7 @@ def test_container(api): name="some container name", container_type="journal", publisher="some container publisher", + publication_status="active", issnl="1234-567X", issne="1230-0000", issnp="1234-0001", diff --git a/python/tests/api_files.py b/python/tests/api_files.py index 443fe63f..8f9caf3e 100644 --- a/python/tests/api_files.py +++ b/python/tests/api_files.py @@ -18,6 +18,10 @@ def test_file(api): url="https://web.archive.org/web/12345542/something.com/blah.pdf", rel="webarchive", ), + FileUrl( + url="https://something.com/blah.pdf", + rel="web", + ), ], release_ids=[], extra=dict(a=2, b=5), diff --git a/python/tests/api_filesets.py b/python/tests/api_filesets.py index 1ec0df17..d7654eb9 100644 --- a/python/tests/api_filesets.py +++ b/python/tests/api_filesets.py @@ -50,17 +50,13 @@ def test_fileset(api): # check that fields match assert fs1.urls == fs2.urls - # XXX: manifest return order is *NOT* currently stable - assert (fs1.manifest == fs2.manifest) or (fs1.manifest == list(reversed(fs2.manifest))) + assert fs1.manifest == fs2.manifest assert fs1.release_ids == fs2.release_ids assert fs1.extra == fs2.extra # expansion r1 = api.get_release(r1edit.ident, expand="filesets") - # XXX: manifest return order is *NOT* currently stable - assert (r1.filesets[0].manifest == fs1.manifest) or ( - r1.filesets[0].manifest == list(reversed(fs1.manifest)) - ) + assert r1.filesets[0].manifest == fs1.manifest # get redirects (none) assert api.get_fileset_redirects(fs2.ident) == [] diff --git a/python/tests/api_webcaptures.py b/python/tests/api_webcaptures.py index 36bf40e9..76bc68c0 100644 --- a/python/tests/api_webcaptures.py +++ b/python/tests/api_webcaptures.py @@ -11,15 +11,17 @@ def test_webcapture(api): r1 = ReleaseEntity(title="test webcapture release", ext_ids=ReleaseExtIds()) r1edit = api.create_release(eg.editgroup_id, r1) + # using datetime.datetime in this object construction to make exact object + # comparisons easier. it is also possible to pass an ISO datetime string + # (including timezone) + now = datetime.datetime.now(datetime.timezone.utc) wc1 = WebcaptureEntity( original_url="http://example.site", - # timestamp = "2012-01-02T03:04:05Z", - timestamp=datetime.datetime.now(datetime.timezone.utc), + timestamp=now, cdx=[ WebcaptureCdxLine( surt="site,example,)/data/thing.tar.gz", - # timestamp="2012-01-02T03:04:05Z", - timestamp=datetime.datetime.now(datetime.timezone.utc), + timestamp=now, url="http://example.site/data/thing.tar.gz", mimetype="application/gzip", status_code=200, @@ -29,8 +31,7 @@ def test_webcapture(api): ), WebcaptureCdxLine( surt="site,example,)/README.md", - # timestamp="2012-01-02T03:04:05Z", - timestamp=datetime.datetime.now(datetime.timezone.utc), + timestamp=now, url="http://example.site/README.md", mimetype="text/markdown", status_code=200, @@ -59,12 +60,9 @@ def test_webcapture(api): assert wc2.timestamp == wc2_rev.timestamp # check that fields match - # I don't know why these aren't equal... - # print(wc1.archive_urls) - # print(wc2.archive_urls) - # 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 + for i in range(len(wc1.archive_urls)): + assert wc1.archive_urls[i].rel == wc2.archive_urls[i].rel + assert wc1.archive_urls[i].url == wc2.archive_urls[i].url assert wc1.cdx[0] == wc2.cdx[0] assert wc1.cdx[0].size == wc2.cdx[0].size assert wc1.cdx == wc2.cdx @@ -73,9 +71,8 @@ def test_webcapture(api): assert wc1.original_url == wc2.original_url assert wc1.extra == wc2.extra - # TODO: check release expansion + # check release expansion r1 = api.get_release(r1edit.ident, expand="webcaptures") - print(r1) assert r1.webcaptures[0].cdx == wc1.cdx # get redirects (none) -- cgit v1.2.3