Add files from the old svn, r101.
[matthijs/upstream/mobilegtd.git] / tests / specs / model / action_spec.py
1 import unittest
2 import sys,os
3 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'..','..')))
4 print sys.path
5 import model.action
6 from model import action
7 from mock import Mock
8
9
10
11 class UnprocessedStatusBehaviour(unittest.TestCase):
12         def setUp(self):
13                 self.status = action.unprocessed
14         
15         def test_should_return_active_on_update(self):
16                 self.assertEqual(self.status.update(None),action.active)
17
18
19
20 class ActionBehaviour(unittest.TestCase):
21
22         def setUp(self):
23                 self.action = model.action.Action(u'oldey',u'some_context')
24                 self.observer = Mock()
25                 self.action.observers.append(self.observer)
26
27         def test_should_be_unprocessed_by_default(self):
28                 self.assertEqual(self.action.status,action.unprocessed)
29
30         def test_should_have_new_field_value_when_set(self):
31                 self.action.description=u'newey'
32                 assert self.action.description == u'newey'
33
34         def test_should_notify_observers_when_field_is_changed_externally(self):
35                 self.action.description=u'newea'
36                 self.observer.notify.assert_called_with(self.action,'description',new='newea',old='oldey')
37
38         def test_should_notify_observers_when_status_changes(self):
39                 self.action.status = action.active
40                 self.observer.notify.assert_called_with(self.action,'status',new=action.active,old=action.unprocessed)
41                 
42
43
44 class ActionParseBehaviour(unittest.TestCase):
45         
46         def setUp(self):
47                 self.description = u'some action'
48                 self.context = u'context/sub_context'
49                 self.info = u'additional stuff'
50                 self.status_string = '-'
51                 self.action = model.action.Action.parse(u'%s %s %s (%s)'%(self.status_string,self.context,self.description,self.info))
52                 
53         def test_should_read_the_description_correctly(self):
54                 self.assertEqual(self.action.description, self.description)
55
56         def test_should_read_the_context_correctly(self):
57                 self.assertEqual(self.action.context, self.context)
58
59         def test_should_read_the_status_correctly(self):
60                 self.assertEqual(self.action.status, action.active)
61
62         def test_should_read_the_info_correctly(self):
63                 self.assertEqual(self.action.info, self.info)