summaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-28 13:22:41 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-28 13:22:41 -0700
commitc5bd3231df17fda2130e3bd51188dbe34628321a (patch)
tree10adab8b356ec82308240379085483aff94e226e /python/tests
parentaf542d66d884bd17daa6f40f3556aa4189b23b36 (diff)
downloadfatcat-c5bd3231df17fda2130e3bd51188dbe34628321a.tar.gz
fatcat-c5bd3231df17fda2130e3bd51188dbe34628321a.zip
start refactoring pythong code
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/api.py308
-rw-r--r--python/tests/codegen_tests/__init__.py (renamed from python/tests/fatcat_client/__init__.py)0
-rw-r--r--python/tests/codegen_tests/test_changelogentries.py (renamed from python/tests/fatcat_client/test_changelogentries.py)0
-rw-r--r--python/tests/codegen_tests/test_changelogentries_inner.py (renamed from python/tests/fatcat_client/test_changelogentries_inner.py)0
-rw-r--r--python/tests/codegen_tests/test_container_entity.py (renamed from python/tests/fatcat_client/test_container_entity.py)0
-rw-r--r--python/tests/codegen_tests/test_creator_entity.py (renamed from python/tests/fatcat_client/test_creator_entity.py)0
-rw-r--r--python/tests/codegen_tests/test_default_api.py (renamed from python/tests/fatcat_client/test_default_api.py)0
-rw-r--r--python/tests/codegen_tests/test_editgroup.py (renamed from python/tests/fatcat_client/test_editgroup.py)0
-rw-r--r--python/tests/codegen_tests/test_editgroup_edits.py (renamed from python/tests/fatcat_client/test_editgroup_edits.py)0
-rw-r--r--python/tests/codegen_tests/test_editor.py (renamed from python/tests/fatcat_client/test_editor.py)0
-rw-r--r--python/tests/codegen_tests/test_entity_edit.py (renamed from python/tests/fatcat_client/test_entity_edit.py)0
-rw-r--r--python/tests/codegen_tests/test_error_response.py (renamed from python/tests/fatcat_client/test_error_response.py)0
-rw-r--r--python/tests/codegen_tests/test_file_entity.py (renamed from python/tests/fatcat_client/test_file_entity.py)0
-rw-r--r--python/tests/codegen_tests/test_release_contrib.py (renamed from python/tests/fatcat_client/test_release_contrib.py)0
-rw-r--r--python/tests/codegen_tests/test_release_entity.py (renamed from python/tests/fatcat_client/test_release_entity.py)0
-rw-r--r--python/tests/codegen_tests/test_release_ref.py (renamed from python/tests/fatcat_client/test_release_ref.py)0
-rw-r--r--python/tests/codegen_tests/test_success.py (renamed from python/tests/fatcat_client/test_success.py)0
-rw-r--r--python/tests/codegen_tests/test_work_entity.py (renamed from python/tests/fatcat_client/test_work_entity.py)0
-rw-r--r--python/tests/entity_lifecycle.py80
-rw-r--r--python/tests/fixtures.py108
-rw-r--r--python/tests/models.py87
-rw-r--r--python/tests/routes.py10
-rw-r--r--python/tests/test_fixtures.py29
23 files changed, 2 insertions, 620 deletions
diff --git a/python/tests/api.py b/python/tests/api.py
deleted file mode 100644
index 02875f64..00000000
--- a/python/tests/api.py
+++ /dev/null
@@ -1,308 +0,0 @@
-
-import json
-import unittest
-import tempfile
-import pytest
-import fatcat
-import fatcat.sql
-from fatcat.models import *
-from fixtures import *
-
-
-def test_health(app):
- rv = app.get('/health')
- obj = json.loads(rv.data.decode('utf-8'))
- assert obj['ok']
-
-def test_api_work(app):
- fatcat.dummy.insert_example_works()
-
- # Invalid Id
- rv = app.get('/v0/work/_')
- assert rv.status_code == 404
-
- # Random
- rv = app.get('/v0/work/random')
- rv = app.get(rv.location)
- work = json.loads(rv.data.decode('utf-8'))
- check_entity_fields(work)
- print(work)
- assert work['title']
- assert work['work_type']
-
- # Valid Id (from random above)
- rv = app.get('/v0/work/{}'.format(work['id']))
- assert rv.status_code == 200
-
- # Missing Id
- rv = app.get('/v0/work/r3zga5b9cd7ef8gh084714iljk')
- assert rv.status_code == 404
-
-def test_api_work_create(app):
- assert WorkIdent.query.count() == 0
- assert WorkRev.query.count() == 0
- assert WorkEdit.query.count() == 0
- rv = app.post('/v0/work',
- data=json.dumps(dict(title="dummy", work_type="thing", extra=dict(a=1, b="zing"))),
- headers={"content-type": "application/json"})
- print(rv)
- assert rv.status_code == 200
- assert WorkIdent.query.count() == 1
- assert WorkRev.query.count() == 1
- assert WorkEdit.query.count() == 1
- # not alive yet
- assert WorkIdent.query.filter(WorkIdent.is_live==True).count() == 0
-
-def test_api_rich_create(app):
-
- # TODO: create user?
-
- 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']
-
- for cls in (WorkIdent, WorkRev, WorkEdit,
- ContainerIdent, ContainerRev, ContainerEdit,
- CreatorIdent, CreatorRev, CreatorEdit,
- ReleaseIdent, ReleaseRev, ReleaseEdit,
- FileIdent, FileRev, FileEdit,
- ChangelogEntry):
- assert cls.query.count() == 0
-
- 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(
- 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']
-
- 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,
- ReleaseIdent,
- FileIdent):
- assert cls.query.filter(cls.is_live==True).count() == 0
-
- assert ChangelogEntry.query.count() == 0
- rv = app.post('/v0/editgroup/{}/accept'.format(editgroup_id),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- 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 foreign key relations worked
- release_rv = json.loads(app.get('/v0/release/{}'.format(release_id)).data.decode('utf-8'))
- print(release_rv)
- 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(app.get('/v0/file/{}'.format(file_id)).data.decode('utf-8'))
- print(file_rv)
- assert file_rv['releases'][0]['release'] == release_id
-
- # test that editor's active edit group is now invalid
- editor = Editor.query.first()
- assert editor.active_editgroup is None
-
-def test_api_release_lookup(rich_app):
- app = rich_app
-
- rv = app.get('/v0/release/1',
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
-
- rv = app.get('/v0/release/lookup',
- data=json.dumps(dict(doi="10.1234/5678")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
- assert obj['doi'] == "10.1234/5678"
- assert obj.get('id') != None
-
- rv = app.get('/v0/release/lookup',
- data=json.dumps(dict(doi="10.1234/5678_noexit")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 404
-
- rv = app.get('/v0/release/lookup',
- data=json.dumps(dict(doi="not_even_valid_doi")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 400
-
-def test_api_creator_lookup(rich_app):
- app = rich_app
-
- rv = app.get('/v0/creator/1',
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
-
- rv = app.get('/v0/creator/lookup',
- data=json.dumps(dict(orcid="0000-0002-1825-0097")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
- assert obj['orcid'] == "0000-0002-1825-0097"
- assert obj.get('id') != None
-
- rv = app.get('/v0/creator/lookup',
- data=json.dumps(dict(orcid="0000-0002-1825-0098")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 404
-
- rv = app.get('/v0/creator/lookup',
- data=json.dumps(dict(orcid="not_even_valid_orcid")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 400
-
-
-def test_api_container_lookup(rich_app):
- app = rich_app
-
- rv = app.get('/v0/container/1',
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
-
- rv = app.get('/v0/container/lookup',
- data=json.dumps(dict(issn="2222-3333")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
- assert obj['issn'] == "2222-3333"
- assert obj.get('id') != None
-
- rv = app.get('/v0/container/lookup',
- data=json.dumps(dict(issn="2222-3334")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 404
-
- rv = app.get('/v0/container/lookup',
- data=json.dumps(dict(issn="not_even_valid_issn")),
- headers={"content-type": "application/json"})
- assert rv.status_code == 400
-
-def test_api_editor_get(rich_app):
- app = rich_app
-
- rv = app.get('/v0/editor/admin',
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
- print(obj)
- assert obj['username'] == "admin"
- assert obj['id'] == 1
-
-def test_api_editor_changelog(rich_app):
- app = rich_app
-
- rv = app.get('/v0/editor/admin/changelog',
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- obj = json.loads(rv.data.decode('utf-8'))
- print(obj)
- assert len(obj) == 1
diff --git a/python/tests/fatcat_client/__init__.py b/python/tests/codegen_tests/__init__.py
index e69de29b..e69de29b 100644
--- a/python/tests/fatcat_client/__init__.py
+++ b/python/tests/codegen_tests/__init__.py
diff --git a/python/tests/fatcat_client/test_changelogentries.py b/python/tests/codegen_tests/test_changelogentries.py
index 3b2bc885..3b2bc885 100644
--- a/python/tests/fatcat_client/test_changelogentries.py
+++ b/python/tests/codegen_tests/test_changelogentries.py
diff --git a/python/tests/fatcat_client/test_changelogentries_inner.py b/python/tests/codegen_tests/test_changelogentries_inner.py
index ac836714..ac836714 100644
--- a/python/tests/fatcat_client/test_changelogentries_inner.py
+++ b/python/tests/codegen_tests/test_changelogentries_inner.py
diff --git a/python/tests/fatcat_client/test_container_entity.py b/python/tests/codegen_tests/test_container_entity.py
index 0bafb7dd..0bafb7dd 100644
--- a/python/tests/fatcat_client/test_container_entity.py
+++ b/python/tests/codegen_tests/test_container_entity.py
diff --git a/python/tests/fatcat_client/test_creator_entity.py b/python/tests/codegen_tests/test_creator_entity.py
index b235b640..b235b640 100644
--- a/python/tests/fatcat_client/test_creator_entity.py
+++ b/python/tests/codegen_tests/test_creator_entity.py
diff --git a/python/tests/fatcat_client/test_default_api.py b/python/tests/codegen_tests/test_default_api.py
index cda38f38..cda38f38 100644
--- a/python/tests/fatcat_client/test_default_api.py
+++ b/python/tests/codegen_tests/test_default_api.py
diff --git a/python/tests/fatcat_client/test_editgroup.py b/python/tests/codegen_tests/test_editgroup.py
index e770fd54..e770fd54 100644
--- a/python/tests/fatcat_client/test_editgroup.py
+++ b/python/tests/codegen_tests/test_editgroup.py
diff --git a/python/tests/fatcat_client/test_editgroup_edits.py b/python/tests/codegen_tests/test_editgroup_edits.py
index 38c3c814..38c3c814 100644
--- a/python/tests/fatcat_client/test_editgroup_edits.py
+++ b/python/tests/codegen_tests/test_editgroup_edits.py
diff --git a/python/tests/fatcat_client/test_editor.py b/python/tests/codegen_tests/test_editor.py
index 00ca625e..00ca625e 100644
--- a/python/tests/fatcat_client/test_editor.py
+++ b/python/tests/codegen_tests/test_editor.py
diff --git a/python/tests/fatcat_client/test_entity_edit.py b/python/tests/codegen_tests/test_entity_edit.py
index 2f0f7ac3..2f0f7ac3 100644
--- a/python/tests/fatcat_client/test_entity_edit.py
+++ b/python/tests/codegen_tests/test_entity_edit.py
diff --git a/python/tests/fatcat_client/test_error_response.py b/python/tests/codegen_tests/test_error_response.py
index f0d09ee8..f0d09ee8 100644
--- a/python/tests/fatcat_client/test_error_response.py
+++ b/python/tests/codegen_tests/test_error_response.py
diff --git a/python/tests/fatcat_client/test_file_entity.py b/python/tests/codegen_tests/test_file_entity.py
index f5806f9b..f5806f9b 100644
--- a/python/tests/fatcat_client/test_file_entity.py
+++ b/python/tests/codegen_tests/test_file_entity.py
diff --git a/python/tests/fatcat_client/test_release_contrib.py b/python/tests/codegen_tests/test_release_contrib.py
index 9a61ef89..9a61ef89 100644
--- a/python/tests/fatcat_client/test_release_contrib.py
+++ b/python/tests/codegen_tests/test_release_contrib.py
diff --git a/python/tests/fatcat_client/test_release_entity.py b/python/tests/codegen_tests/test_release_entity.py
index 9a1f0e97..9a1f0e97 100644
--- a/python/tests/fatcat_client/test_release_entity.py
+++ b/python/tests/codegen_tests/test_release_entity.py
diff --git a/python/tests/fatcat_client/test_release_ref.py b/python/tests/codegen_tests/test_release_ref.py
index cafb6700..cafb6700 100644
--- a/python/tests/fatcat_client/test_release_ref.py
+++ b/python/tests/codegen_tests/test_release_ref.py
diff --git a/python/tests/fatcat_client/test_success.py b/python/tests/codegen_tests/test_success.py
index 28d855fb..28d855fb 100644
--- a/python/tests/fatcat_client/test_success.py
+++ b/python/tests/codegen_tests/test_success.py
diff --git a/python/tests/fatcat_client/test_work_entity.py b/python/tests/codegen_tests/test_work_entity.py
index 57b0cdad..57b0cdad 100644
--- a/python/tests/fatcat_client/test_work_entity.py
+++ b/python/tests/codegen_tests/test_work_entity.py
diff --git a/python/tests/entity_lifecycle.py b/python/tests/entity_lifecycle.py
deleted file mode 100644
index 4ac7ee68..00000000
--- a/python/tests/entity_lifecycle.py
+++ /dev/null
@@ -1,80 +0,0 @@
-
-import json
-import unittest
-import tempfile
-import pytest
-import fatcat
-import fatcat.sql
-from fatcat.models import *
-from fixtures import *
-
-
-def test_merge_works(app):
-
- # two works, each with releases
- rv = app.post('/v0/work',
- data=json.dumps(dict()),
- headers={"content-type": "application/json"})
- workA_id = json.loads(rv.data.decode('utf-8'))['id']
-
- rv = app.post('/v0/work',
- data=json.dumps(dict()),
- headers={"content-type": "application/json"})
- workB_id = json.loads(rv.data.decode('utf-8'))['id']
-
- rv = app.post('/v0/release',
- data=json.dumps(dict(
- title="some release",
- work_type="journal-article",
- work=workA_id,
- doi="10.1234/A1")),
- headers={"content-type": "application/json"})
- releaseA1 = json.loads(rv.data.decode('utf-8'))['id']
-
- rv = app.post('/v0/release',
- data=json.dumps(dict(
- title="some release",
- work_type="journal-article",
- work=workB_id,
- doi="10.1234/B1")),
- headers={"content-type": "application/json"})
- releaseB1 = json.loads(rv.data.decode('utf-8'))['id']
-
- rv = app.post('/v0/release',
- data=json.dumps(dict(
- title="some release",
- work_type="journal-article",
- work=workB_id,
- doi="10.1234/A1")),
- headers={"content-type": "application/json"})
- releaseB2 = json.loads(rv.data.decode('utf-8'))['id']
-
- # XXX: what if workB primary was set?
-
- editgroup_id = 1
- rv = app.post('/v0/editgroup/{}/accept'.format(editgroup_id),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
- assert ChangelogEntry.query.count() == 1
- assert WorkIdent.query.filter(WorkIdent.is_live==True).count() == 2
- assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 3
-
- # merge works
- fatcat.sql.merge_works(workA_id, workB_id)
- editgroup_id = 2
- rv = app.post('/v0/editgroup/{}/accept'.format(editgroup_id),
- headers={"content-type": "application/json"})
- assert rv.status_code == 200
-
- # check results
- assert ChangelogEntry.query.count() == 2
- assert WorkIdent.query.filter(WorkIdent.is_live==True).count() == 2
- assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 3
-
- workA_json = json.loads(app.get('/v0/work/{}'.format(workA_id)).data.decode('utf-8'))
- workB_json = json.loads(app.get('/v0/work/{}'.format(workB_id)).data.decode('utf-8'))
- assert workA_json['rev'] == workB_json['rev']
- print(workA_json)
- print(workB_json)
- assert workA_json['redirect_id'] == None
- assert workB_json['redirect_id'] == workA_json['id']
diff --git a/python/tests/fixtures.py b/python/tests/fixtures.py
index d3d8c24b..9092421f 100644
--- a/python/tests/fixtures.py
+++ b/python/tests/fixtures.py
@@ -5,30 +5,18 @@ import json
import signal
import pytest
import fatcat
-import fatcat.sql
-from fatcat.models import *
@pytest.fixture
def full_app():
- fatcat.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
fatcat.app.testing = True
fatcat.app.debug = False
- fatcat.db.session.remove()
- fatcat.db.drop_all()
- fatcat.db.create_all()
- fatcat.sql.populate_db()
return fatcat.app
@pytest.fixture
def app(full_app):
return full_app.test_client()
-@pytest.fixture
-def rich_app(app):
- enrichen_test_app(app)
- return app
-
@pytest.fixture(scope="function")
def api_client(full_app):
@@ -46,102 +34,6 @@ def api_client(full_app):
## Helpers ##################################################################
-def enrichen_test_app(app):
-
- 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(
- 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
-
def check_entity_fields(e):
for key in ('rev', 'is_live', 'redirect_id'):
assert key in e
diff --git a/python/tests/models.py b/python/tests/models.py
deleted file mode 100644
index 98bb6bc7..00000000
--- a/python/tests/models.py
+++ /dev/null
@@ -1,87 +0,0 @@
-
-import json
-import unittest
-import tempfile
-import pytest
-import fatcat
-import fatcat.sql
-from fatcat.models import *
-from fixtures import *
-
-
-def test_example_works(app):
- fatcat.dummy.insert_example_works()
-
-def test_random_works(app):
- fatcat.dummy.insert_random_works()
-
-def test_load_crossref(app):
- with open('./tests/files/crossref-works.2018-01-21.badsample.json', 'r') as f:
- raw = [json.loads(l) for l in f.readlines() if len(l) > 3]
- for obj in raw:
- fatcat.sql.add_crossref_via_model(obj)
-
-def test_schema_release_rev(app):
- assert ReleaseRev.query.count() == 0
- e = {
- "title": "Bogus title",
- "release_type": "book",
- "creators": [],
- "refs": [],
- }
- model = release_rev_schema.load(e)
- fatcat.db.session.add(model.data)
- fatcat.db.session.commit()
- assert ReleaseRev.query.count() == 1
- model_after = ReleaseRev.query.first()
- serial = release_rev_schema.dump(model_after).data
- #check_release(serial)
- for k in e:
- assert e[k] == serial[k]
-
-def test_schema_creator_rev(app):
- assert ReleaseRev.query.count() == 0
- e = {
- "name": "Robin (Batman)",
- }
- model = creator_rev_schema.load(e)
- fatcat.db.session.add(model.data)
- fatcat.db.session.commit()
- assert CreatorRev.query.count() == 1
- model_after = CreatorRev.query.first()
- serial = creator_rev_schema.dump(model_after).data
- check_creator(serial)
- for k in e.keys():
- assert e[k] == serial[k]
-
-def test_schema_container_rev(app):
- assert ReleaseRev.query.count() == 0
- e = {
- "name": "Papers Monthly",
- }
- model = container_rev_schema.load(e)
- fatcat.db.session.add(model.data)
- fatcat.db.session.commit()
- assert ContainerRev.query.count() == 1
- model_after = ContainerRev.query.first()
- serial = container_rev_schema.dump(model_after).data
- check_container(serial)
- for k in e.keys():
- assert e[k] == serial[k]
-
-def test_schema_file_rev(app):
- assert ReleaseRev.query.count() == 0
- e = {
- "sha1": "asdf",
- "size": 6,
- }
- model = file_rev_schema.load(e)
- print(model)
- fatcat.db.session.add(model.data)
- fatcat.db.session.commit()
- assert FileRev.query.count() == 1
- model_after = FileRev.query.first()
- serial = file_rev_schema.dump(model_after).data
- check_file(serial)
- for k in e.keys():
- assert e[k] == serial[k]
diff --git a/python/tests/routes.py b/python/tests/routes.py
index 79d97fe4..80eb15fe 100644
--- a/python/tests/routes.py
+++ b/python/tests/routes.py
@@ -3,14 +3,10 @@ import json
import tempfile
import pytest
import fatcat
-import fatcat.sql
-from fatcat.models import *
from fixtures import *
-def test_static_routes(rich_app):
- app = rich_app
-
+def test_static_routes(app):
for route in ('/health', '/robots.txt', '/', '/about'):
rv = app.get(route)
assert rv.status_code == 200
@@ -18,9 +14,7 @@ def test_static_routes(rich_app):
assert app.get("/static/bogus/route").status_code == 404
-def test_all_views(rich_app):
- app = rich_app
-
+def test_all_views(app):
for route in ('work', 'release', 'creator', 'container', 'file'):
print(route)
rv = app.get('/{}/1'.format(route))
diff --git a/python/tests/test_fixtures.py b/python/tests/test_fixtures.py
deleted file mode 100644
index 0a0d3176..00000000
--- a/python/tests/test_fixtures.py
+++ /dev/null
@@ -1,29 +0,0 @@
-
-import pytest
-import fatcat.api_client
-from fixtures import *
-
-
-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_editgroup == None