class TestingRooms(unittest.TestCase):

    def setUp(self):
        self.office = Office("Mercury")
        self.living_space = LivingSpace("Jupiter")

    def test_has_no_occupant(self):
        """
        This method test if the room or offices has no occupant
        """
        self.assertFalse(self.office.has_no_occupant())
        self.assertFalse(self.living_space.has_no_occupant())

    def test_get_member_details(self):
        """
        This method test the get member details
        """
        self.assertIsNotNone(self.office.get_member_details())
        self.assertIsNotNone(self.living_space.get_member_details())

    def test_is_room_filled(self):
        """
        This method test if the room is filled
        """
        self.assertFalse(self.office.is_room_filled())
        self.assertFalse(self.living_space.is_room_filled())
Beispiel #2
0
    def setUp(self):
        self.amity = Amity()

        self.office_1 = Office('PERL')
        self.office_2 = Office('OCCULUS')
        self.living_space_1 = LivingSpace('DOJO')
        self.living_space_2 = LivingSpace('NODE')

        self.staff_1 = Staff("BOB", "WACHIRA")
        self.staff_2 = Staff("BOB", "ODHIAMBO")
        self.fellow_1 = Fellow("LAWRENCE", "WACHIRA", "N")
        self.fellow_2 = Fellow("LAWRENCE", "NYAMBURA", "Y")
        self.fellow_3 = Fellow("MARTIN", "MUNGAI", "Y")

        self.staff_1.employee_id, self.staff_1.office_allocated = 1, "PERL"
        self.staff_2.employee_id = 2
        self.fellow_1.employee_id = 3
        self.fellow_2.employee_id, self.fellow_2.office_allocated = 4, \
            "OCCULUS"
        self.fellow_2.living_space_allocated = "DOJO"
        self.fellow_3.employee_id = 5

        self.office_1.current_occupancy = 1
        self.office_2.current_occupancy = 1
        self.living_space_1.current_occupancy = 1

        self.amity.rooms = [self.office_1, self.office_2, self.living_space_1,
                            self.living_space_2]
        self.amity.offices = [self.office_1, self.office_2]
        self.amity.living_spaces = [self.living_space_2, self.living_space_1]
        self.amity.persons = [self.staff_1, self.staff_2, self.fellow_1,
                              self.fellow_2, self.fellow_3]
        self.amity.staff = [self.staff_2, self.staff_1]
        self.amity.fellows = [self.fellow_2, self.fellow_1, self.fellow_3]

        self.initial_room_count = len(self.amity.rooms)
        self.initial_office_count = len(self.amity.offices)
        self.initial_living_space_count = len(self.amity.living_spaces)
        self.initial_persons_count = len(self.amity.persons)
        self.initial_staff_count = len(self.amity.staff)
        self.initial_fellow_count = len(self.amity.fellows)

        self.amity.create_files_directory()
        self.amity.create_databases_directory()

        self.saved_id = None
        if Path('./models/.id.txt').is_file():
            with open('./models/.id.txt', "r") as current_id:
                self.saved_id = current_id.read()
        else:
            with open('./models/.id.txt', "w+") as person_id:
                person_id.write("5")
Beispiel #3
0
    def create_room(self, name, room_type):
        if name.isalpha():
            if name.upper() in [room.name for room in self.rooms]:
                print("\n  Room {} already exists".format(name.upper()))
                return "Duplicate entry"

            elif room_type.upper() in ["OFFICE", "O"]:
                office_object = Office(name.upper())
                self.offices.append(office_object)
                self.rooms.append(office_object)
                print("\n  Office {} has been created".format(name.upper()))

            elif room_type.upper() in ["LIVINGSPACE", "L"]:
                living_space_object = LivingSpace(name.upper())
                self.living_spaces.append(living_space_object)
                self.rooms.append(living_space_object)
                print("\n  Living Space {} has been created".format(
                    name.upper()))

            else:
                print("\n  Invalid room type {}. Type help for usage "
                      "instructions".format(room_type))
                return "Invalid room type"

        else:
            print("\n  Invalid room name {}. Name should only consist of "
                  "alphabetical characters".format(name))
            return "Invalid room name"
 def setUp(self):
     self.office = Office("Mercury")
     self.living_space = LivingSpace("Jupiter")
