diff options
Diffstat (limited to 'tests')
-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) |