/
tests.py
79 lines (52 loc) · 1.47 KB
/
tests.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
Entry point for app tests
'''
import os
import pytest
from flask import Request
from app import create_app
from app.models import db as _db
#TODO: Figure out how to test things
@pytest.fixture(scope='session')
def app(request):
'''Session-wide test Flask application.'''
app = create_app(__name__, 'app/test_config.py')
# Establish an application context before running the tests.
ctx = app.app_context()
ctx.push()
def teardown():
ctx.pop()
request.addfinalizer(teardown)
return app
@pytest.fixture(scope='session')
def db(app, request):
"""Session-wide test database."""
def teardown():
_db.drop_all()
_db.app = app
_db.create_all()
request.addfinalizer(teardown)
return _db
@pytest.fixture(scope='function')
def session(db, request):
"""Creates a new database session for a test."""
connection = db.engine.connect()
transaction = connection.begin()
options = dict(bind=connection, binds={})
session = db.create_scoped_session(options=options)
db.session = session
def teardown():
transaction.rollback()
connection.close()
session.remove()
request.addfinalizer(teardown)
return session
def get_resource(app, path):
testClient = app.test_client()
rv = testClient.get(path)
assert(rv.status_code == 200)
def test_get_index(app):
get_resource(app, '/')
def test_get_humanstxt(app):
# get_resource(app, '/humans.txt')
pass