Beispiel #1
0
class ClassAmitySuccessTest(unittest.TestCase):
    def setUp(self):
        self.amity = Amity()
        self.amity.all_people = []
        self.amity.all_rooms = []
        self.amity.office_allocations = defaultdict(list)
        self.amity.lspace_allocations = defaultdict(list)
        self.amity.fellows_list = []
        self.amity.staff_list = []

    def test_add_person(self):
        self.amity.add_person("awesome", "fellow", "y")
        self.assertEqual(len(self.amity.all_people), 1)

    def test_add_person_failure(self):
        self.amity.add_person("angie", "staff")
        people_names = [people.person_name for people in self.amity.all_people]
        self.assertIn("angie", people_names)
        msg = self.amity.add_person("angie", "staff")
        self.assertEqual(
            msg, "sorry, this user already exists.please choose another name")

    def test_room_added_to_list(self):
        self.amity.create_room("purple", "office")
        self.assertEqual(len(self.amity.all_rooms), 1)

    def test_room_with_same_name_not_created(self):
        self.amity.create_room("purple", "office")
        r_names = [r.room_name for r in self.amity.all_rooms]
        self.assertIn("purple", r_names)
        msg = self.amity.create_room("purple", "office")
        self.assertEqual(
            msg, "sorry, room already exists!please choose another name")

    def test_office_allocation(self):
        self.amity.add_person("Angie", "Staff", "Y")
        for room, occupants in self.amity.office_allocations:
            self.assertIn("Angie", self.amity.office_allocations[occupants])

    def test_lspace_allocation(self):
        self.amity.add_person("Angie", "fellow", "Y")
        for room, occupants in self.amity.lspace_allocations:
            self.assertIn("Angie", self.amity.lspace_allocations[occupants])

    def test_reallocate_person(self):
        self.amity.create_room("blue", "office")
        self.amity.add_person("angie", "staff")
        print(self.amity.office_allocations)
        self.amity.reallocate_person("angie", "blue")
        self.assertIn("angie", self.amity.office_allocations["blue"])

    def test_person_is_removed_from_old_room(self):
        self.amity.create_room("blue", "office")
        self.amity.add_person("angie", "staff")
        self.assertIn("angie", self.amity.office_allocations["blue"])
        self.amity.create_room("yellow", "office")
        self.amity.reallocate_person("angie", "yellow")
        self.assertNotIn("angie", self.amity.office_allocations["blue"])

    def test_load_from_file(self):
        dirname = os.path.dirname(os.path.realpath(__file__))
        self.amity.load_people(os.path.join(dirname, "test.txt"))
        self.assertEqual(len(self.amity.fellows_list), 4)
        self.assertEqual(len(self.amity.staff_list), 3)

    def test_it_prints_unallocated(self):
        self.amity.print_unallocated('test_print')
        self.assertTrue(os.path.isfile('test_print.txt'))
        os.remove('test_print.txt')

    def test_it_saves_state(self):
        self.amity.save_state('test.db')
        self.assertTrue(os.path.isfile('test.db.db'))
        os.remove('test.db.db')