Beispiel #5
0
    def load_state(self, database_name=None):

        self.create_databases_directory()
        if not database_name:
            database_name = 'Amity.sqlite3'
        else:
            database_name += '.sqlite3'

        if not path.isfile(databases_directory_path + database_name):
            print("\n  Database '{}' does not exist. Try a different "
                  "name".format(database_name))
            return "Database does not exist"

        conn = sqlite3.connect(databases_directory_path + database_name)
        cur = conn.cursor()

        cur.execute('''SELECT * FROM Amity_employees''')
        amity_employees = cur.fetchall()

        cur.execute('''SELECT * FROM Amity_rooms''')
        amity_rooms = cur.fetchall()

        conn.close()

        error = colored("\n  ERROR:", 'red')

        if amity_employees:
            for row in amity_employees:
                if row[4] == "STAFF":
                    if row[1] not in [
                            person.employee_id for person in self.persons
                    ]:
                        staff_object = Staff(row[2], row[3])
                        staff_object.employee_id = row[1]
                        staff_object.office_allocated = row[5]
                        self.staff.append(staff_object)
                        self.persons.append(staff_object)
                        print("\n  Staff {} has been loaded "
                              "successfully".format(staff_object))
                        sleep(0.2)

                    else:
                        print("\n  {} Could not load staff {} successfully. "
                              "They already exist in the current session. "
                              "Always load state first before adding rooms "
                              "or persons".format(error,
                                                  row[2] + ' ' + row[3]))

                elif row[4] == "FELLOW":
                    if row[1] not in [
                            person.employee_id for person in self.persons
                    ]:
                        fellow_object = Fellow(row[2], row[3], row[6])
                        fellow_object.employee_id = row[1]
                        fellow_object.office_allocated = row[5]
                        fellow_object.living_space_allocated = row[7]
                        self.fellows.append(fellow_object)
                        self.persons.append(fellow_object)
                        print("\n  Fellow {} has been loaded "
                              "successfully".format(fellow_object))
                        sleep(0.2)

                    else:
                        print("\n  {} Could not load fellow {} successfully. "
                              "They already exist in the current session. "
                              "Always load state first before adding rooms "
                              "or persons".format(error,
                                                  row[2] + ' ' + row[3]))

        if amity_rooms:
            for row in amity_rooms:
                if row[2] == "OFFICE":
                    if row[1] not in [room.name for room in self.rooms]:
                        office_object = Office(row[1])
                        office_object.current_occupancy = row[3]
                        self.offices.append(office_object)
                        self.rooms.append(office_object)
                        print("\n  Office {} has been loaded "
                              "successfully".format(office_object))
                        sleep(0.2)

                    else:
                        colored_message = colored(
                            " Could not load office {} successfully. It "
                            "already exists in the current session. It's "
                            "always better to load state first before adding "
                            "rooms or persons".format(row[1]), 'yellow')
                        print(error + colored_message)

                elif row[2] == "LIVING SPACE":
                    if row[1] not in [room.name for room in self.rooms]:
                        living_space_object = LivingSpace(row[1])
                        living_space_object.current_occupancy = row[3]
                        self.living_spaces.append(living_space_object)
                        self.rooms.append(living_space_object)
                        print("\n  Living Space {} has been loaded "
                              "successfully".format(living_space_object))
                        sleep(0.2)

                    else:
                        colored_message = colored(
                            " Could not load living space {} successfully. It "
                            "already exists in the current session. It's "
                            "always better to load state first before adding "
                            "rooms or persons".format(row[1]), 'yellow')
                        print(error + colored_message)

        if not amity_rooms and not amity_employees:
            print("\n  No data to load from {}".format(database_name))
            return "No data to load"

        print("\n\n  [All non-duplicate data from '{}' has been loaded "
              "successfully]".format(database_name))

        return "State loaded from {} successfully".format(database_name)