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"""
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()
20 self
.assertEqual(model
.foo
, 'bar')
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()
43 'test_dict': { 'hello':'world' },
44 'test_list': [ 'foo', 'bar' ],
47 self
.assertEqual(model
.test_dict
['hello'], 'world')
48 self
.assertEqual(model
.test_list
[1], 'bar')
51 if __name__
== '__main__':