-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathtest_foreign_keys.py
47 lines (39 loc) · 1.65 KB
/
test_foreign_keys.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
"""Test foreign key edge cases."""
import os
import shutil
import json
from sandman import app
class TestSandmanForeignKeysBase(object):
"""Class to test edge-case foreign key conditions, using a database
explicitly built to contain these cases."""
DB_LOCATION = os.path.join(os.getcwd(), 'tests', 'foreign_key.sqlite3')
def setup_method(self, _):
"""Grab the database file from the *data* directory and configure the
app."""
shutil.copy(
os.path.join(
os.getcwd(),
'tests',
'data',
'foreign_key.sqlite3'),
self.DB_LOCATION)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////' + self.DB_LOCATION
app.config['SANDMAN_SHOW_PKS'] = False
app.config['SANDMAN_GENERATE_PKS'] = True
app.config['TESTING'] = True
self.app = app.test_client()
# pylint: disable=unused-variable
from . import foreign_key_models
def test_get(self):
"""Test simple HTTP GET, enough to cover all cases for now."""
response = self.app.get('/job_schedules')
assert len(json.loads(response.get_data(as_text=True))[u'resources']) == 1
def test_date_time(self):
"""Test serializing a datetime object works properly."""
response = self.app.get('/date_times')
assert len(json.loads(response.get_data(as_text=True))[u'resources']) == 1
def teardown_method(self, _):
"""Remove the database file copied during setup."""
os.unlink(self.DB_LOCATION)
# pylint: disable=attribute-defined-outside-init
self.app = None