doc: Add git-cola-1.3.7 release notes
[git-cola.git] / test / test_cola_model.py
blob25305fc09ef52039042eaf72cea920cac1ef61cc
1 #!/usr/bin/env python
2 import unittest
3 import helper
5 from cola.models.base import BaseModel
7 class ExampleModel(BaseModel):
8 """An example model for use by these tests"""
9 def pass_through(self, value):
10 """Passes values through unmodified"""
11 return value
13 class ModelTest(unittest.TestCase):
14 """Tests the cola.model.Model class"""
16 def test_create_attribute(self):
17 """Test that arbitrary attributes provide set_* methods"""
18 model = ExampleModel()
19 model.set_foo('bar')
20 self.assertEqual(model.foo, 'bar')
22 def test_param(self):
23 """Test attribute access in case we f*** up __getattr__"""
24 model = ExampleModel()
25 model.attribute = 'value'
26 self.assertEqual(model.param('attribute'), 'value')
28 def test_method(self):
29 """Test calling a concrete method"""
30 model = ExampleModel()
31 self.assertEqual(model.pass_through('value'), 'value')
33 def test_dict_attribute(self):
34 """Test setting dictionaries/dictionary values."""
35 model = ExampleModel()
36 model.thedict = { 'hello': 'world' }
37 self.assertEqual(model.thedict['hello'], 'world' )
39 def test_from_dict(self):
40 """Test reconstituting a model from a dictionary."""
41 model = ExampleModel()
42 model.from_dict({
43 'test_dict': { 'hello':'world' },
44 'test_list': [ 'foo', 'bar' ],
45 'test_str': 'foo',
47 self.assertEqual(model.test_dict['hello'], 'world')
48 self.assertEqual(model.test_list[1], 'bar')
51 if __name__ == '__main__':
52 unittest.main()