diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-03-22 21:30:06 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-03-22 21:30:30 -0700 |
commit | daf21f0b80e1783ed1eb777a7b6a9c5618c069d7 (patch) | |
tree | bb4107e1b6647d0d9ac37e525be29b02b3982b70 /tests/test_backend.py | |
parent | 33492754881a27c88f6a1ed38e463bba15ecf837 (diff) | |
download | fatcat-daf21f0b80e1783ed1eb777a7b6a9c5618c069d7.tar.gz fatcat-daf21f0b80e1783ed1eb777a7b6a9c5618c069d7.zip |
restructure
Diffstat (limited to 'tests/test_backend.py')
-rw-r--r-- | tests/test_backend.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_backend.py b/tests/test_backend.py new file mode 100644 index 00000000..afc6215d --- /dev/null +++ b/tests/test_backend.py @@ -0,0 +1,59 @@ + +import os +import json +import fatcat +import fatcat.sql +import unittest +import tempfile +from nose.tools import * + +# TODO: replace all these "assert" with unit test version (which displays left +# and right on failure) + +# TODO: http://alextechrants.blogspot.com/2013/08/unit-testing-sqlalchemy-apps.html + +## Helpers ################################################################## + +def check_entity_fields(e): + for key in ('id', 'rev', 'previous', 'state', 'redirect_id', 'edit_id', + 'extra_json'): + assert_in(key, e) + for key in ('id', 'rev'): + assert_is_not_none(e[key]) + +## API Tests ################################################################ + +class FatcatTestCase(unittest.TestCase): + + def setUp(self): + fatcat.app.config['DATABASE_URI'] = 'sqlite://:memory:' + fatcat.app.testing = True + self.app = fatcat.app.test_client() + fatcat.db.create_all() + + def test_health(self): + rv = self.app.get('/health') + obj = json.loads(rv.data.decode('utf-8')) + assert obj['ok'] + + def test_works(self): + + # Invalid Id + rv = self.app.get('/v0/work/_') + assert rv.status_code == 404 + + # Missing Id (TODO) + #rv = self.app.get('/v0/work/rzga5b9cd7efgh04iljk') + #assert rv.status is 404 + + # Valid Id + rv = self.app.get('/v0/work/r3zga5b9cd7ef8gh084714iljk') + assert rv.status_code == 200 + obj = json.loads(rv.data.decode('utf-8')) + check_entity_fields(obj) + assert obj['title'] + assert_equal(obj['work_type'], "journal-article") + + def test_something(self): + + fatcat.sql.populate_db() |