blob: 07a2a9067e8f8a4a1d139923110dcb85274309d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import os
import json
import pytest
import fatcat
import fatcat.sql
import unittest
import tempfile
# 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 key in e
for key in ('id', 'rev'):
assert e[key] is not None
## 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 == 404
# Valid Id (TODO)
#rv = self.app.get('/v0/work/r3zga5b9cd7ef8gh084714iljk')
#assert rv.status_code == 200
rv = self.app.get('/v0/work/random')
obj = json.loads(rv.data.decode('utf-8'))
check_entity_fields(obj)
assert obj['title']
assert obj['work_type'] == "journal-article"
def test_populate(self):
fatcat.sql.populate_db()
def test_populate_complex(self):
fatcat.sql.populate_complex_db()
|