Beispiel #2
0
class AmityTestCase(unittest.TestCase):
    """Test cases for Amity class"""
    def setUp(self):
        self.living_space = LivingSpace("Swift")
        self.office = Office("Scala")
        self.fellow = Fellow("Mike Jon")
        self.fellow2 = Fellow("Lucas Chan", "Y")
        self.staff = Staff("Rick Man")
        self.amity = Amity()

    def test_rooms_are_added_successfully(self):
        """Tests offices of living spaces are created"""

        self.amity.create_room("Scala", "O")
        self.amity.create_room("Go", "L")
        self.assertEqual(len(self.amity.list_of_rooms), 2)

    def test_office_is_created_successfully(self):
        """Tests offices are created"""

        office = self.amity.create_room("Office", "O")
        self.assertIsInstance(office, Office)

    def test_living_space_is_created_successfully(self):
        """Tests living_spaces are created"""

        l_space = self.amity.create_room("Keja", "L")
        self.assertIsInstance(l_space, LivingSpace)

    def test_living_space_does_not_exceed_four_people(self):
        """Tests living space does not exceed capacity"""

        self.amity.list_of_rooms.append(self.living_space)
        self.living_space.occupants = ["Tom", "Dick", "Harry", "Johny"]
        self.amity.allocate_room(self.fellow, "Y")
        self.assertEqual(len(self.amity.unallocated_members), 1)
        self.assertEqual(len(self.living_space.occupants), 4)

    def test_office_does_not_exceed_six_people(self):
        """Tests office does not exceed capacity"""

        self.amity.list_of_rooms.append(self.office)
        self.office.occupants = [
            "alpha", "beta", "charlie", "delta", "echo", "foxtrot"
        ]
        self.amity.allocate_room(self.staff, "N")
        self.assertEqual(len(self.amity.unallocated_members), 1)
        self.assertEqual(len(self.office.occupants), 6)

    def test_staff_is_not_allocated_living_space(self):
        """Tests staff members can only be in offices"""

        self.amity.list_of_rooms.append(self.living_space)
        self.amity.allocate_room(self.staff, "N")
        self.assertEqual(len(self.amity.list_of_rooms[0].occupants), 0)
        self.assertEqual(len(self.amity.unallocated_members), 1)

    def test_duplicate_rooms_are_not_added(self):
        """Tests rooms with same name are not allowed"""

        self.amity.list_of_rooms.append(self.living_space)
        self.assertEqual(self.amity.create_room("Swift", "L"),
                         "Room already exists")

    def test_fellow_gets_office_by_default(self):
        """Tests fellow is created and allocated room"""

        self.amity.list_of_rooms.append(self.office)
        self.amity.add_person("Tom", "Riley", "Fellow")
        self.assertTrue(self.amity.list_of_rooms[0].occupants[0].person_name ==
                        "Tom Riley".upper())

    def test_staff_member_is_added_successfully(self):
        """Tests staff member is created and allocated room"""

        self.amity.list_of_rooms.append(self.office)
        self.amity.add_person("Rick", "James", "Staff")
        self.assertEqual(len(self.amity.allocated_members), 1)

    def test_people_are_loaded_from_file_successfully(self):
        """Tests ii accepts data from file"""

        with patch("builtins.open", mock_open(read_data="sample text")) as m:
            self.amity.load_people("file")

        m.assert_called_with("file", 'r')

    def test_for_invalid_person_role(self):
        """Tests invalid person role is not allowed"""

        res = self.amity.add_person("Guy", "Ross", "Invalid")
        self.assertEqual(res, "Invalid is not a valid person role")

    def test_members_are_added_to_waiting_list_if_no_rooms(self):
        """Tests unallocated people are added to waiting list"""

        self.amity.add_person("Roomless", "Man", "Fellow", "Y")
        self.amity.add_person("Roomless", "Woman", "Staff")
        self.amity.add_person("Random", "Person", "Fellow")
        self.assertEqual(len(self.amity.unallocated_members), 3)

    def test_members_are_added_to_waiting_list_if_rooms_full(self):
        """Tests members who miss rooms are added to waiting list"""

        self.living_space.occupants += ["one", "two", "three", "four"]
        self.office.occupants += ["one", "two", "three", "four", "five", "six"]
        self.amity.add_person("Molly", "Sue", "Fellow", "Y")
        self.amity.add_person("Ledley", "Moore", "Staff")
        self.assertEqual(len(self.amity.unallocated_members), 2)

    def test_fellow_gets_office_and_living_space_if_wants_room(self):
        """Tests fellow who wants accomodation gets a living space"""

        self.amity.list_of_rooms.append(self.living_space)
        self.amity.list_of_rooms.append(self.office)
        self.amity.add_person("Martin", "Luther", "Fellow", "Y")
        self.assertTrue(self.amity.allocated_members[0].person_name ==
                        "Martin Luther".upper())
        self.assertEqual(self.amity.list_of_rooms[0].occupants[0].person_name,
                         "MARTIN LUTHER")
        self.assertEqual(self.amity.list_of_rooms[1].occupants[0].person_name,
                         "MARTIN LUTHER")

    def test_cannot_reallocate_non_existent_person(self):
        """Tests members not allocated cannot be reallocated"""

        self.amity.list_of_rooms.append(self.living_space)
        res = self.amity.reallocate_person("No Name", "Swift")
        self.assertEqual(res, "Person not found")

    def test_cannot_reallocate_non_existent_room(self):
        """Tests reallocation only allows valid rooms"""

        self.amity.allocated_members.append(self.staff)
        res = self.amity.reallocate_person("Rick Man", "Inexistent")
        self.assertEqual(res, "Room not found")

    def test_cannot_reallocate_to_same_room(self):
        """
        Tests person cannot be reallocated to
        the same room
        """

        self.amity.list_of_rooms.append(self.office)
        self.amity.list_of_rooms[0].occupants.append(self.fellow)
        self.amity.allocated_members.append(self.fellow)
        res = self.amity.reallocate_person("Mike Jon", "Scala")
        self.assertEqual(res, "Person is already in room")

    def test_cannot_reallocate_staff_to_living_space(self):
        """Tests staff cannot be reallocated to livingspace"""

        self.amity.list_of_rooms += [self.office, self.living_space]
        self.amity.allocated_members.append(self.staff)
        self.amity.list_of_rooms[0].occupants.append(self.staff)
        res = self.amity.reallocate_person("Rick Man", "Swift")
        self.assertEqual(res, "Staff cannot be allocated living space")

    def test_cannot_reallocate_person_to_full_room(self):
        """Tests person cannot be reallocated a full room"""

        self.amity.list_of_rooms.append(self.living_space)
        self.amity.add_person("Fellow", "One", "Fellow", "Y")
        self.amity.add_person("Fellow", "Two", "Fellow", "Y")
        self.amity.add_person("Fellow", "Three", "Fellow", "Y")
        self.amity.add_person("Fellow", "Four", "Fellow", "Y")
        self.amity.list_of_rooms.append(self.office)
        self.amity.allocated_members.append(self.fellow)
        res = self.amity.reallocate_person("Mike Jon", "Swift")
        self.assertEqual(res, "Room is full")

    def test_person_is_reallocated_successfully(self):
        """Tests reallocate person works"""

        self.amity.list_of_rooms += [self.office, self.living_space]
        self.amity.allocated_members.append(self.fellow)
        self.amity.list_of_rooms[0].occupants.append(self.fellow)
        self.amity.reallocate_person("Mike Jon", "Swift")
        # Assert the person is transfered to new room
        self.assertEqual(self.amity.list_of_rooms[1].occupants[0].person_name,
                         "Mike Jon")
        # Assert the person is removed from former room
        self.assertTrue(len(self.amity.list_of_rooms[0].occupants) == 0)

    def test_cannot_print_inexistent_room(self):
        """
        Tests print_room raises alert if there
        are no occupants
        """

        res = self.amity.print_room("None")
        self.assertEqual(res, "Room does not exist")

    def test_print_room_works(self):
        """
        Tests print room returns
        the names of occupants
        """

        self.amity.list_of_rooms.append(self.office)
        self.amity.list_of_rooms[0].occupants += \
            [self.fellow, self.fellow2, self.staff]

        res = self.amity.print_room("Scala")
        self.assertEqual(res, "Print room successful")

    def test_print_allocations_raises_alert_if_no_rooms(self):
        """Tests alert is raised if no allocations available"""

        self.assertEqual(self.amity.print_allocations(None), "No rooms")

    def test_print_allocations_to_screen_works(self):
        """Tests allocations are printed to screen"""

        self.amity.list_of_rooms += [self.office, self.living_space]
        self.amity.add_person("Carla", "Bruni", "Staff")
        self.amity.add_person("Peter", "Pan", "Fellow")
        self.amity.add_person("Mike", "Ross", "Fellow", "Y")
        self.amity.add_person("Hype", "Mann", "Fellow")
        res = self.amity.print_allocations(None)
        self.assertEqual(res, "Print allocations successful")

    def test_allocations_are_written_to_file(self):
        """Tests if allocations are saved to file"""

        self.amity.list_of_rooms += [self.office, self.living_space]
        self.amity.allocated_members += [self.staff, self.fellow, self.fellow2]
        self.amity.list_of_rooms[0].occupants.append(self.staff)
        self.amity.list_of_rooms[0].occupants.append(self.fellow)
        self.amity.list_of_rooms[0].occupants.append(self.fellow2)
        self.amity.list_of_rooms[1].occupants.append(self.fellow2)

        m = mock_open()
        with patch('builtins.open', m):
            self.amity.print_allocations("file")
        m.assert_called_with("file", 'w')

    def test_print_unallocated_people_works(self):
        """Tests unallocated people are printed to screen"""

        self.amity.unallocated_members += [
            self.fellow, self.fellow2, self.staff
        ]
        res = self.amity.print_unallocated(None)
        self.assertEqual(res, "Print unallocations successful")

    def test_it_prints_unallocated_people_to_file(self):
        """Tests if unallocated people are saved to file"""

        self.amity.unallocated_members += [
            self.staff, self.fellow, self.fellow2
        ]

        m = mock_open()
        with patch('builtins.open', m):
            self.amity.print_unallocated("file")
        m.assert_called_with("file", 'w')

    def test_load_state_from_invalid_path_raises_error(self):
        """Tests load state does not accept invalid path"""

        res = self.amity.load_people("invalid path")
        self.assertEqual(res, "Error. File not found")

    def test_cannot_save_blank_data_to_db(self):
        """Tests blank data is not saved to db"""

        res = self.amity.save_state(None)
        self.assertEqual(res, "No data")

    def tearDown(self):
        del self.living_space
        del self.office
        del self.fellow
        del self.fellow2
        del self.staff
        del self.amity
