summaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-04-04 17:50:30 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-04-04 17:50:30 -0700
commit60d7a0cdff7d41cf897373feba784a1dd2136450 (patch)
treee0d713c46a6dcf45a2bfe59de9058b83669fd816 /python/tests
parent1e93397f1a757cc4b6c566c6827f5151d88a8461 (diff)
downloadfatcat-60d7a0cdff7d41cf897373feba784a1dd2136450.tar.gz
fatcat-60d7a0cdff7d41cf897373feba784a1dd2136450.zip
add basic tests for a bunch of form handling code
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/web_entity_views.py154
1 files changed, 137 insertions, 17 deletions
diff --git a/python/tests/web_entity_views.py b/python/tests/web_entity_views.py
index 480b39cc..263a4652 100644
--- a/python/tests/web_entity_views.py
+++ b/python/tests/web_entity_views.py
@@ -4,6 +4,8 @@ import pytest
from fatcat_client.rest import ApiException
from fixtures import *
+from fatcat_web.forms import ReleaseEntityForm, FileEntityForm, ContainerEntityForm
+
DUMMY_DEMO_ENTITIES = {
'container': 'aaaaaaaaaaaaaeiraaaaaaaaai',
'creator': 'aaaaaaaaaaaaaircaaaaaaaaai',
@@ -47,18 +49,6 @@ def test_entity_basics(app):
# TODO: redirects and deleted entities
-def test_container(app_admin):
- app = app_admin
-
- rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai')
- assert rv.status_code == 200
-
- rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai/edit')
- assert rv.status_code == 200
-
- rv = app.get('/container/create')
- assert rv.status_code == 200
-
def test_lookups(app):
@@ -104,13 +94,60 @@ def test_lookups(app):
assert rv.status_code == 404
+def test_web_container(app):
+
+ rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai')
+ assert rv.status_code == 200
+ rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai/edit')
+ assert rv.status_code == 302
+ rv = app.get('/container/create')
+ assert rv.status_code == 302
+
+
+def test_web_container_login(full_app, app_admin):
+
+ rv = app_admin.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai/edit')
+ assert rv.status_code == 200
+ assert b'Journal of Trivial Results' in rv.data
+ assert b'1234-5678' in rv.data
+ rv = app_admin.get('/container/create')
+ assert rv.status_code == 200
+
+ # creation (via form)
+ with full_app.test_request_context():
+ form = ContainerEntityForm()
+ form.issnl.data = "invalid-issn"
+ rv = app_admin.post('/container/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'invalid-issn' in rv.data
+
+ with full_app.test_request_context():
+ form = ContainerEntityForm()
+ # these fields are required
+ form.name.data = "Journal of Experiments"
+ rv = app_admin.post('/container/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 200
+ assert b"Journal of Experiments" in rv.data
+
+ # editing (via form)
+ with full_app.test_request_context():
+ form = ContainerEntityForm()
+ form.issnl.data = "invalid-issn"
+ rv = app_admin.post('/container/aaaaaaaaaaaaaeiraaaaaaaaai/edit',
+ data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'invalid-issn' in rv.data
+
+
def test_web_creator(app):
# not logged in
rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai')
assert rv.status_code == 200
rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai/edit')
- assert rv.status_code == 302
+ assert rv.status_code == 404
+ rv = app.get('/creator/create')
+ assert rv.status_code == 404
def test_web_file(app):
@@ -120,8 +157,65 @@ def test_web_file(app):
assert rv.status_code == 200
rv = app.get('/file/aaaaaaaaaaaaamztaaaaaaaaai/edit')
assert rv.status_code == 302
- rv = app.get('/file/aaaaaaaaaaaaamztaaaaaaaaai/history')
+ rv = app.get('/file/create')
+ assert rv.status_code == 302
+
+
+def test_web_file_login(full_app, app_admin):
+
+ rv = app_admin.get('/file/aaaaaaaaaaaaamztaaaaaaaaai/edit')
+ assert rv.status_code == 200
+ assert b'7d97e98f8af710c7e7fe703abc8f639e0ee507c4' in rv.data
+ assert b'archive.org/robots.txt' in rv.data
+ rv = app_admin.get('/file/create')
+ assert rv.status_code == 200
+
+ # creation (via form)
+ with full_app.test_request_context():
+ form = FileEntityForm()
+ form.sha1.data = "invalidstring"
+ rv = app_admin.post('/file/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'invalidstring' in rv.data
+
+ with full_app.test_request_context():
+ form = FileEntityForm()
+ # these fields are required
+ form.size.data = 1234
+ form.sha1.data = "202f899638fcaa97128b968a43a8f45e00b69a25"
+ rv = app_admin.post('/file/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 200
+
+ # editing (via form)
+ with full_app.test_request_context():
+ form = FileEntityForm()
+ form.md5.data = "invalidstring"
+ rv = app_admin.post('/file/aaaaaaaaaaaaamztaaaaaaaaai/edit',
+ data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'invalidstring' in rv.data
+
+def test_web_fileset(app):
+ # not logged in
+
+ rv = app.get('/fileset/aaaaaaaaaaaaaztgaaaaaaaaai')
+ assert rv.status_code == 200
+ rv = app.get('/fileset/aaaaaaaaaaaaaztgaaaaaaaaai/edit')
+ assert rv.status_code == 404
+ rv = app.get('/fileset/create')
+ assert rv.status_code == 404
+
+
+def test_web_webcatpure(app):
+ # not logged in
+
+ rv = app.get('/webcapture/aaaaaaaaaaaaa53xaaaaaaaaai')
assert rv.status_code == 200
+ rv = app.get('/webcapture/aaaaaaaaaaaaa53xaaaaaaaaai/edit')
+ assert rv.status_code == 404
+ rv = app.get('/webcapture/create')
+ assert rv.status_code == 404
+
def test_web_release(app):
# not logged in
@@ -135,13 +229,41 @@ def test_web_release(app):
assert rv.status_code == 302
-def test_web_release_login(app_admin):
+def test_web_release_login(full_app, app_admin):
rv = app_admin.get('/release/aaaaaaaaaaaaarceaaaaaaaaai/edit')
assert rv.status_code == 200
+ assert b'robin hood' in rv.data
+ assert b'PMC555' in rv.data
rv = app_admin.get('/release/create')
assert rv.status_code == 200
+ # creation (via form)
+ with full_app.test_request_context():
+ form= ReleaseEntityForm()
+ form.title.data = "My Research: Missing Some Stuff"
+ rv = app_admin.post('/release/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'My Research: Missing Some Stuff' in rv.data
+
+ with full_app.test_request_context():
+ form = ReleaseEntityForm()
+ # these fields are required
+ form.title.data = "Creating Releases: A Review"
+ form.release_type.data = "article-journal"
+ form.release_status.data = "draft"
+ rv = app_admin.post('/release/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 200
+
+ # editing
+ with full_app.test_request_context():
+ form= ReleaseEntityForm()
+ form.title.data = "My Research: Missing Some Stuff"
+ form.release_type.data = "bogus-release-type"
+ rv = app_admin.post('/release/create', data=form.data, follow_redirects=True)
+ assert rv.status_code == 400
+ assert b'My Research: Missing Some Stuff' in rv.data
+
def test_web_search(app):
@@ -153,10 +275,8 @@ def test_web_work(app):
rv = app.get('/work/aaaaaaaaaaaaavkvaaaaaaaaai')
assert rv.status_code == 200
-
rv = app.get('/work/aaaaaaaaaaaaavkvaaaaaaaaai/edit')
assert rv.status_code == 404
-
rv = app.get('/work/create')
assert rv.status_code == 404