summaryrefslogtreecommitdiffstats
path: root/tests/fixtures.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-04-23 16:07:21 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-04-23 16:07:21 -0700
commit5bdd3f6e871599acb339aadc9b78cc12860f9759 (patch)
treee753e48b2becc4806bfbc8d91acb58bd75783534 /tests/fixtures.py
parentf87a203cd19f777ef328af1576e00dd59025649a (diff)
downloadfatcat-5bdd3f6e871599acb339aadc9b78cc12860f9759.tar.gz
fatcat-5bdd3f6e871599acb339aadc9b78cc12860f9759.zip
skeleton route/views
Diffstat (limited to 'tests/fixtures.py')
-rw-r--r--tests/fixtures.py124
1 files changed, 118 insertions, 6 deletions
diff --git a/tests/fixtures.py b/tests/fixtures.py
index 9176b8c5..04b4314a 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -18,15 +18,127 @@ def app():
@pytest.fixture
def rich_app(app):
- assert app.post('/v0/work',
+
+ rv = app.post('/v0/editgroup',
+ data=json.dumps(dict(
+ extra=dict(q=1, u="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ editgroup_id = obj['id']
+
+ rv = app.post('/v0/container',
+ data=json.dumps(dict(
+ name="schmournal",
+ publisher="society of authors",
+ issn="2222-3333",
+ editgroup=editgroup_id,
+ extra=dict(a=2, i="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ container_id = obj['id']
+
+ rv = app.post('/v0/creator',
+ data=json.dumps(dict(
+ name="anon y. mouse",
+ orcid="0000-0002-1825-0097",
+ editgroup=editgroup_id,
+ extra=dict(w=1, q="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ creator_id = obj['id']
+
+ rv = app.post('/v0/work',
+ data=json.dumps(dict(
+ title="dummy work",
+ work_type="book",
+ editgroup=editgroup_id,
+ extra=dict(a=3, b="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ work_id = obj['id']
+
+ # this stub work will be referenced
+ rv = app.post('/v0/release',
+ data=json.dumps(dict(
+ title="derivative work",
+ work_type="journal-article",
+ work=work_id,
+ creators=[creator_id],
+ doi="10.1234/58",
+ editgroup=editgroup_id,
+ refs=[
+ dict(stub="some other journal article"),
+ ],
+ extra=dict(f=7, b="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ stub_release_id = obj['id']
+
+ rv = app.post('/v0/release',
+ data=json.dumps(dict(
+ title="dummy work",
+ work_type="book",
+ work=work_id,
+ container=container_id,
+ creators=[creator_id],
+ doi="10.1234/5678",
+ editgroup=editgroup_id,
+ refs=[
+ dict(stub="some book", target=stub_release_id),
+ ],
+ extra=dict(f=7, b="loopy"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ release_id = obj['id']
+
+ rv = app.post('/v0/file',
data=json.dumps(dict(
- title="dummy",
- work_type="thing",
- extra=dict(a=1, b="zing"))),
- headers={"content-type": "application/json"}
- ).status_code == 200
+ sha1="deadbeefdeadbeef",
+ size=1234,
+ releases=[release_id],
+ editgroup=editgroup_id,
+ extra=dict(f=4, b="zing"))),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+ obj = json.loads(rv.data.decode('utf-8'))
+ file_id = obj['id']
+
+ rv = app.post('/v0/editgroup/{}/accept'.format(editgroup_id),
+ headers={"content-type": "application/json"})
+ assert rv.status_code == 200
+
return app
+def test_rich_app_fixture(rich_app):
+ app = rich_app
+
+ assert ChangelogEntry.query.count() == 1
+
+ for cls in (WorkIdent, WorkRev, WorkEdit,
+ ContainerIdent, ContainerRev, ContainerEdit,
+ CreatorIdent, CreatorRev, CreatorEdit,
+ FileIdent, FileRev, FileEdit):
+ assert cls.query.count() == 1
+ for cls in (ReleaseIdent, ReleaseRev, ReleaseEdit):
+ assert cls.query.count() == 2
+
+ for cls in (WorkIdent,
+ ContainerIdent,
+ CreatorIdent,
+ FileIdent):
+ assert cls.query.filter(cls.is_live==True).count() == 1
+ assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 2
+
+ # test that editor's active edit group is now invalid
+ editor = Editor.query.first()
+ assert editor.active_edit_group == None
+
## Helpers ##################################################################