summaryrefslogtreecommitdiffstats
path: root/tests/test_backend.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-04-20 14:59:09 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-04-20 14:59:09 -0700
commitfd1bc46a147c491229a307245367ac451eb1f442 (patch)
tree12003705404a7f48e315628e109ba82b42faa76c /tests/test_backend.py
parent064a68bfd8ede79c3927ab3a9d9507d5716d8154 (diff)
downloadfatcat-fd1bc46a147c491229a307245367ac451eb1f442.tar.gz
fatcat-fd1bc46a147c491229a307245367ac451eb1f442.zip
test for refs (api)
Diffstat (limited to 'tests/test_backend.py')
-rw-r--r--tests/test_backend.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/test_backend.py b/tests/test_backend.py
index 25421560..e6e15f3a 100644
--- a/tests/test_backend.py
+++ b/tests/test_backend.py
@@ -236,6 +236,24 @@ class APITestCase(FatcatTestCase):
obj = json.loads(rv.data.decode('utf-8'))
work_id = obj['id']
+ # this stub work will be referenced
+ rv = self.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 = self.app.post('/v0/release',
data=json.dumps(dict(
title="dummy work",
@@ -246,9 +264,9 @@ class APITestCase(FatcatTestCase):
doi="10.1234/5678",
editgroup=editgroup_id,
refs=[
- dict(stub="some other journal article"),
+ dict(stub="some book", target=stub_release_id),
],
- extra=dict(f=7, b="zing"))),
+ extra=dict(f=7, b="loopy"))),
headers={"content-type": "application/json"})
assert rv.status_code == 200
obj = json.loads(rv.data.decode('utf-8'))
@@ -269,9 +287,10 @@ class APITestCase(FatcatTestCase):
for cls in (WorkIdent, WorkRev, WorkEdit,
ContainerIdent, ContainerRev, ContainerEdit,
CreatorIdent, CreatorRev, CreatorEdit,
- ReleaseIdent, ReleaseRev, ReleaseEdit,
FileIdent, FileRev, FileEdit):
assert cls.query.count() == 1
+ for cls in (ReleaseIdent, ReleaseRev, ReleaseEdit):
+ assert cls.query.count() == 2
for cls in (WorkIdent,
ContainerIdent,
@@ -280,6 +299,7 @@ class APITestCase(FatcatTestCase):
FileIdent):
assert cls.query.filter(cls.is_live==True).count() == 0
+ assert ChangelogEntry.query.count() == 0
rv = self.app.post('/v0/editgroup/{}/accept'.format(editgroup_id),
headers={"content-type": "application/json"})
assert rv.status_code == 200
@@ -288,16 +308,17 @@ class APITestCase(FatcatTestCase):
for cls in (WorkIdent, WorkRev, WorkEdit,
ContainerIdent, ContainerRev, ContainerEdit,
CreatorIdent, CreatorRev, CreatorEdit,
- ReleaseIdent, ReleaseRev, ReleaseEdit,
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,
- ReleaseIdent,
FileIdent):
assert cls.query.filter(cls.is_live==True).count() == 1
+ assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 2
# Test that foreign key relations worked
release_rv = json.loads(self.app.get('/v0/release/{}'.format(release_id)).data.decode('utf-8'))
@@ -305,6 +326,7 @@ class APITestCase(FatcatTestCase):
assert(release_rv['creators'][0]['creator'] == creator_id)
assert(release_rv['container']['id'] == container_id)
assert(release_rv['work']['id'] == work_id)
+ assert(release_rv['refs'][0]['target'] == stub_release_id)
file_rv = json.loads(self.app.get('/v0/file/{}'.format(file_id)).data.decode('utf-8'))
print(file_rv)