aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/transform_toml.py22
-rw-r--r--python/tests/web_editing.py131
-rw-r--r--python/tests/web_entity_views.py16
3 files changed, 152 insertions, 17 deletions
diff --git a/python/tests/transform_toml.py b/python/tests/transform_toml.py
new file mode 100644
index 00000000..d12ba027
--- /dev/null
+++ b/python/tests/transform_toml.py
@@ -0,0 +1,22 @@
+
+import json
+
+from fatcat_tools import *
+from fatcat_openapi_client import *
+from import_crossref import crossref_importer
+from fixtures import *
+
+
+def test_basic_toml(crossref_importer):
+ with open('tests/files/crossref-works.single.json', 'r') as f:
+ # not a single line
+ raw = json.loads(f.read())
+ r = crossref_importer.parse_record(raw)
+ r.state = 'active'
+ toml_str = entity_to_toml(r)
+ r2 = entity_from_toml(toml_str, ReleaseEntity)
+ assert r == r2
+
+ toml_str = entity_to_toml(r, pop_fields=['ident', 'revision', 'blah', 'extra'])
+ r3 = entity_from_toml(toml_str, ReleaseEntity)
+ assert r != r3
diff --git a/python/tests/web_editing.py b/python/tests/web_editing.py
index 17f4f5ae..fb8b3f93 100644
--- a/python/tests/web_editing.py
+++ b/python/tests/web_editing.py
@@ -2,7 +2,7 @@
from fixtures import *
-def test_web_release_create_merge(app_admin, api):
+def test_web_release_create_accept(app_admin, api):
eg = quick_eg(api)
@@ -24,6 +24,18 @@ def test_web_release_create_merge(app_admin, api):
#assert b'badmojo' in rv.data
assert b'Not a valid choice' in rv.data
+ # bad wikidata QID
+ rv = app_admin.post('/release/create',
+ data={
+ 'editgroup_id': eg.editgroup_id,
+ 'release_type': 'article-journal',
+ 'release_stage': 'published',
+ 'title': 'something bogus',
+ 'wikidata_qid': '884',
+ },
+ follow_redirects=True)
+ assert rv.status_code == 400
+
# ok/valid submit
rv = app_admin.post('/release/create',
data={
@@ -31,9 +43,11 @@ def test_web_release_create_merge(app_admin, api):
'release_type': 'article-journal',
'release_stage': 'published',
'title': 'something bogus',
+ 'doi': '10.1234/999999',
},
follow_redirects=True)
assert rv.status_code == 200
+ assert b'10.1234/999999' in rv.data
rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
assert rv.status_code == 200
@@ -129,18 +143,117 @@ def test_web_file_create(app_admin, api):
follow_redirects=True)
assert rv.status_code == 200
+def test_web_file_toml_create(app_admin, api):
-def test_web_edit_get(app_admin):
+ eg = quick_eg(api)
- # these are all existing entities
- rv = app_admin.get('/release/aaaaaaaaaaaaarceaaaaaaaaai/edit')
+ # bogus/bad submit
+ rv = app_admin.post('/file/create/toml',
+ data={
+ 'editgroup_id': eg.editgroup_id,
+ },
+ follow_redirects=True)
+ assert rv.status_code == 400
+
+ # ok/valid submit
+ rv = app_admin.post('/file/create/toml',
+ data={
+ 'editgroup_id': eg.editgroup_id,
+ 'toml': """
+size = 12345
+sha1 = "45be56a396c4d03faaa41e055170c23534dec736"
+ """,
+ },
+ follow_redirects=True)
assert rv.status_code == 200
- assert b'A bigger example' in rv.data
- rv = app_admin.get('/file/aaaaaaaaaaaaamztaaaaaaaaam/edit')
+ # upper-case SHA-1
+ rv = app_admin.post('/file/create/toml',
+ data={
+ 'editgroup_id': eg.editgroup_id,
+ 'toml': """
+size = 12345
+sha1 = "45BE56A396C4D03FAAA41E055170C23534DEC736"
+ """,
+ },
+ follow_redirects=True)
+ assert rv.status_code == 400
+
+def test_web_file_delete(app_admin, api):
+
+ eg = quick_eg(api)
+
+ rv = app_admin.get('/file/aaaaaaaaaaaaamztaaaaaaaaam/delete')
assert rv.status_code == 200
- assert b'ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362' in rv.data
- rv = app_admin.get('/container/aaaaaaaaaaaaaeiraaaaaaaaam/edit')
+ rv = app_admin.post('/file/aaaaaaaaaaaaamztaaaaaaaaam/delete',
+ data={
+ 'editgroup_id': eg.editgroup_id,
+ },
+ follow_redirects=True)
assert rv.status_code == 200
- assert b'1549-1277' in rv.data
+ # NOTE: did not *accept* the deletion edit
+
+DUMMY_DEMO_ENTITIES = {
+ 'container': 'aaaaaaaaaaaaaeiraaaaaaaaam',
+ 'creator': 'aaaaaaaaaaaaaircaaaaaaaaaq',
+ 'file': 'aaaaaaaaaaaaamztaaaaaaaaam',
+ 'fileset': 'aaaaaaaaaaaaaztgaaaaaaaaai',
+ 'webcapture': 'aaaaaaaaaaaaa53xaaaaaaaaai',
+ 'release': 'aaaaaaaaaaaaarceaaaaaaaaai',
+ 'work': 'aaaaaaaaaaaaavkvaaaaaaaaai',
+}
+
+def test_web_edit_get(app_admin):
+
+ # these are all existing entities
+ for entity_type in ['release', 'file', 'container']:
+ rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit')
+ assert rv.status_code == 200
+ if entity_type == 'release':
+ assert b'A bigger example' in rv.data
+ elif entity_type == 'file':
+ assert b'ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362' in rv.data
+ elif entity_type == 'container':
+ assert b'1549-1277' in rv.data
+
+ rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit/toml')
+ assert rv.status_code == 200
+ if entity_type == 'release':
+ assert b'A bigger example' in rv.data
+ elif entity_type == 'file':
+ assert b'ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362' in rv.data
+ elif entity_type == 'container':
+ assert b'1549-1277' in rv.data
+
+ # TOML-only endpoints
+ for entity_type in ['creator', 'fileset', 'webcapture', 'work']:
+ rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit')
+ assert rv.status_code == 302
+
+ rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit/toml')
+ assert rv.status_code == 200
+
+
+def test_web_create_get(app_admin):
+
+ for entity_type in ['release', 'file', 'container']:
+ rv = app_admin.get(f'/{entity_type}/create')
+ assert rv.status_code == 200
+
+ rv = app_admin.get(f'/{entity_type}/create/toml')
+ assert rv.status_code == 200
+
+ # these are TOML only
+ for entity_type in ['creator', 'fileset', 'webcapture', 'work']:
+ rv = app_admin.get(f'/{entity_type}/create')
+ assert rv.status_code == 302
+
+ rv = app_admin.get(f'/{entity_type}/create/toml')
+ assert rv.status_code == 200
+
+def test_web_edit_delete(app_admin):
+
+ for entity_type in DUMMY_DEMO_ENTITIES.keys():
+ rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/delete')
+ assert rv.status_code == 200
diff --git a/python/tests/web_entity_views.py b/python/tests/web_entity_views.py
index b01bd815..7b973ef2 100644
--- a/python/tests/web_entity_views.py
+++ b/python/tests/web_entity_views.py
@@ -210,9 +210,9 @@ def test_web_creator(app):
rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai')
assert rv.status_code == 200
rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai/edit')
- assert rv.status_code == 404
+ assert rv.status_code == 302
rv = app.get('/creator/create')
- assert rv.status_code == 404
+ assert rv.status_code == 302
def test_web_file(app):
@@ -266,9 +266,9 @@ def test_web_fileset(app):
rv = app.get('/fileset/aaaaaaaaaaaaaztgaaaaaaaaai')
assert rv.status_code == 200
rv = app.get('/fileset/aaaaaaaaaaaaaztgaaaaaaaaai/edit')
- assert rv.status_code == 404
+ assert rv.status_code == 302
rv = app.get('/fileset/create')
- assert rv.status_code == 404
+ assert rv.status_code == 302
def test_web_webcatpure(app):
@@ -277,9 +277,9 @@ def test_web_webcatpure(app):
rv = app.get('/webcapture/aaaaaaaaaaaaa53xaaaaaaaaai')
assert rv.status_code == 200
rv = app.get('/webcapture/aaaaaaaaaaaaa53xaaaaaaaaai/edit')
- assert rv.status_code == 404
+ assert rv.status_code == 302
rv = app.get('/webcapture/create')
- assert rv.status_code == 404
+ assert rv.status_code == 302
def test_web_release(app):
@@ -376,6 +376,6 @@ 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
+ assert rv.status_code == 302
rv = app.get('/work/create')
- assert rv.status_code == 404
+ assert rv.status_code == 302