class TestReallocatePerson(unittest.TestCase): """Reallocation test cases""" def setUp(self): self.dojo = Dojo() def test_person_exists(self): """test_person_exists""" self.dojo.create_room("red", "office") reallocate = self.dojo.reallocate_person("mwenda", "red") msg = colored("Person Mwenda does not exist!", "red") self.assertEqual(reallocate, msg) def test_room_exists(self): """test_room_exists""" self.dojo.add_person("miriti", 'fellow') reallocate = self.dojo.reallocate_person("miriti", "red") error = colored("Room red does not exist!", "red") self.assertEqual(reallocate, error) def test_reallocated(self): """test_reallocated successfully""" self.dojo.add_person('miriti', 'staff') self.dojo.create_room('blue', 'office') first = self.dojo.print_room("blue") self.assertEqual("0 names printed", first) self.dojo.reallocate_person("miriti", "blue") results = self.dojo.print_room('blue') self.assertEqual(results, "1 names printed")
class TestPrint(unittest.TestCase): def setUp(self): """ SetUp Dojo instance and populate test data""" self.instance = Dojo() self.instance.offices = { 'Blue': ['Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau'], 'Brown': ['Morris Kimani', 'Elizabeth Mabishi'], 'Band': ['Joy Warugu', 'Evans Musomi', 'Jackson Saya'] } self.instance.livingspaces = { 'Black': ['Loice Andia'], 'Bold': [], 'Blueberry': ['Elizabeth Mabishi', 'Joy Warugu'] } self.instance.fellows = [ 'Joshua Ondieki', 'Loice Andia', 'Morris Kimani', 'Elizabeth Mabishi', 'Joy Warugu' ] self.instance.staff = [ 'James Ndiga', 'Annette Kamau', 'Evans Musomi', 'Jackson Saya' ] self.instance.fellows.append('Lost Guy') self.instance.all_people.append( 'Lost Guy' ) # add a person without getting allocations :: LOST GUY FELLOW Y self.instance.all_rooms = { 'Blue': [ 'office', [ 'Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau' ] ], 'Brown': ['office', ['Morris Kimani', 'Elizabeth Mabishi']], 'Band': ['office', ['Joy Warugu', 'Evans Musomi', 'Jackson Saya']], 'Black': ['livingspace', ['Loice Andia']], 'Bold': ['livingspace', []], 'Blueberry': ['office', ['Elizabeth Mabishi', 'Joy Warugu']] } def test_print_names_of_people_in_specific_room(self): people_in_blue = { 'Blue': ['Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau'] } query_with_room_name = self.instance.print_room('Blue') self.assertEqual(query_with_room_name, people_in_blue) def test_print_allocations_with_file(self): self.instance.print_allocations('test.txt') test_file = Path("test.txt") self.assertTrue(test_file.is_file()) def test_print_unallocations_with_file(self): self.instance.print_unallocations('test1.txt') test_file = Path("test1.txt") self.assertTrue(test_file.is_file())
class TestPrintRoom(unittest.TestCase): """testcase for print room""" def setUp(self): self.dojo = Dojo() def test_print_room(self): '''test that members of a room are printed''' self.dojo.create_room('blue', 'office') self.dojo.add_person('mwenda', 'fellow', 'Y') self.dojo.add_person('miriti', 'staff') self.dojo.add_person('Eric', 'fellow') results = self.dojo.print_room('blue') expected = "3 names printed" self.assertEqual(results, expected) def test_room_must_be_avialable(self): """test that cannot print rooms not available""" room = self.dojo.print_room('bluered') msg = colored("Room bluered does not exist!", "red") self.assertEqual(room, msg)