class PrintRoomTestCase(TestCase): def setUp(self): self.amity = Amity() def test_print_room_successfully(self): self.amity.create_room(["office Ruby"]) self.amity.add_person("collins", "a", 'fellow') out = self.amity.print_room("Ruby") self.assertTrue("collins" in out.lower()) def test_print_empty_room_with_message_successfully(self): self.amity.create_room(["office ruby"]) out = self.amity.print_room("ruby") self.assertTrue("empty" in out.lower())
class PrintAllocationsTestCase(TestCase): def setUp(self): self.amity = Amity() def test_print_allocations_successfully(self): self.amity.create_room(["office Mombasa"]) self.amity.add_person('Edwin', 'Kato', 'fellow') stdout = self.amity.print_allocations() self.assertTrue('edwin' in stdout.lower()) def test_print_allocations_successfully_2(self): self.amity.create_room(['office shell']) self.amity.add_person('Dona', 'Mwine', 'fellow') self.amity.add_person('Shem', 'O', 'staff') stdout = self.amity.print_allocations() self.assertTrue('dona' in stdout.lower()) self.assertTrue('shem' in stdout.lower()) def test_print_allocations_with_living_room(self): self.amity.create_room(['office oculus']) self.amity.create_room(['living catherines']) self.amity.add_person('collins', 'a', 'fellow', True) stdout = self.amity.print_allocations() self.assertTrue('catherines' in stdout.lower()) self.assertTrue('collins' in stdout.lower()) def test_print_allocations_to_file(self): self.amity.create_room(['office ruby']) self.amity.add_person('collins', 'a', 'fellow', True) msg = self.amity.print_allocations("test_allocations.txt") self.assertEqual( msg.lower(), "allocations successfully written to file test_allocations.txt.") def tearDown(self): if os.path.exists("test_allocations.txt"): os.system('rm test_allocations.txt')
class TestAddPerson(TestCase): def setUp(self): self.amity = Amity() self.amity.create_room(['office Mombasa']) self.amity.create_room(['living Catherines']) def test_add_person_successfully(self): # clear all people in the room initial_people_count = len(self.amity.people) self.amity.add_person("Collins", "Abitekaniza", "Fellow") self.assertEqual(len(self.amity.people) - initial_people_count, 1) def test_add_more_people_successfully(self): initial_people_count = len(self.amity.people) call_1 = self.amity.add_person("Mbithe", "Nzomo", "Fellow") self.assertTrue(call_1) call_2 = self.amity.add_person("John", "A", "Fellow") self.assertTrue(call_2) self.assertEqual(len(self.amity.people) - initial_people_count, 2) def test_add_people_different_types(self): initial_people_count = len(self.amity.people) call_fellow = self.amity.add_person("Collins", "Abitekaniza", 'Fellow') self.assertTrue(call_fellow) call_staff = self.amity.add_person("Josh", "A", "Staff") self.assertTrue(call_staff) self.assertEqual(len(self.amity.people) - initial_people_count, 2) def test_person_type(self): person_1 = self.amity.add_person("Mukiibi", "David", "Fellow") person_2 = self.amity.add_person("Bill", "TheLizard", "Staff") self.assertTrue(isinstance(person_1, Fellow)) self.assertTrue(isinstance(person_2, Staff)) def test_person_type_ignorecasing(self): person_1 = self.amity.add_person("John", "Skeet", "Fellow") person_2 = self.amity.add_person("Collins", "Abitekaniza", "fEllOw") person_3 = self.amity.add_person("Josh", "A", "sTAFF") person_4 = self.amity.add_person("Mahad", "A", "fElloW") self.assertTrue(isinstance(person_1, Fellow)) self.assertTrue(isinstance(person_2, Fellow)) self.assertTrue(isinstance(person_3, Staff)) self.assertTrue(isinstance(person_4, Fellow)) def test_add_person_invalid_type(self): msg = self.amity.add_person("Collins", "A", "loosososo") self.assertEqual(msg.lower(), "person of type loosososo doesn\'t exist") def test_add_person_without_room_in_amity(self): self.amity.rooms[:] = [] res = self.amity.add_person("Collins", "A", "fellow") self.assertTrue(res)
class TestAmity(unittest.TestCase): def setUp(self): self.test_amity = Amity() def test_create_living_space(self): """ This is testing for when a user creates living spaces """ self.test_amity.create_room('living space', ['Braavos']) self.assertEqual(len(self.test_amity.room_directory), 1, "Braavos has been successfully created!") def test_create_office(self): """ This is testing for when a user creates offices """ self.test_amity.create_room('office', ['Valyria']) self.assertEqual(len(self.test_amity.room_directory), 1, "Valyria has been successfully created!") def test_room_does_not_exist(self): office_space = self.test_amity.create_room("office", ["Old Town"]) self.assertEqual(office_space, "room exists") def test_add_person_fellow(self): self.test_amity.add_person("Joe", "Nzau", "FELLOW", "Y") self.assertNotEqual(len(self.test_amity.unallocated_living_space), 1) def test_add_person_staff(self): self.test_amity.add_person("Pauline", "Magda", "STAFF") self.assertNotEqual(len(self.test_amity.unallocated_office), 1) def test_random_generating_office_room(self): self.test_amity.create_room('office', ["WinterFell"]) self.test_amity.create_room('office', ['Westeros']) random_office = self.test_amity.generating_random_office() self.assertIn(random_office, self.test_amity.office) def test_random_generating_living_space(self): self.test_amity.create_room("living space", ["King's Landing"]) self.test_amity.create_room('living space', ['Casterly Rock']) random_living_space = self.test_amity.generating_random_living_space() self.assertIn(random_living_space, self.test_amity.living_space) def test_file_path(self): self.test_amity.load_people(filename="amity_load.txt") self.assertTrue(os.path.exists("amity_load.txt")) os.remove("amity_load.txt") def test_print_allocations(self): file = open(os.path.join("amity_load.txt")) lines = file.readlines() self.assertTrue("Casterly Rock\n" in lines) self.assertTrue("WinterFell\n" in lines) os.remove("amity_load.txt") def test_print_unallocated(self): self.test_amity.print_unallocated_people('file') self.assertTrue(os.path.isfile('amity_load.txt')) os.remove('amity_load.txt') def test_print_rooms(self): self.test_amity.print_rooms_and_allocated_members('file') self.assertTrue(os.path.isfile('amity_load.txt')) os.remove('amity_load.txt') def test_saves_state(self): Amity.save_state('amity_db') self.assertTrue(os.path.isfile('amity_db.sqlite'))