diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-14 13:10:32 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-14 13:10:32 -0700 |
commit | 8fdd0b859047cf7e1dabc9f0f88ec6a5201e1f74 (patch) | |
tree | 28ab853cafdb6b8038959fd6bad1b4e89ecdec08 /tests/test_backend.py | |
parent | 9422515ed353a4a0c2a4c4b76a4d9fc20c9675e3 (diff) | |
download | fatcat-8fdd0b859047cf7e1dabc9f0f88ec6a5201e1f74.tar.gz fatcat-8fdd0b859047cf7e1dabc9f0f88ec6a5201e1f74.zip |
refactor backend tests
Diffstat (limited to 'tests/test_backend.py')
-rw-r--r-- | tests/test_backend.py | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/tests/test_backend.py b/tests/test_backend.py index 4c9169f3..4cd474cc 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -12,12 +12,32 @@ import tempfile ## Helpers ################################################################## def check_entity_fields(e): - for key in ('id', 'rev', 'is_live', 'redirect_id'): + for key in ('rev', 'is_live', 'redirect_id'): assert key in e for key in ('id',): assert e[key] is not None -## API Tests ################################################################ +def check_release(e): + check_entity_fields(e) + for key in ('work', 'release_type'): + assert key in e + for key in ('title'): + assert e[key] is not None + +def check_creator(e): + check_entity_fields(e) + for key in ('name'): + assert e[key] is not None + +def check_container(e): + check_entity_fields(e) + for key in ('name'): + assert e[key] is not None + +def check_file(e): + check_entity_fields(e) + for key in ('size', 'sha1'): + assert e[key] is not None class FatcatTestCase(unittest.TestCase): @@ -30,12 +50,45 @@ class FatcatTestCase(unittest.TestCase): fatcat.db.create_all() fatcat.sql.populate_db() + +## Model Tests ############################################################### + +class ModelTestCase(FatcatTestCase): + + def test_populate(self): + fatcat.sql.populate_db() + + def test_example_works(self): + fatcat.dummy.insert_example_works() + + def test_random_works(self): + fatcat.dummy.insert_random_works() + + def test_load_crossref(self): + 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(obj) + + def test_hydrate_work(self): + fatcat.dummy.insert_random_works() + fatcat.sql.hydrate_work(1) + + def test_hydrate_release(self): + fatcat.dummy.insert_random_works() + fatcat.sql.hydrate_release(1) + + +## API Tests ################################################################# + +class APITestCase(FatcatTestCase): + def test_health(self): rv = self.app.get('/health') obj = json.loads(rv.data.decode('utf-8')) assert obj['ok'] - def test_works(self): + def test_api_work(self): fatcat.dummy.insert_example_works() # Invalid Id @@ -58,26 +111,3 @@ class FatcatTestCase(unittest.TestCase): # Missing Id rv = self.app.get('/v0/work/r3zga5b9cd7ef8gh084714iljk') assert rv.status_code == 404 - - def test_populate(self): - fatcat.sql.populate_db() - - def test_example_works(self): - fatcat.dummy.insert_example_works() - - def test_random_works(self): - fatcat.dummy.insert_random_works() - - def test_load_crossref(self): - 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(obj) - - def test_hydrate_work(self): - fatcat.dummy.insert_random_works() - fatcat.sql.hydrate_work(1) - - def test_hydrate_release(self): - fatcat.dummy.insert_random_works() - fatcat.sql.hydrate_release(1) |