1 """Unit test cases for testing you application's model classes.
2
3 If your project uses a database, you should set up database tests similar to
4 what you see below.
5
6 Be sure to set the ``db_uri`` in the ``test.cfg`` configuration file in the
7 top-level directory of your project to an appropriate uri for your testing
8 database. SQLite is a good choice for testing, because you can use an in-memory
9 database which is very fast and the data in it has to be boot-strapped from
10 scratch every time, so the tests are independant of any pre-existing data.
11
12 You can also set the ``db_uri``directly in this test file but then be sure
13 to do this before you import your model, e.g.::
14
15 from turbogears import testutil, database
16 database.set_db_uri("sqlite:///:memory:")
17 from spammcan.model import YourModelClass, User, ...
18 """
19
20 from turbogears.testutil import DBTest
21
22
23 from spammcan.model import User
24 from turbogears.database import session
25
27
29 """Object creation should set the name."""
30 obj = User(user_name = u"creosote",
31 email_address = u"spam@python.not",
32 display_name = u"Mr Creosote",
33 password = u"Wafer-thin Mint")
34
35 session.save(obj)
36
37 session.flush()
38 retrieved_user = User.by_email_address(u'spam@python.not')
39 assert retrieved_user, \
40 'User should have been found by email address'
41
42 assert retrieved_user.user_name == u'creosote', \
43 "User name should have been creosote, not '%s'" % retrieved_user.user_name
44 assert obj.display_name == u"Mr Creosote"
45