ui: add 'Save *.orig Merge Backups' to the options dialog
[git-cola.git] / t / t0002-model-object.py
blobdca60f5979a2486a799ff4a2ede5c129617aa0e9
1 #!/usr/bin/env python
2 import unittest
3 from testmodel import TestModel
5 class ModelTest(unittest.TestCase):
6 def setUp(self):
7 self.model = TestModel()
8 def tearDown(self):
9 del self.model
11 def testCreate(self):
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' )
31 def testGetter(self):
32 """Test calling using the get* method."""
33 self.failUnless( self.model.getAttribute() == 'value' )
35 def testSetter(self):
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."""
43 self.model.array = []
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."""
53 self.model.array = []
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' )
61 def testDict(self):
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' ],
72 'test_str': 'foo',
74 self.failUnless( self.model.get_test_dict()['hello'] == 'world' )
75 self.failUnless( self.model.get_test_list()[1] == 'bar' )
77 if __name__ == '__main__':
78 unittest.main()