Changeset 5164

Show
Ignore:
Timestamp:
08/19/08 14:28:35 (5 months ago)
Author:
Gustavo
Message:

Filled test_models with an example on how to test the models.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/tests/test_models.py_tmpl

    r4479 r5164  
     1# -*- coding: utf-8 -*- 
     2"""Test suite for the TG app's models""" 
     3 
     4from tg.testutil import DBTest 
     5from sqlalchemy import create_engine 
     6 
     7from {{package}} import model 
     8 
     9test_database = create_engine("sqlite:///:memory:") 
     10 
     11class TestModel(DBTest): 
     12    """The base class for testing models in you TG project.""" 
     13    model = model 
     14    database = test_database 
     15 
     16     
     17class TestUser(TestModel): 
     18    """Test case for the User model.""" 
     19     
     20    def setUp(self): 
     21        super(TestUser, self).setUp() 
     22        self.member = model.User() 
     23        self.member.user_name = u"ignucius" 
     24        self.member.email_address = u"ignucius@example.org" 
     25         
     26    def test_member_creation_username(self): 
     27        """The member constructor must set the user name right""" 
     28        self.assertEqual(self.member.user_name, u"ignucius") 
     29         
     30    def test_member_creation_email(self): 
     31        """The member constructor must set the email right""" 
     32        self.assertEqual(self.member.email_address, u"ignucius@example.org") 
     33     
     34    def test_no_permissions_by_default(self): 
     35        """User objects should have no permission by default.""" 
     36        self.assertEqual(len(self.member.permissions), 0) 
     37         
     38    def test_getting_by_email(self): 
     39        """Users should be fetcheable by their email addresses""" 
     40        model.DBSession.add(self.member) 
     41        him = model.User.by_email_address(u"ignucius@example.org") 
     42        self.assertEqual(him, self.member)