diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-16 18:34:19 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-16 18:34:19 -0700 |
commit | 4cf667c283d54f769e73d76bb23bbb68b4329cf8 (patch) | |
tree | 4bbeb1cdeb053c09e86e2cc41962382bcb837729 /python/tests/models.py | |
parent | b2d5968e0a7ac5576782f54980c930345f4c5298 (diff) | |
download | fatcat-4cf667c283d54f769e73d76bb23bbb68b4329cf8.tar.gz fatcat-4cf667c283d54f769e73d76bb23bbb68b4329cf8.zip |
move python code to subdirectory
Diffstat (limited to 'python/tests/models.py')
-rw-r--r-- | python/tests/models.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/python/tests/models.py b/python/tests/models.py new file mode 100644 index 00000000..98bb6bc7 --- /dev/null +++ b/python/tests/models.py @@ -0,0 +1,87 @@ + +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] |