2 from model.projects import Projects
5 class ProjectsBehaviour(unittest.TestCase):
7 self.projects = Projects()
9 self.projects.observers.append(self.observer)
11 def create_project(self,name=None,status=None):
19 def assert_observed(self,attribute,new=None,old=None):
20 self.observer.notify.assert_called_with(self.projects,attribute,new=new,old=old)
22 def test_should_notify_observers_when_project_is_added(self):
23 p = self.create_project()
24 self.projects.append(p)
25 self.assert_observed('add_item',new=p,old=None)
28 class EmptyProjectsBehaviour(ProjectsBehaviour):
29 def test_should_not_contain_any_projects(self):
30 self.assertEqual(self.projects,[])
32 class NonEmptyProjectsBehaviour(ProjectsBehaviour):
35 super(NonEmptyProjectsBehaviour,self).setUp()
36 self.searched_projects = [self.create_project(status=0),self.create_project(status=0)]
37 for p in self.searched_projects:
38 self.projects.append(p)
39 self.not_searched_projects = [self.create_project(status=1),self.create_project(status=2)]
40 for p in self.not_searched_projects:
41 self.projects.append(p)
43 def test_should_remember_all_added_projects(self):
44 for p in self.searched_projects+self.not_searched_projects:
45 self.assertTrue(p in self.projects)
47 def test_should_be_able_to_filter_projects_by_status(self):
48 self.assertEqual(self.projects.with_status(0),self.searched_projects)
50 def test_should_notify_observers_when_project_is_removed(self):
52 self.projects.remove(p)
53 self.assert_observed('remove_item',new=p,old=None)