summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-18 19:08:32 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-18 19:08:32 -0800
commit629eec677d0a0c5c4110a1993a93c71b33021f28 (patch)
tree8a228eae52a38878c4384cf05d72577bbe162348
parent2477a3dc9b9ca4e7889bd894997118bf455c3213 (diff)
downloadfatcat-629eec677d0a0c5c4110a1993a93c71b33021f28.tar.gz
fatcat-629eec677d0a0c5c4110a1993a93c71b33021f28.zip
basic tests for filesets and webcaptures
-rw-r--r--python/tests/api_filesets.py71
-rw-r--r--python/tests/api_webcaptures.py89
2 files changed, 160 insertions, 0 deletions
diff --git a/python/tests/api_filesets.py b/python/tests/api_filesets.py
new file mode 100644
index 00000000..58ee7b5c
--- /dev/null
+++ b/python/tests/api_filesets.py
@@ -0,0 +1,71 @@
+
+import json
+import pytest
+from copy import copy
+
+from fatcat_client import *
+from fatcat_client.rest import ApiException
+from fixtures import *
+
+
+def test_fileset(api):
+
+ eg = quick_eg(api)
+ r1 = ReleaseEntity(title="test fileset release")
+ r1edit = api.create_release(r1, editgroup_id=eg.editgroup_id)
+
+ fs1 = FilesetEntity()
+ fs1.manifest = [
+ FilesetEntityManifest(
+ path="data/thing.tar.gz",
+ size=54321,
+ md5="540da3ea6e448d8dfb057c05225f853a",
+ sha1="1dab6a0e110f9b5d70b18db0abf051f7f93faf06",
+ sha256="c7b49f3e84cd1b7cb0b0e3e9f632b7be7e21b4dc229df23331f880a8a7dfa75a",
+ extra={"a": 1, "b": 3},
+ ),
+ FilesetEntityManifest(
+ path="README.md",
+ size=54210,
+ md5="5f83592b5249671719bbed6ce91ecfa8",
+ sha1="455face3598611458efe1f072e58624790a67266",
+ sha256="429bcafa4d3d0072d5b2511e12c85c1aac1d304011d1c406da14707f7b9cd905",
+ extra={"x": 1, "y": "q"},
+ ),
+ ]
+ fs1.urls = [
+ FileEntityUrls(url="https://archive.org/download/fileset-123/", rel="repository"),
+ FileEntityUrls(url="https://humble-host.com/~user123/dataset/", rel="web"),
+ ]
+ fs1.release_ids = [r1edit.ident]
+
+ fs1edit = api.create_fileset(fs1, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
+ fs2 = api.get_fileset(fs1edit.ident)
+
+ # check that fields match
+ assert fs1.urls == fs2.urls
+ assert fs1.manifest == fs2.manifest
+ assert fs1.release_ids == fs2.release_ids
+
+ # expansion
+ r1 = api.get_release(r1edit.ident, expand="filesets")
+ assert r1.filesets[0].manifest == fs1.manifest
+
+
+def test_bad_fileset(api):
+
+ eg = quick_eg(api)
+
+ bad_list = [
+ # good (for testing test itself)
+ #FilesetEntity(manifest=[FilesetEntityManifest(path="123.jpg", size=1234)]),
+ #FilesetEntity(urls=[FileEntityUrls(url="thing", rel="blah")]),
+ FilesetEntity(manifest=[FilesetEntityManifest(path="123.jpg", size="big")]),
+ FilesetEntity(release_ids=["asdf"]),
+ ]
+
+ for b in bad_list:
+ with pytest.raises(fatcat_client.rest.ApiException):
+ api.create_fileset(b, editgroup_id=eg.editgroup_id)
+
diff --git a/python/tests/api_webcaptures.py b/python/tests/api_webcaptures.py
new file mode 100644
index 00000000..6af32bc8
--- /dev/null
+++ b/python/tests/api_webcaptures.py
@@ -0,0 +1,89 @@
+
+import json
+import pytest
+import datetime
+from copy import copy
+
+from fatcat_client import *
+from fatcat_client.rest import ApiException
+from fixtures import *
+
+
+def test_webcapture(api):
+
+ eg = quick_eg(api)
+ r1 = ReleaseEntity(title="test webcapture release")
+ r1edit = api.create_release(r1, editgroup_id=eg.editgroup_id)
+
+ wc1 = WebcaptureEntity(
+ original_url = "http://example.site",
+ #timestamp = "2012-01-02T03:04:05Z",
+ timestamp = datetime.datetime.now(datetime.timezone.utc),
+ )
+ wc1.cdx = [
+ WebcaptureEntityCdx(
+ surt="site,example,)/data/thing.tar.gz",
+ #timestamp="2012-01-02T03:04:05Z",
+ timestamp=datetime.datetime.now(datetime.timezone.utc),
+ url="http://example.site/data/thing.tar.gz",
+ mimetype="application/gzip",
+ status_code=200,
+ sha1="455face3598611458efe1f072e58624790a67266",
+ sha256="c7b49f3e84cd1b7cb0b0e3e9f632b7be7e21b4dc229df23331f880a8a7dfa75a",
+ ),
+ WebcaptureEntityCdx(
+ surt="site,example,)/README.md",
+ #timestamp="2012-01-02T03:04:05Z",
+ timestamp=datetime.datetime.now(datetime.timezone.utc),
+ url="http://example.site/README.md",
+ mimetype="text/markdown",
+ status_code=200,
+ sha1="455face3598611458efe1f072e58624790a67266",
+ sha256="429bcafa4d3d0072d5b2511e12c85c1aac1d304011d1c406da14707f7b9cd905",
+ ),
+ ]
+ wc1.archive_urls = [
+ FileEntityUrls(rel="wayback", url="https://web.archive.org/web/"),
+ ]
+ wc1.release_ids = [r1edit.ident]
+
+ wc1edit = api.create_webcapture(wc1, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
+ wc2 = api.get_webcapture(wc1edit.ident)
+
+ # 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
+ assert wc1.cdx == wc2.cdx
+ assert wc1.release_ids == wc2.release_ids
+ assert wc1.timestamp == wc2.timestamp
+ assert wc1.original_url == wc2.original_url
+
+ # TODO: check release expansion
+ r1 = api.get_release(r1edit.ident, expand="webcaptures")
+ print(r1)
+ assert r1.webcaptures[0].cdx == wc1.cdx
+
+
+def test_bad_webcapture(api):
+
+ eg = quick_eg(api)
+
+ bad_list = [
+ # good (for testing test itself)
+ WebcaptureEntity(cdx=[
+ WebcaptureEntityCdx(
+ surt="site,example,)/123.jpg",
+ url="http://example.site/123.jpg",
+ sha1="455face3598611458efe1f072e58624790a67266",
+ timestamp=201506071122)]),
+ ]
+
+ for b in bad_list:
+ with pytest.raises(fatcat_client.rest.ApiException):
+ api.create_webcapture(b, editgroup_id=eg.editgroup_id)
+