Beispiel #3
0
class AmityTestCase(unittest.TestCase):
    """ Tests for amity """
    def setUp(self):
        self.amity = Amity()
        self.amity.rooms = []
        self.amity.offices = []
        self.amity.living_spaces = []
        self.amity.people = []
        self.amity.fellows = []
        self.amity.staff = []
        self.amity.waiting_list = []
        self.amity.office_waiting_list = []
        self.amity.living_space_waiting_list = []

    # ... Tests for create_room ...#

    def test_create_room_add_room_successfully(self):
        """ Test that room was created successfully """
        self.amity.create_room(["Hogwarts"], "office")
        self.assertEqual("Hogwarts", self.amity.rooms[0].room_name)

    def test_create_room_duplicates(self):
        """ Test that room can only be added once """
        self.amity.create_room(["Hogwarts"], "office")
        self.assertIn("Hogwarts", [i.room_name for i in self.amity.rooms])
        length_of_rooms = len(self.amity.rooms)
        self.amity.create_room(["Hogwarts"], "office")
        self.assertEqual(len(self.amity.rooms), length_of_rooms)

    # ... Tests for add_person ...#

    def test_add_person_add_fellow(self):
        """ Test that fellow was added successfully """
        self.amity.create_room(["BlueRoom"], "Office")
        person = self.amity.add_person("Robley", "Gori", "fellow", "N")
        p_id = self.amity.people[0].person_id
        self.assertIn(
            "Robley Gori of id " + str(p_id) + " has been added to "
            "the system", person)

    def test_add_person_add_staff(self):
        """ Test that staff was added successfully """

        self.amity.create_room(["Maathai"], "LivingSpace")
        person = self.amity.add_person("Robley", "Gori", "fellow", "Y")
        p_id = self.amity.people[0].person_id
        self.assertIn(
            "Robley Gori of id " + str(p_id) + " has been added to "
            "the system", person)

    def test_add_person_add_person_to_office(self):
        """ Test that person is successfully added to office """

        self.amity.create_room(["red"], "Office")
        self.amity.add_person("Jack", "Line", "staff", "N")
        person = self.amity.add_person("Robley", "Gori", "fellow", "N")
        self.assertIn("", person)

    def test_add_person_add_fellow_to_living_space(self):
        """ Test that fellow is successfully added to living space """
        self.amity.create_room(["blue"], "Office")
        self.amity.add_person("Jack", "Line", "staff", "N")
        person = self.amity.add_person("Robley", "Gori", "fellow", "N")
        self.assertIn("", person)

    def test_add_person_add_staff_to_living_space(self):
        """ Test that staff cannot be added to living space """
        self.amity.create_room(["Maathai"], "LivingSpace")
        person = self.amity.add_person("Robley", "Gori", "staff", "Y")
        self.assertIn("Staff cannot be allocated a living space!", person)

    def test_add_person_add_person_full_office(self):
        """ Test that person is added to waiting list if offices are full """
        self.amity.create_room(["PinkRoom"], "Office")
        self.amity.load_people("people.txt")

        person = self.amity.add_person("Jackline", "Maina", "Fellow", "Y")
        self.assertIn(
            "Jackline Maina has been added to the office waiting "
            "list", person)

    def test_add_person_add_fellow_full_living_space(self):
        """ Test that fellow is added to waiting list if living spaces are \
        full """
        self.amity.create_room(["Maathai"], "LivingSpace")
        self.amity.add_person("Flevian", "Kanaiza", "Fellow", "Y")
        self.amity.add_person("Robley", "Gori", "Fellow", "Y")
        self.amity.add_person("Jus", "Machungwa", "Fellow", "Y")
        self.amity.add_person("Angela", "Mutava", "Fellow", "Y")
        person = self.amity.add_person("Jackline", "Maina", "Fellow", "Y")
        self.assertIn(
            "Jackline Maina has been added to the living space "
            "waiting list", person)

    # ... Tests for reallocate person ...#

    def test_reallocate_person_reallocates_person(self):
        """ Tests that person is reallocated """
        self.amity.create_room(["PinkRoom"], "Office")
        self.amity.add_person("Robley", "Gori", "fellow", "N")
        p_id = self.amity.people[0].person_id
        person = self.amity.reallocate_person(p_id, "ConferenceCentre")
        self.assertIn(
            "Sorry. Room ConferenceCentre does not exist in the "
            "system.", person)

    # ... Tests for load people ...#

    def test_load_people_loads_people_from_txt_file(self):
        """ Tests that people are successfully loaded from a txt file """
        self.amity.load_people("people.txt")
        self.assertTrue("Data successfully loaded to amity!")

    # ... Tests for print allocations ...#

    def test_print_allocations_prints_allocations_to_screen(self):
        """To test if method prints allocations to screen."""
        self.amity.create_room(["red"], "office")
        self.amity.load_people("people.txt")
        self.amity.print_allocations()
        self.assertTrue("These are the rooms and there allocations")

    def test_print_allocations_prints_allocations_to_txt_file(self):
        """To test if method prints allocations to txt file."""
        self.amity.create_room(["red"], "office")
        self.amity.load_people("people.txt")
        self.amity.print_allocations("files/allocations.txt")
        self.assertTrue("Data has been dumped to file")

    # ... Tests for unallocated rooms ...#

    def test_print_unallocated_prints_unallocated_people_to_screen(self):
        """To test if method prints unallocated people to screen."""
        self.amity.load_people("people.txt")
        self.amity.load_people("people.txt")
        self.amity.print_unallocated()
        self.assertTrue("These are the people in the waiting list")

    def test_print_unallocated_prints_unallocated_people_to_txt_file(self):
        """To test if method prints unallocated people to txt file."""
        self.amity.load_people("people.txt")
        self.amity.print_unallocated("files/unallocated.txt")
        self.assertTrue("Data has been dumped to file")

    # ... Tests for print room ...#

    def test_print_room_prints_all_people_in_room_name_to_screen(self):
        """ It tests that all people in a room name are printed to screen """
        self.amity.create_room(["red"], "office")
        self.amity.load_people("people.txt")
        self.amity.print_room("red")
        self.assertTrue("red")

    # ... Tests for save state ...#

    def test_save_state_adds_data_to_database(self):
        """ Test to affirm that data from the application is successfully \
        added to the database """
        self.amity.save_state()
        self.assertTrue("Data successfully saved to database!")

    # ... Tests for load state ...#

    def test_load_state_successfully_loads_data_from_database(self):
        """ Test that data is successfully loaded from database """
        self.amity.save_state("amity.db")
        self.assertTrue("Data successfully loaded to amity!")
