3 from testmodel
import TestModel
5 class ModelTest(unittest
.TestCase
):
8 self
.model
= TestModel()
13 def testRegularAttributes(self
):
14 '''Test accessing attribute via model.attribute.'''
15 self
.failUnless( self
.model
.attribute
== 'value' )
17 def testUppercaseAttributes(self
):
18 '''Test accessing attribute via model.ATTRIBUTE.'''
19 self
.failUnless( self
.model
.ATTRIBUTE
== 'value' )
21 def testMixedcaseAttributes(self
):
22 '''Test accessing attribute via model.Attribute.'''
23 self
.failUnless( self
.model
.Attribute
== 'value' )
25 def testExplicitAttr(self
):
26 '''Test accessing an explicit attribute.'''
27 self
.failUnless( self
.model
.hello
== 'world' )
29 def testRealMethod(self
):
30 '''Test calling a concrete model method.'''
31 self
.failUnless( self
.model
.realMethod() == 'real' )
34 '''Test calling using the get* method.'''
35 self
.failUnless( self
.model
.getAttribute() == 'value' )
38 '''Test using the set* method.'''
39 self
.model
.set('newAttribute','baz')
40 self
.failUnless( self
.model
.newattribute
== 'baz' )
41 self
.failUnless( self
.model
.getNewAttribute() == 'baz' )
43 def testAddArray(self
):
44 '''Test using the add* array method.'''
46 self
.model
.addArray('bar')
47 self
.failUnless( self
.model
.array
[0] == 'bar' )
49 self
.model
.addArray('baz','quux')
50 self
.failUnless( self
.model
.array
[1] == 'baz' )
51 self
.failUnless( self
.model
.array
[2] == 'quux' )
53 def testAppendArray(self
):
54 '''Test using the append* array method.'''
56 self
.model
.appendArray('bar')
57 self
.failUnless( self
.model
.array
[0] == 'bar' )
59 self
.model
.appendArray('baz','quux')
60 self
.failUnless( self
.model
.array
[1] == 'baz' )
61 self
.failUnless( self
.model
.array
[2] == 'quux' )
64 '''Test setting dictionary/dictionary values.'''
65 self
.model
.dict = { 'hello': 'world' }
66 self
.failUnless( self
.model
.dict['hello'] == 'world' )
67 self
.failUnless( self
.model
.getDict()['hello'] == 'world' )
69 def testFromDict(self
):
70 '''Test reconstituting a model from a dictionary.'''
71 self
.model
.from_dict({
72 'test_dict': { 'hello':'world' },
73 'test_list': [ 'foo', 'bar' ],
76 self
.failUnless( self
.model
.get_test_dict()['hello'] == 'world' )
77 self
.failUnless( self
.model
.get_test_list()[1] == 'bar' )
79 if __name__
== '__main__': unittest
.main()