3 from testmodel
import TestModel
5 class ModelTest(unittest
.TestCase
):
7 self
.model
= TestModel()
12 self
.model
.create(foo
='bar')
13 self
.failUnless(self
.model
.get_foo()=='bar')
15 def testRegularAttributes(self
):
16 """Test accessing attribute via model.attribute."""
17 self
.failUnless( self
.model
.attribute
== 'value' )
19 def testMixedcaseAttributes(self
):
20 """Test accessing attribute via model.Attribute."""
21 self
.failUnless( self
.model
.AtTrIbUte
== 'value' )
23 def testExplicitAttr(self
):
24 """Test accessing an explicit attribute. Just in case we f** up getattr"""
25 self
.failUnless( self
.model
.hello
== 'world' )
27 def testRealMethod(self
):
28 """Test calling a concrete model method."""
29 self
.failUnless( self
.model
.testMethod() == 'test' )
32 """Test calling using the get* method."""
33 self
.failUnless( self
.model
.getAttribute() == 'value' )
36 """Test using the set* method."""
37 self
.model
.set_param('newAttribute','baz')
38 self
.failUnless( self
.model
.newattribute
== 'baz' )
39 self
.failUnless( self
.model
.getNewAttribute() == 'baz' )
41 def testAddArray(self
):
42 """Test using the add* array method."""
44 self
.model
.addArray('bar')
45 self
.failUnless( self
.model
.array
[0] == 'bar' )
47 self
.model
.addArray('baz','quux')
48 self
.failUnless( self
.model
.array
[1] == 'baz' )
49 self
.failUnless( self
.model
.array
[2] == 'quux' )
51 def testAppendArray(self
):
52 """Test using the append* array method."""
54 self
.model
.appendArray('bar')
55 self
.failUnless( self
.model
.array
[0] == 'bar' )
57 self
.model
.appendArray('baz','quux')
58 self
.failUnless( self
.model
.array
[1] == 'baz' )
59 self
.failUnless( self
.model
.array
[2] == 'quux' )
62 """Test setting dictionary/dictionary values."""
63 self
.model
.dict = { 'hello': 'world' }
64 self
.failUnless( self
.model
.dict['hello'] == 'world' )
65 self
.failUnless( self
.model
.getDict()['hello'] == 'world' )
67 def testFromDict(self
):
68 """Test reconstituting a model from a dictionary."""
69 self
.model
.from_dict({
70 'test_dict': { 'hello':'world' },
71 'test_list': [ 'foo', 'bar' ],
74 self
.failUnless( self
.model
.get_test_dict()['hello'] == 'world' )
75 self
.failUnless( self
.model
.get_test_list()[1] == 'bar' )
77 if __name__
== '__main__':