Beispiel #4
0
class TestAmity(unittest.TestCase):
    '''
    This class tests all the funtionality of the amity famility allocation
    system. It has only focussed on the amity module since the class amity
    interacts with all the other modules and performs all the logical
    functioning of the application
    '''
    def setUp(self):
        self.amity = Amity()

    def test_returns_error_if_input_is_nonalphabetical(self):
        self.assertIn('123 is an invalid name type!',
                      self.amity.create_room(['123'], 'office'))

    def test_create_room(self):
        self.amity.create_room(["Pink"], "office")
        self.amity.create_room(['Blue'], 'livingspace')
        self.assertIn("Pink", Room.rooms['office'])
        self.assertIn('Blue', Room.rooms['livingspace'])

    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_correct_message_room_creation(self):
        res = self.amity.create_room(["Pink"], "office")
        self.assertIn('There are 1 offices and 0 livingspaces in the system.',
                      res)
        self.assertIn('Enter a valid room type.(office|livingspace)',
                      self.amity.create_room(["Orange"], "ofice"))

    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_create_room_increments_rooms_by_one(self):
        self.assertEqual(len(Room.rooms['office']), 0)
        self.amity.create_room(["Orange"], "office")
        self.assertEqual(len(Room.rooms['office']), 1)

    @patch.dict('app.room.Room.rooms', {
        "office": {
            'Yellow': []
        },
        "livingspace": {}
    })
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_create_room_duplicate_rooms(self):
        self.assertIn('A room with that name exists. Select another name',
                      self.amity.create_room(['Yellow'], 'office'))

    ''' This section tests the functionality of adding a person to the
    system, allocation of rooms and reallocation of a person from one room
    to another'''

    def test_only_alphabetical_names_allowed(self):
        self.assertIn('Invalid name format. Alphabets only',
                      self.amity.add_person('1234', 'Menjo', 'fellow'))
        self.assertIn('Invalid name format. Alphabets only',
                      self.amity.add_person('Menjo', '1234', 'fellow'))

    def test_restriction_on_job_designation(self):
        self.assertIn('Enter a valid designation',
                      self.amity.add_person('Charlie', 'Kip', 'worker'))

    def test_restriction_on_residence(self):
        self.assertIn('Respond with Y or N for residence',
                      self.amity.add_person('Charlie', 'Kip', 'fellow', 'R'))

    def test_new_person_gets_ID(self):
        self.amity.add_person('Mary', 'Chepkoech', 'staff')
        self.assertIn('ST01', Person.people['staff'])
        self.amity.add_person('Kevin', 'Leo', 'fellow', 'Y')
        self.assertIn('FE01', Person.people['fellow'])

    @patch.dict(
        'app.room.Room.rooms', {
            "office": {
                'Yellow': {
                    "Room_name": 'Yellow',
                    "Max_occupants": 6,
                    "Total_occupants": 0,
                    "Occupants": []
                }
            },
            "livingspace": {}
        })
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 1)
    @patch.object(Amity, "livingspaces", 0)
    def test_add_person_adds_person_to_lists(self):
        self.amity.add_person('Mary', 'Chepkoech', 'staff')
        self.amity.add_person('Kevin', 'Leo', 'fellow', 'Y')
        self.assertIn('Mary Chepkoech', Person.people['staff']['ST01']['Name'])
        self.assertIn('Kevin Leo', Person.people['fellow']['FE01']['Name'])

    @patch.dict(
        'app.room.Room.rooms', {
            "office": {
                'Brown': {
                    "Room_name": 'Brown',
                    "Max_occupants": 6,
                    "Total_occupants": 0,
                    "Occupants": []
                }
            },
            "livingspace": {
                'Beige': {
                    "Room_name": 'Beige',
                    "Max_occupants": 4,
                    "Total_occupants": 0,
                    "Occupants": []
                }
            }
        })
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 1)
    @patch.object(Amity, "livingspaces", 1)
    def test_person_is_allocated_room_after_creation(self):
        self.amity.add_person('Sophie', 'Njeri', 'fellow', 'Y')
        self.assertIn('FE01', Room.rooms['office']['Brown']['Occupants'])
        self.assertIn('FE01', Room.rooms['livingspace']['Beige']['Occupants'])

    def test_reallocate_person(self):
        self.amity.create_room(['Brown'], 'office')
        self.amity.create_room(['Beige'], 'livingspace')
        self.amity.add_person('Sophie', 'Njeri', 'fellow', 'Y')
        self.amity.create_room(["Orange"], "office")
        self.amity.reallocate('FE01', 'Orange')
        self.assertIn('FE01', Room.rooms['office']['Orange']['Occupants'])

    @patch.dict(
        'app.room.Room.rooms', {
            "office": {
                'Brown': {
                    "Room_name": 'Brown',
                    "Max_occupants": 6,
                    "Total_occupants": 0,
                    "Occupants": []
                }
            },
            "livingspace": {
                'Beige': {
                    "Room_name": 'Beige',
                    "Max_occupants": 4,
                    "Total_occupants": 0,
                    "Occupants": []
                }
            }
        })
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 1)
    @patch.object(Amity, "livingspaces", 1)
    def test_reallocation_to_nonexistent_room(self):
        self.amity.add_person('Sophie', 'Njeri', 'fellow', 'Y')
        self.assertIn('No such room exists',
                      self.amity.reallocate('FE01', 'Orange'))

    # Tests the print_room functionality
    def test_print_room_nonexistent_room(self):
        self.assertIn('No such room exists', self.amity.print_room('Orange'))

    def test_print_room_with_no_occupants(self):
        self.amity.create_room(['Brown'], 'office')
        self.assertEqual(self.amity.print_room('Brown'), 'No occupants.')

    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_print_room_with_occupants(self):
        self.amity.create_room(['Brown'], 'office')
        self.amity.add_person('Sophie', 'Njeri', 'fellow')
        self.assertIn('FE01 Sophie Njeri', self.amity.print_room('Brown'))

    # Tests the printing of unallocated persons
    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    @patch.object(Amity, "unallocated_people", [])
    def test_empty_unallocated(self):
        self.assertEqual(self.amity.print_unallocated(),
                         'There are no unallocated people')

    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_unallocated_with_entries(self):
        self.amity.add_person('Sophie', 'Njeri', 'fellow')
        self.assertIn('Sophie Njeri', self.amity.print_unallocated())

    # Tests for the print allocations begin here
    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    def test_print_allocations_with_no_rooms(self):
        self.assertEqual(self.amity.print_allocations(),
                         'There are no rooms in the system at the moment.')

    @patch.dict('app.room.Room.rooms', {"office": {}, "livingspace": {}})
    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    @patch.dict(
        'app.room.Room.rooms', {
            "office": {
                'Brown': {
                    "Room_name": 'Brown',
                    "Max_occupants": 6,
                    "Total_occupants": 0,
                    "Occupants": ['ST01']
                }
            },
            "livingspace": {}
        })
    @patch.dict(
        'app.person.Person.people', {
            "staff": {
                'ST01': {
                    'Name': 'Mary Chepkoech',
                    'Resident': 'N'
                }
            },
            "fellow": {}
        })
    @patch.object(Amity, "offices", 1)
    @patch.object(Amity, "livingspaces", 0)
    def test_print_allocations_with_occupants_in_rooms(self):
        res = self.amity.print_allocations()
        self.assertIn('ST01 Mary Chepkoech', res['off_occupants'])

    # Tests for the load people method begins here

    @patch.dict('app.person.Person.people', {"staff": {}, "fellow": {}})
    def test_load_people(self):
        if os.path.exists('app'):
            os.chdir('app')
        self.amity.load_people('test.txt')
        assert (Person.people['staff'] > 1)

    # Tests for the database
    def test_save_state(self):
        if os.path.exists('app'):
            os.chdir('app')
        self.assertEqual(self.amity.save_state('savefile.db'),
                         'The current data has been saved to the database.')

    @patch.object(Room, "rooms", {"office": {}, "livingspace": {}})
    @patch.object(Person, "people", {"staff": {}, "fellow": {}})
    @patch.object(Amity, "offices", 0)
    @patch.object(Amity, "livingspaces", 0)
    @patch.object(Amity, "available_rooms", [])
    @patch.object(Amity, "unallocated_people", [])
    def test_load_state(self):
        if os.path.exists('app'):
            os.chdir('app')
        self.assertEqual(
            self.amity.load_state('new_infile.db'),
            "Data has been successfully loaded from the database.")