X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=tests%2Fspecs%2Fmodel%2Faction_spec.py;fp=tests%2Fspecs%2Fmodel%2Faction_spec.py;h=92b1a959c412c30cb7e1eaf36fd4fa286afad315;hb=826cc2e9923c858d3c6a86c04f371cfb326e1728;hp=0000000000000000000000000000000000000000;hpb=44f7fa2ef41d54548aa800b2bb71a886261c5046;p=matthijs%2Fupstream%2Fmobilegtd.git diff --git a/tests/specs/model/action_spec.py b/tests/specs/model/action_spec.py new file mode 100644 index 0000000..92b1a95 --- /dev/null +++ b/tests/specs/model/action_spec.py @@ -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)