Example #1
0
class AppStateTestCase(TestCase):
    def setUp(self):
        self.amity = Amity()

    def test_save_state_successfully(self):
        self.amity.create_room(['office demo'])
        self.amity.save_state()
        self.assertTrue(os.path.exists("recent.db"))
        # house cleaning
        os.system('rm default_state.db')

    def test_save_state_with_specific_db_name(self):
        self.amity.create_room(['office demo'])
        self.amity.save_state('my_state.db')
        self.assertTrue(os.path.exists("my_state.db"))
        os.system("rm my_state.db")

    def test_load_state(self):
        self.amity.save_state("empty_state.db")
        msg = self.amity.load_state("empty_state.db")
        self.assertEqual(msg.lower(),
                         "state empty_state.db loaded successfully")

    def test_load_state_no_params(self):
        msg = self.amity.load_state()
        self.assertEqual(
            msg.lower(),
            "please specify target state, use 'recent.db' to get the recently saved"
        )

    def test_load_state_invalid_path(self):
        msg = self.amity.load_state("lsksksksks.db")
        self.assertEqual(
            msg.lower(),
            "target state lsksksksks.db not found, please check spelling")
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)
Example #3
0
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())
Example #4
0
class UnallocatedTestCase(TestCase):
    def setUp(self):
        self.amity = Amity()

    def test_print_unallocated_no_rooms(self):
        msg = self.amity.print_unallocated()
        self.assertEqual(
            msg.lower(),
            "no rooms present in amity yet, please try adding some rooms")

    def test_print_unallocated_with_no_people_created(self):
        self.amity.create_room(['office ruby'])
        msg = self.amity.print_unallocated()
        self.assertEqual(msg.lower(), "no unallocations found in amity")
Example #5
0
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')
Example #6
0
class TestCreateRoom(TestCase):
    def setUp(self):
        self.amity = Amity()

    def test_create_room_succesfully(self):
        initial_room_count = len(self.amity.rooms)
        self.amity.create_room(["office Mombasa"])
        new_room_count = len(self.amity.rooms)

        self.assertEqual(new_room_count - initial_room_count, 1)

    def test_create_rooms_successfully(self):
        initial_room_count = len(self.amity.rooms)
        self.amity.create_room(["office Mombasa Lagos"])
        new_room_count = len(self.amity.rooms)

        self.assertEqual(new_room_count - initial_room_count, 2)

    def test_create_rooms_successfully_2(self):
        initial_room_count = len(self.amity.rooms)
        self.amity.create_room(["office Kampala Lagos NewYork Nairobi"])
        new_room_count = len(self.amity.rooms)

        self.assertEqual(new_room_count - initial_room_count, 4)

    def test_create_room_with_type_office(self):
        self.amity.rooms[:] = []
        self.amity.create_room(["Office Lagos"])

        self.assertTrue(isinstance(self.amity.rooms[0], Office))

    def test_create_room_with_type_livingspace(self):
        self.amity.rooms[:] = []
        self.amity.create_room(["Living Catherines"])

        self.assertTrue(isinstance(self.amity.rooms[0], LivingSpace))

    def test_create_rooms_multiple_types(self):
        self.amity.rooms[:] = []
        self.amity.create_room(["Office Dojo"])
        self.amity.create_room(["Living Catherines"])

        self.assertTrue(isinstance(self.amity.rooms[0], Office))
        self.assertTrue(isinstance(self.amity.rooms[1], LivingSpace))

    def test_create_room_invalid_type(self):
        err = self.amity.create_room(["lorem ipsum"])
        self.assertEqual(err.lower(), "room of type lorem doesn\'t exist")

    def test_create_room_duplicate(self):
        self.amity.rooms[:] = []
        self.amity.create_room(["office ipsum"])
        err = self.amity.create_room(["office ipsum"])
        self.assertEqual(len(self.amity.rooms), 1)
Example #7
0
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'))