PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/shabti/templates/default/+package+/tests/test_models.py_tmpl

https://bitbucket.org/gawel/shabti
Unknown | 54 lines | 43 code | 11 blank | 0 comment | 0 complexity | d40efe245e40256f0d4c5e4bf38cba03 MD5 | raw file
 1{{if sqlalchemy}}
 2# default/tests/test_models
 3from sqlalchemy.exceptions import IntegrityError
 4from elixir import *
 5from {{package}}.tests import *
 6from {{package}}.model import Session, metadata
 7
 8class Individual(Entity):
 9    """Table 'Individual'.
10    
11    used in test_models.py
12    
13    >>> me = Individual()
14    
15    """
16    name = Field(Unicode(20), unique=True)
17    favorite_color = Field(Unicode(20))
18    created = Field(DateTime)
19    active = Field(Boolean)
20    
21class TestMyModel(TestModel):
22    def setUp(self):
23        TestModel.setUp(self)
24    
25    def tearDown(self):
26        TestModel.tearDown(self)
27    
28    def test_simpleassert(self):
29        """TestMyModel (default): check entity creation and retrieval"""
30        einstein = Individual(name = u'einstein')
31        Session.commit()
32        ind1 = Session.query(Individual).first()
33        assert ind1 is einstein
34        # why this fail ?!
35        # assert ind1.name == einstein.name == u'einstein'
36    
37    def test_exception(self):
38        """TestMyModel (default): check duplicate entity creation is disallowed"""
39        me = Individual(name = u'giuseppe')
40        me_again = Individual(name = u'giuseppe')
41        self.assertRaises(IntegrityError, Session.commit)
42        Session.rollback()
43    
44    def test_many(self):
45        """TestMyModel (default): check creation of many entities"""
46        from {{package}}.lib.fixtures import lorem_ipsum
47        for i in xrange(5):
48            lorem_ipsum(Individual)
49        Session.commit()
50        assert len(Session.query(Individual).all()) == 50
51
52
53# --- Added by Shabti default template
54{{endif}}