vigiboard / vigiboard / tests / models / __init__.py @ 20367931
History | View | Annotate | Download (1.54 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 wri(self,str): |
27 |
f=open("/home/tandreja/moimoi","a") |
28 |
f.write("%s %s\n" % (str,self.__class__)) |
29 |
f.close() |
30 |
|
31 |
def setup(self): |
32 |
try:
|
33 |
new_attrs = {} |
34 |
new_attrs.update(self.attrs)
|
35 |
new_attrs.update(self.do_get_dependencies())
|
36 |
self.obj = self.klass(**new_attrs) |
37 |
DBSession.add(self.obj)
|
38 |
DBSession.flush() |
39 |
return self.obj |
40 |
except:
|
41 |
DBSession.rollback() |
42 |
raise
|
43 |
|
44 |
def tearDown(self): |
45 |
DBSession.rollback() |
46 |
|
47 |
def do_get_dependencies(self): |
48 |
"""Use this method to pull in other objects that need to be created for this object to be build properly"""
|
49 |
return {}
|
50 |
|
51 |
def test_create_obj(self): |
52 |
pass
|
53 |
|
54 |
def test_query_obj(self): |
55 |
obj = DBSession.query(self.klass).one()
|
56 |
for key, value in self.attrs.iteritems(): |
57 |
assert_equals(getattr(obj, key), value)
|