Add files from the old svn, r101.
[matthijs/upstream/mobilegtd.git] / tests / specs / model / action_spec.py
diff --git a/tests/specs/model/action_spec.py b/tests/specs/model/action_spec.py
new file mode 100644 (file)
index 0000000..92b1a95
--- /dev/null
@@ -0,0 +1,63 @@
+import unittest
+import sys,os
+sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'..','..')))
+print sys.path
+import model.action
+from model import action
+from mock import Mock
+
+
+
+class UnprocessedStatusBehaviour(unittest.TestCase):
+       def setUp(self):
+               self.status = action.unprocessed
+       
+       def test_should_return_active_on_update(self):
+               self.assertEqual(self.status.update(None),action.active)
+
+
+
+class ActionBehaviour(unittest.TestCase):
+
+       def setUp(self):
+               self.action = model.action.Action(u'oldey',u'some_context')
+               self.observer = Mock()
+               self.action.observers.append(self.observer)
+
+       def test_should_be_unprocessed_by_default(self):
+               self.assertEqual(self.action.status,action.unprocessed)
+
+       def test_should_have_new_field_value_when_set(self):
+               self.action.description=u'newey'
+               assert self.action.description == u'newey'
+
+       def test_should_notify_observers_when_field_is_changed_externally(self):
+               self.action.description=u'newea'
+               self.observer.notify.assert_called_with(self.action,'description',new='newea',old='oldey')
+
+       def test_should_notify_observers_when_status_changes(self):
+               self.action.status = action.active
+               self.observer.notify.assert_called_with(self.action,'status',new=action.active,old=action.unprocessed)
+               
+
+
+class ActionParseBehaviour(unittest.TestCase):
+       
+       def setUp(self):
+               self.description = u'some action'
+               self.context = u'context/sub_context'
+               self.info = u'additional stuff'
+               self.status_string = '-'
+               self.action = model.action.Action.parse(u'%s %s %s (%s)'%(self.status_string,self.context,self.description,self.info))
+               
+       def test_should_read_the_description_correctly(self):
+               self.assertEqual(self.action.description, self.description)
+
+       def test_should_read_the_context_correctly(self):
+               self.assertEqual(self.action.context, self.context)
+
+       def test_should_read_the_status_correctly(self):
+               self.assertEqual(self.action.status, action.active)
+
+       def test_should_read_the_info_correctly(self):
+               self.assertEqual(self.action.info, self.info)