vigiboard / vigiboard / tests / models / __init__.py @ 57f7cb3f
History | View | Annotate | Download (1.41 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""Unit test suite for the models of the application."""
|
3 |
from nose.tools import assert_equals |
4 |
|
5 |
from vigiboard.model import DBSession |
6 |
from vigiboard.tests import setup_db, teardown_db |
7 |
|
8 |
__all__ = ['ModelTest']
|
9 |
|
10 |
#Create an empty database before we start our tests for this module
|
11 |
def setup(): |
12 |
"""Function called by nose on module load"""
|
13 |
setup_db() |
14 |
|
15 |
#Teardown that database
|
16 |
def teardown(): |
17 |
"""Function called by nose after all tests in this module ran"""
|
18 |
teardown_db() |
19 |
|
20 |
class ModelTest(object): |
21 |
"""Base unit test case for the models."""
|
22 |
|
23 |
klass = None
|
24 |
attrs = {} |
25 |
|
26 |
def setup(self): |
27 |
try:
|
28 |
new_attrs = {} |
29 |
new_attrs.update(self.attrs)
|
30 |
new_attrs.update(self.do_get_dependencies())
|
31 |
self.obj = self.klass(**new_attrs) |
32 |
DBSession.add(self.obj)
|
33 |
DBSession.flush() |
34 |
return self.obj |
35 |
except:
|
36 |
DBSession.rollback() |
37 |
raise
|
38 |
|
39 |
def tearDown(self): |
40 |
DBSession.rollback() |
41 |
|
42 |
def do_get_dependencies(self): |
43 |
"""Use this method to pull in other objects that need to be created for this object to be build properly"""
|
44 |
return {}
|
45 |
|
46 |
def test_create_obj(self): |
47 |
pass
|
48 |
|
49 |
def test_query_obj(self): |
50 |
obj = DBSession.query(self.klass).one()
|
51 |
for key, value in self.attrs.iteritems(): |
52 |
assert_equals(getattr(obj, key), value)
|