def setUp(self): self.mock_data = [{ "announcement": "..", "completed_on": "1453504099", "id": 1, "is_completed": True, "name": "Project1", "show_announcement": True, "url": "http://<server>/index.php?/projects/overview/1", "suite_mode": 3 }, { "announcement": "..", "completed_on": None, "id": 2, "is_completed": False, "name": "Project1", "show_announcement": True, "url": "http://<server>/index.php?/projects/overview/2", "suite_mode": 3 }] ptemp = list() for pdata in self.mock_data: ptemp.append(Project(pdata)) self.projects = ProjectContainer(ptemp)
class TestProjectContainer(unittest.TestCase): def setUp(self): self.mock_data = [{ "announcement": "..", "completed_on": "1453504099", "id": 1, "is_completed": True, "name": "Project1", "show_announcement": True, "url": "http://<server>/index.php?/projects/overview/1", "suite_mode": 3 }, { "announcement": "..", "completed_on": None, "id": 2, "is_completed": False, "name": "Project1", "show_announcement": True, "url": "http://<server>/index.php?/projects/overview/2", "suite_mode": 3 }] ptemp = list() for pdata in self.mock_data: ptemp.append(Project(pdata)) self.projects = ProjectContainer(ptemp) def test_len(self): self.assertEqual(len(self.projects), 2) def test_completed(self): self.assertEqual(len(list(self.projects.completed())), 1) self.assertEqual(list(self.projects.completed())[0].id, 1) def test_active(self): self.assertEqual(len(list(self.projects.active())), 1) self.assertEqual(list(self.projects.active())[0].id, 2) def test_getitem(self): self.assertEqual(self.projects[0].id, 1)
def projects(self): return ProjectContainer(list(map(Project, self.api.projects())))