예제 #1
0
 def test_create_room_already_taken(self):
     dojo = Dojo()
     dojo.create_room("office", "MergeConflict")
     self.assertEqual(dojo.create_room("office", "MergeConflict"),
                      "MergeConflict already exists",
                      msg='Room already exists')
     self.assertEqual(dojo.create_room("livingspace", "MergeConflict"),
                      "MergeConflict already exists",
                      msg='Room already exists')
예제 #2
0
 def test_add_staff_successfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     number_of_staff = len(dojo.staff_added)
     new_staff = dojo.add_person("Maria", "staff")
     new_number_of_staff = len(dojo.staff_added)
     self.assertEqual(number_of_staff + 1,
                      new_number_of_staff,
                      msg='New staff Not Added')
예제 #3
0
 def test_add_staff_with_accommodation_unsuccessfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     dojo.create_room("livingspace", "livingspace1")
     dojo.create_room("livingspace", "livingspace2")
     number_of_staff = len(dojo.staff_added)
     new_staff = dojo.add_person("Maria", "staff", "Y")
     new_number_of_staff = len(dojo.staff_added)
     self.assertEqual(number_of_staff,
                      new_number_of_staff,
                      msg='Staff cannot be allocated livingspace')
예제 #4
0
 def test_add_fellow_with_accommodation_successfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     dojo.create_room("livingspace", "livingspace1")
     dojo.create_room("livingspace", "livingspace2")
     number_of_fellows = len(dojo.fellows_added)
     new_fellow = dojo.add_person("Martina", "fellow", "Y")
     new_number_of_fellows = len(dojo.fellows_added)
     self.assertEqual(number_of_fellows + 1,
                      new_number_of_fellows,
                      msg='New fellow Not Added')
예제 #5
0
	def test_create_room_complete(self):
		dojo = Dojo()
		initial_room_count = len(dojo.list_of_rooms)
		black_office = dojo.create_room("Black", "office")
		self.assertTrue(black_office, "An office called black has been created")
		new_room_count = len(dojo.list_of_rooms)
		self.assertEqual(new_room_count - initial_room_count, >1)
예제 #6
0
 def test_create_livingspace_successfully(self):
     dojo = Dojo()
     number_of_livingspaces = len(dojo.livingspaces_created)
     new_livingspace = dojo.create_room("livingspace", "Uganda")
     new_number_of_livingspaces = len(dojo.livingspaces_created)
     self.assertEqual(number_of_livingspaces + 1,
                      new_number_of_livingspaces,
                      msg='New livingspace Not Added')
예제 #7
0
 def test_create_office_successfully(self):
     dojo = Dojo()
     number_of_offices = len(dojo.offices_created)
     new_office = dojo.create_room("office", "Fox")
     new_number_of_offices = len(dojo.offices_created)
     self.assertEqual(number_of_offices + 1,
                      new_number_of_offices,
                      msg='New office Not Added')
예제 #8
0
class TestAddingRoom(unittest.TestCase):
    def setUp(self):
        self.dojo = Dojo()

    def test_adds_office_successfully(self):
        """Tests if room of type office is added successfully"""
        office = self.dojo.create_room("office", "A04")
        self.assertEqual(office, "Office added successfully")

    def test_adds_living_space_successfully(self):
        """Tests if room of type livingSpace is added successfully"""
        living_space = self.dojo.create_room("living_space", "Arusha")
        self.assertEqual(living_space, "Living space added successfully")

    def test_room_exists(self):
        """Tests if room already exists"""
        room = self.dojo.create_room("office", "Bujumbura")
        self.assertEqual(room, "Room already exists")
예제 #9
0
class CreateRoomTestCase(unittest.TestCase):
    def setUp(self):
        self.dojo = Dojo()

    def test_initial_room_check(self):
        self.assertEqual(self.dojo.rooms, {}, msg='invalid')

    def test_create_room_successfully(self):
        initial_room_count = len(self.dojo.rooms)
        blue_office = self.dojo.create_room('office', 'blue')
        self.assertTrue(blue_office)
        new_room_count = len(self.dojo.rooms)
        self.assertEqual(new_room_count - initial_room_count, 1)

    def test_create_multiple_rooms(self):
        self.dojo.create_room('office', 'blue', 'black')
        self.assertEqual(self.dojo.rooms, {'office': ['blue', 'black']},
                         msg='Multiple rooms cannot be entered')

    def test_create_single_rooms(self):
        self.dojo.create_room('living_space', 'dom')
        self.assertEqual(
            self.dojo.rooms, {'living_space': ['dom']},
            msg='Unable to add room when provided with single room')

    def test_create_unknown_room_type(self):
        self.assertEqual(self.dojo.create_room('kitchen', 'dom'),
                         'Unknown room',
                         msg='Unknown room')

    def test_add_unknown_person_position(self):
        self.dojo.add_person('john deer', 'facilitator', 'Y')
        self.assertEqual(self.dojo.people, {'fellow': [('blue', 'Y')]},
                         msg='Unknown position')

    def test_add_unknown_person_position(self):
        self.assertEqual(self.dojo.add_person('john deer', 'facilitator', 'Y'),
                         'Unknown position',
                         msg='Unknown position')

    '''def test_add_person_fellow(self):
        self.dojo.add_person('john deer', 'fellow', 'Y')
        self.assertEqual(self.dojo.people['fellow'], {'fellow':
                                                      [('john deer', 'Y')]}, msg='Unable to add fellow')'''
    '''def test_add_person_staff(self):
예제 #10
0
class TestDojo(unittest.TestCase):
    def setUp(self):
        self.new = Dojo()

    def test_check_one_office_Added(self):
        self.new.create_room("office", ["black"])
        self.assertEqual(len(self.new.offices), 1)

    def test_multiple_offices_added(self):
        self.new.create_room("office", ["black", "blue", "green"])
        self.assertEqual(len(self.new.offices), 3)

    def test_livingspace_added(self):
        self.new.create_room('living space', ['amsterdam'])
        self.assertEqual(len(self.new.living_spaces), 1)

    def test_multiple_living_spaces(self):
        self.new.create_room('living space', ['amsterdam', 'london'])
        self.assertEqual(len(self.new.living_spaces), 2)

    def test_cant_create_same_office_twice(self):
        self.new.create_room('office', ['amsterdam'])
        self.new.create_room('office', ['amsterdam'])
        self.assertEqual(len(self.new.offices), 1)

    def test_cant_create_same_living_twice(self):
        self.new.create_room('living space', ['amsterdam'])
        self.new.create_room('living space', ['amsterdam'])
        self.assertEqual(len(self.new.living_spaces), 1)

    def test_cant_create_room_with_same_names(self):
        self.new.create_room('living space', ['amsterdam'])
        self.new.create_room('office', ['amsterdam'])
        self.assertEqual(len(self.new.living_spaces), 1)

    def test_add_fellow(self):
        self.new.add_person('Akash Baga', 'fellow', 'Y')
        self.assertEqual(len(self.new.all_people), 1)

    def test_add_staff(self):
        self.new.add_person('Akash Baga', 'staff', 'N')
        self.assertEqual(len(self.new.all_people), 1)

    def test_cant_add_same_person_again(self):
        self.new.add_person('Akash Baga', 'staff', 'N')
        self.new.add_person('Akash Baga', 'staff', 'N')
        self.assertEqual(len(self.new.all_people), 1)

    def test_cant_add_same_staff_again(self):
        self.new.add_person('Akash Baga', 'staff', 'N')
        self.new.add_person('Akash Baga', 'staff', 'N')
        self.assertEqual(len(self.new.all_people), 1)

    def test_allocated_office(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        members = self.new.offices[0].occupants
        self.assertEqual(len(members), 1)

    def test_allocated_living(self):
        self.new.create_room('living', ['jbo'])
        self.new.add_person('Joe', 'fellow', 'Y')
        members = self.new.living_spaces[0].occupants
        self.assertEqual(len(members), 1)

    def test_print_allocations_to_file(self):
        self.new.create_room('living', ['jbo'])
        self.new.add_person('Joe', 'fellow', 'Y')
        self.new.print_allocations_to_file('allocations.txt')
        self.assertTrue(os.path.exists("allocations.txt"))
        os.remove('allocations.txt')

    def test_print_unllocations_to_file(self):
        self.new.create_room('living', ['jbo'])
        self.new.add_person('Joe', 'fellow', 'Y')
        self.new.print_unallocations_to_file('unallocations.txt')
        self.assertTrue(os.path.exists("unallocations.txt"))
        os.remove('unallocations.txt')

    def test_unallocated_person(self):
        self.new.add_person('Joe', 'staff', 'N')
        self.assertEqual(len(self.new.unallocated_office), 1)

    def test_unallocated_no_unallocated_person(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        self.assertEqual(len(self.new.unallocated_office), 0)

    def test_reallocate_person_person_added(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        old_office = self.new.offices[0]
        self.new.create_room('office', ['ams'])
        new_office = self.new.offices[1]
        self.new.reallocate_person('Joe', 'ams')
        self.assertEqual(len(new_office.occupants), 1)

    def test_reallocate_person_person_removed(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        old_office = self.new.offices[0]
        self.new.create_room('office', ['ams'])
        new_office = self.new.offices[1]
        self.new.reallocate_person('Joe', 'ams')
        self.assertEqual(len(old_office.occupants), 0)

    def test_save_state(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        self.new.save_state('dojo_db')
        self.assertTrue(os.path.exists("dojo_db"))
        os.remove('dojo_db')

    def test_save_state_data(self):
        self.new.create_room('office', ['jbo'])
        self.new.add_person('Joe', 'staff', 'N')
        self.new.save_state('dojo_db')
        engine = create_engine('sqlite:///dojo')
        Session = sessionmaker()
        Session.configure(bind=engine)
        session = Session()
        everyone = session.query(People).all()
        all_rooms = session.query(Rooms).all()
        self.assertEqual(everyone[0].name, 'Joe')

    def test_load_state_data(self):
        self.new.load_state('dojo_db')
        self.assertEqual(len(self.new.all_people), 1)
        os.remove('dojo_db')

    def test_load_people(self):
        self.new.create_room('office', ['jbo'])
        f = open("test.txt", "a")
        f.write("Paul Pogba FELLOW Y" + "\n")
        f.close()
        self.new.load_people('test.txt')
        self.assertEqual(len(self.new.all_people), 1)
        os.remove('test.txt')
예제 #11
0
class TestPersonCreation(unittest.TestCase):
    """ Test cases to for successful creation and failed of person(s) """
    def test_can_add_person(self):
        """ Test successful addition of person """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.add_person('John', 'john', 'STAFF', '')
        self.dojo.add_person('Anne', 'Ndinda', 'FELLOW', 'Y')
        self.dojo.add_person('Steve', 'Mcmon', 'FELLOW', 'N')
        self.assertEqual(len(self.dojo.total_people), 4,
                         'Person(s) were added to the system!')

    def test_can_add_staff(self):
        """ Test successful addition of staff """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.assertEqual(len(self.dojo.total_people), 0)
        self.dojo.add_person('Fred', 'Flint', 'STAFF')
        self.assertEqual(len(self.dojo.total_people), 1,
                         ' staff member(s) has been added to the system!')

    def test_can_add_fellow(self):
        """ Test successful addition of fellows"""

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.assertEqual(len(self.dojo.total_people), 0)
        self.dojo.add_person('Joe', 'jameson', 'FELLOW', 'Y')
        self.dojo.add_person('James', 'konia', 'FELLOW')
        self.dojo.add_person('Larry', 'smith', 'FELLOW', 'N')
        self.assertEqual(len(self.dojo.total_people), 3,
                         'staff member(s) were added to the system!')

    def test_cannot_add_person_with_missing_arguments(self):
        """ Test failure in addition of persons with Missing arguments """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.num_of_people = len(self.dojo.total_people)
        self.dojo.add_person('Kevin', '', '')
        self.dojo.add_person('', '', '', 'Y')
        self.dojo.add_person('', '', '', '')
        self.assertEqual(
            len(self.dojo.total_people), self.num_of_people,
            'Person(s) cannot be created without necessary credentials')
예제 #12
0
class TestPrintCreation(unittest.TestCase):
    """ Test cases to for successful and failed  printing of lists"""
    def test_can_print_names_of_people_in_room_on_screen(self):
        """ test successful printing of names of people in room_name on screen"""

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.print_room("kenya")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("office space kenya contains Kevin Oriels", output)

    def test_successful_print_list_of_allocation_on_screen(self):
        """ test successful printing of names of people allocated a room on screen"""
        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.print_allocations()
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn('Kevin Oriels', output)

    def test_successful_print_list_of_unallocated_on_screen(self):
        """ test successful printing of names of people not allocated a room on screen"""
        self.dojo = Dojo()
        self.dojo.add_person('Diego', 'Pamio', 'FELLOW')
        self.dojo.print_unallocated()
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn('Diego Pamio', output)

    def test_cannot_print_list_for_room_not_existing(self):
        """ test unsuccessful printing of names of people in room_name that does not exist """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.print_room("Britain")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("Sorry.That rooms does not exist.", output)

    def test_can_print_empty_room(self):
        """ test  printing of names of people in room_name that does not exist """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.print_room("kenya")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("office space kenya contains no occupants", output)

    def test_successful_print_list_of_allocation_to_txt_file(self):
        """ test successful printing of names of people allocated a room to a txt file """
        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.create_room("living", ["Nairobi"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.print_allocations("allocated_persons")
        self.assertTrue(os.path.isfile("allocated_persons.txt"))
        allocated_file = open("allocated_persons.txt").readlines()
        first_line = allocated_file[1]
        third_line = allocated_file[5]
        self.assertEquals(first_line, "kenya \n")
        self.assertEquals(third_line, "Kevin Oriels\n")
        os.remove("allocated_persons.txt")

    def test_successful_print_list_of_unallocated_to_txt_file(self):
        """ test successful printing of names of people not allocated a room to a txt file """
        self.dojo = Dojo()
        self.dojo.add_person('Diego', 'Pamio', 'FELLOW')
        self.dojo.add_person('Trent', 'Renzor', 'FELLOW', 'Y')
        self.dojo.print_unallocated("unallocated_persons")
        self.assertTrue(os.path.isfile("unallocated_persons.txt"))
        unallocated_file = open("unallocated_persons.txt").readlines()
        first_line = unallocated_file[4]
        self.assertEquals(first_line, "Diego Pamio, Trent Renzor\n")
        os.remove("unallocated_persons.txt")
예제 #13
0
class TestRoom(TestCase):
    """class for testing dojo functions"""
    def setUp(self):
        """setup defaults"""
        self.held, sys.stdout = sys.stdout, StringIO()
        self.my_instance = Dojo()

    def test_create_office(self):
        """test for successful office creation"""
        initial_room_count = len(self.my_instance.rooms)
        self.my_instance.create_room("office", "blue")
        new_room_count = len(self.my_instance.rooms)
        self.assertEqual(new_room_count - initial_room_count, 1)
        self.assertIn("blue", self.my_instance.office_allocations.keys())

    def test_create_living_space(self):
        """test for successful living space creation"""
        initial_room_count = len(self.my_instance.rooms)
        self.my_instance.create_room("living_space", "white")
        new_room_count = len(self.my_instance.rooms)
        self.assertEqual(new_room_count - initial_room_count, 1)
        self.assertIn("white",
                      self.my_instance.living_space_allocations.keys())

    def test_create_room_with_similar_names(self):
        """test whether someone can create rooms will similar names.
        This is not allowed"""
        self.my_instance.create_room("office", "blue")
        output = self.my_instance.create_room("office", "blue")
        self.assertIn("room already exists", output)

    def test_add_staff(self):
        """"test for successful staff addition to the dojo"""
        initial_person_count = len(self.my_instance.people)
        self.my_instance.add_person("Godwin", "Gitonga", "staff")
        new_person_count = len(self.my_instance.people)
        self.assertEqual(new_person_count > initial_person_count, True)

    def test_add_staff_requesting_accommodation(self):
        """"test for staff addition to the dojo with request for accommodation. It """
        initial_person_count = len(self.my_instance.people)
        self.my_instance.add_person("Godwin", "Gitonga", "staff", "Y")
        output = sys.stdout.getvalue()
        self.assertIn("Staff cannot be allocated living spaces", output)
        new_person_count = len(self.my_instance.people)
        self.assertEqual(new_person_count > initial_person_count, True)

    def test_add_fellow(self):
        """"test for successful fellow addition to the dojo"""
        initial_person_count = len(self.my_instance.people)
        self.my_instance.add_person("Godwin", "Gitonga", "fellow", "Y")
        new_person_count = len(self.my_instance.people)
        self.assertEqual(new_person_count > initial_person_count, True)

    def test_add_fellow_with_similar_names(self):
        """"test for successful fellow addition to the dojo"""
        initial_person_count = len(self.my_instance.people)
        self.my_instance.add_person("Godwin", "Gitonga", "fellow", "Y")
        self.my_instance.add_person("Godwin", "Gitonga", "fellow", "Y")
        output = sys.stdout.getvalue()
        self.assertIn("1", output)
        self.assertIn("2", output)
        new_person_count = len(self.my_instance.people)
        self.assertEqual(new_person_count - initial_person_count, 2)

    def test_add_person_on_full_office(self):
        """test for addition of people when an office is full"""
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        output = sys.stdout.getvalue()
        self.assertIn("unallocated office", output)

    def test_add_person_on_full_lspace(self):
        """test for addition of people when an living space is full"""
        self.my_instance.create_room("living_space", "pink")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        output = sys.stdout.getvalue()
        self.assertIn("unallocated living space", output)

    def test_auto_allocate_office(self):
        self.my_instance.add_person("godwin", "gitonga", "staff")
        self.assertIn("godwin gitonga",
                      self.my_instance.office_allocations["unallocated"])
        self.my_instance.create_room("office", "blue")
        self.assertIn("godwin gitonga",
                      self.my_instance.office_allocations["blue"])
        self.assertNotIn("godwin gitonga",
                         self.my_instance.office_allocations["unallocated"])

    def test_auto_allocate_lspace(self):
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("godwin", "gitonga", "fellow", "Y")
        self.assertIn("godwin gitonga",
                      self.my_instance.living_space_allocations["unallocated"])
        self.my_instance.create_room("living_space", "white")
        self.assertIn("godwin gitonga",
                      self.my_instance.living_space_allocations["white"])
        self.assertNotIn(
            "godwin gitonga",
            self.my_instance.living_space_allocations["unallocated"])

    def test_print_room(self):
        """test for the printing a rooms occupants"""
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("godwin", "gitonga", "staff")
        self.my_instance.print_room("blue")
        my_output = sys.stdout
        output = my_output.getvalue()
        self.assertIn("godwin gitonga", output)

    def test_print_non_existing_room(self):
        """test for the printing a non existing room"""
        self.my_instance.print_room("blue")
        my_output = sys.stdout
        output = my_output.getvalue()
        self.assertIn("room blue does not exist", output)

    def test_print_empty_room(self):
        """test for the printing a non existing room"""
        self.my_instance.create_room("office", "blue")
        output = self.my_instance.print_room("blue")
        self.assertIn("room blue is empty", output)

    def test_load_people(self):
        """test for loading people from a file"""
        initial_people_count = len(self.my_instance.people)
        output = self.my_instance.load_people("people.txt")
        self.assertIn("data loaded successfully", output)
        current_people_count = len(self.my_instance.people)
        self.assertEqual(current_people_count > initial_people_count, True)

    def test_load_people_from_unavailable_file(self):
        """test for loading people from a file that is not available"""
        initial_people_count = len(self.my_instance.people)
        output = self.my_instance.load_people("dummy.txt")
        self.assertIn("file not found", output)
        current_people_count = len(self.my_instance.people)
        self.assertEqual(current_people_count, initial_people_count)

    def test_print_with_no_allocations(self):
        """test for print allocations without people allocated"""
        my_output = self.my_instance.print_allocations()
        self.assertIn("no allocations to print", my_output)

    def test_print_allocations_on_file(self):
        """test for printing allocation on a file"""
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "fellow", "y")
        self.my_instance.print_allocations("allocations.txt")
        self.assertTrue(os.path.isfile("allocations.txt"))
        os.remove("allocations.txt")

    def test_print_allocations_on_screen(self):
        """test for displaying allocations"""
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "fellow", "y")
        self.my_instance.print_allocations()
        my_output = sys.stdout.getvalue()
        self.assertIn("martin white", my_output)

    def test_print_unallocated(self):
        """test for displaying unallocated people"""
        self.my_instance.create_room("office", "grey")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "fellow", "y")
        self.my_instance.print_unallocated()
        my_output = sys.stdout.getvalue()
        self.assertIn("martin", my_output)

    def test_print_unallocated_from_empty_list(self):
        """test for displaying unallocated people"""
        self.my_instance.create_room("office", "white")
        my_output = self.my_instance.print_unallocated()
        self.assertIn("no list of unallocated people", my_output)

    def test_print_unallocated_on_file(self):
        """test for printing unallocated people on a file"""
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "staff")
        self.my_instance.add_person("martin", "white", "fellow", "y")
        self.my_instance.add_person("martin", "white", "fellow", "y")
        self.my_instance.print_unallocated("unallocations.txt")
        self.assertTrue(os.path.isfile("unallocations.txt"))
        os.remove("unallocations.txt")

    def test_reallocate_office(self):
        """test for reallocation function"""
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("Godwin", "Gitonga", "staff")
        self.assertEqual(len(self.my_instance.office_allocations["blue"]), 1)
        self.my_instance.create_room("office", "white")
        self.my_instance.reallocate_person(1, "white")
        self.assertEqual(len(self.my_instance.office_allocations["blue"]), 0)
        self.assertEqual(len(self.my_instance.office_allocations["white"]), 1)

    def test_reallocate_living_space(self):
        """test for reallocation function"""
        self.my_instance.create_room("living_space", "blue")
        self.my_instance.add_person("Godwin", "Gitonga", "fellow", "Y")
        self.assertEqual(
            len(self.my_instance.living_space_allocations["blue"]), 1)
        self.my_instance.create_room("living_space", "white")
        self.my_instance.reallocate_person(1, "white")
        self.assertEqual(
            len(self.my_instance.living_space_allocations["blue"]), 0)
        self.assertEqual(
            len(self.my_instance.living_space_allocations["white"]), 1)

    def test_reallocate_non_existing_person(self):
        self.my_instance.create_room("office", "blue")
        self.assertEqual(len(self.my_instance.office_allocations["blue"]), 0)
        self.my_instance.create_room("office", "white")
        output = self.my_instance.reallocate_person(1, "white")
        self.assertIn("person to reallocate doesn't exist", output)

    def test_reallocate_non_existing_room(self):
        self.my_instance.create_room("office", "blue")
        self.my_instance.add_person("Godwin", "Gitonga", "staff")
        self.assertEqual(len(self.my_instance.office_allocations["blue"]), 1)
        output = self.my_instance.reallocate_person(1, "white")
        self.assertIn("room not available for reallocation", output)

    def test_default_save_state(self):
        """test for storing the current state in the database"""
        self.my_instance.save_state()
        self.assertTrue(os.path.isfile('my_default_db.sqlite'))
        os.remove('my_default_db.sqlite')

    def test_save_state_with_filename(self):
        """test for storing the current state in the database"""
        self.my_instance.save_state("my_db")
        self.assertTrue(os.path.isfile('my_db.sqlite'))
        os.remove('my_db.sqlite')

    def test_content_in_db(self):
        db_name = "my_db"
        self.my_instance.create_room("office", "blue")
        self.my_instance.save_state(db_name)
        conn = sqlite3.connect(db_name + ".sqlite")
        c = conn.cursor()
        query = "SELECT room_name FROM room"
        cursor = c.execute(query)
        last_id = cursor.fetchone()[0]
        self.assertIn(last_id, "blue")

    def test_load_state(self):
        """test for retrieving the current state from the database"""
        my_instance = Dojo()
        people_initial_list = len(my_instance.people)
        my_instance.load_state("alloc")
        people_new_list = len(my_instance.people)
        self.assertTrue(people_new_list > people_initial_list)
예제 #14
0
class TestDojo(unittest.TestCase):

	def setUp(self):
		self.dojo = Dojo()

		"""
		checks if the all_rooms list is empty and returns a length
		of
		"""
	def test_create_room_works(self):
		self.assertEqual(len(self.dojo.all_rooms), 0)
		self.dojo.create_room('office1', 'office')
		self.assertEqual(len(self.dojo.all_rooms), 1, 'a new office has been created')

		"""
		checks if a room name exists in the list of all rooms and
		returns an error if the room name exists

		"""
		checks if multiple rooms are created
		"""

	def test_multiple_rooms_created(self):
		self.assertEqual(len(self.dojo.all_rooms), 0)
		self.dojo.create_room('office1', 'office')
		self.dojo.create_room('office2', 'office')
		self.dojo.create_room('office3', 'office')
		self.assertEqual(len(self.dojo.all_rooms), 3)

		"""
		tests if the livingspace room has been created
		"""

	def test_livingspace_created(self):
		self.assertEqual(len(self.dojo.livingspace), 0)
		self.dojo.create_room('mycrib', 'livingspace')
		self.assertEqual(len(self.dojo.livingspace), 1)

		"""
		tests if the office room has been created
		"""

	def test_office_created(self):
		self.assertEqual(len(self.dojo.office), 0)
		self.dojo.create_room('my_office', 'office')
		self.assertEqual(len(self.dojo.office), 1)

	def test_add_person_added(self):
		self.assertEqual(len(self.dojo.fellows), 0)
		self.dojo.add_person('Kola D', 'fellow')
		self.assertEqual(len(self.dojo.fellows),1)


	def test_fellow_is_added(self):
		self.dojo.create_room('office1', 'office')
		self.assertEqual(len(self.dojo.fellows),0)
		self.dojo.add_person('kola', 'fellow')
		self.assertEqual(len(self.dojo.all_rooms), 1, 'Fellow kola has been added to office1 successfully')

	def test_accomodation_is_added(self):
		self.dojo.create_room('my_crib', 'livingspace')
		self.assertEqual(len(self.dojo.fellows), 0)
		self.dojo.add_person('kola', 'fellow', 'Y')
		self.assertEqual(len(self.dojo.all_rooms), 1, 'Fellow kola has been added to my_crib successfully')


	def test_staff_added(self):
		self.dojo.create_room('office1', 'office')
		self.assertEqual(len(self.dojo.staff),0)
		self.dojo.add_person('kola', 'Staff')
		self.assertEqual(len(self.dojo.all_rooms), 1, 'Staff kola has been added to office1 successfully')

	def test_print_room(self):
		self.dojo.create_room('office', 'office1')
		self.dojo.create_room('livingspace', 'living1')
		self.dojo.add_person('kola', 'fellow')
		self.dojo.add_person('deno', 'staff')
		self.assertEqual(self.dojo.print_rooms('office1'), 'rooms printed')
예제 #15
0
class TestCreateRoom(unittest.TestCase):
    def setUp(self):
        self.class_instance = Dojo()

    def test_create_room_successfully(self):
        initial_room_count = len(self.class_instance.all_rooms['offices'])
        blue_office = self.class_instance.create_room("office", ["Blue"])
        for key in self.class_instance.offices:  # one liner
            if key == "Blue_office":
                self.assertIn("Blue_office", key)
        offices = self.class_instance.offices
        new_room_count = len(self.class_instance.all_rooms['offices'])
        self.assertEqual(new_room_count - initial_room_count, 1)

    def test_room_exists(self):
        green_living1 = self.class_instance.create_room(
            "living", ["green"])  # no hardcode
        green_living2 = self.class_instance.create_room("living", ["green"])

        self.assertEqual(len(self.class_instance.livingSpaces), 1)

        chrome_office1 = self.class_instance.create_room("office", ["chrome"])
        chrome_office2 = self.class_instance.create_room("office", ["chrome"])

        self.assertEqual(len(self.class_instance.offices), 1)

    def test_room_invalid__room_type(self):
        invalid_room_type = self.class_instance.create_room(
            "invalid", ["green"])
        self.assertEqual(len(self.class_instance.offices), 0)

    def test_add_person_successfully(self):
        add_room = self.class_instance.create_room("living", ["mara"])
        add_room
        add_room2 = self.class_instance.create_room("office", ["chrome"])
        add_room2
        # multiple adds checking fellow/staff and wants accomodation
        initial_people_count = len(self.class_instance.people['fellow'])
        self.class_instance.add_person("joey", "fellow", "No")
        self.class_instance.add_person("emily", "fellow", "Y")
        new_people_count = len(self.class_instance.people['fellow'])

        #check if there has been any additions
        self.assertEqual(new_people_count - initial_people_count, 2)
        # multiple adds checking fellow/staff and wants accomodation
        initial_people_count = len(self.class_instance.people['staff'])
        jane_add = self.class_instance.add_person("jane", "staff", "Y")
        viktor_add = self.class_instance.add_person("viktor", "staff", "No")
        new_people_count = len(self.class_instance.people['staff'])

        #check if there has been any additions
        self.assertEqual(new_people_count - initial_people_count, 2)

    def test_room_allocation(self):
        add_room = self.class_instance.create_room("living", ["mara"])
        derek_add_allocate = self.class_instance.add_person(
            "derek", "fellow", "y")
        add_room
        derek_add_allocate

        self.assertEqual(self.class_instance.livingSpaces["mara_living"],
                         ["derek"])

    def test_print_room(self):
        add_room = self.class_instance.create_room("living",
                                                   ["mara"])  # should be added
        add_person = self.class_instance.add_person("emily", "fellow",
                                                    "y")  # should be added
        add_room
        add_person

        print(self.class_instance.livingSpaces)

        print(self.class_instance.fellows)
        self.assertIn("emily", self.class_instance.livingSpaces["mara_living"])
        print_room = self.class_instance.print_room

    def test_vacant_space(self):
        add_room = self.class_instance.create_room("living", ["mara"])
        add_room
        self.assertEqual("living space is vacant",
                         self.class_instance.vacant_space("mara_living"))
예제 #16
0
	def test_room_already_exists(self):
		dojo = Dojo()
		black_office = dojo.create_room("Black", "office")
		black_exists = dojo.room_exists("Black")
예제 #17
0
class TestRoomCreation(unittest.TestCase):

    """ Test cases for successful room creation and successful person addition
       """
    def setUp(self):
        self.dojo = Dojo()

    def test_create_room(self):
        self.assertEqual(len(self.dojo.rooms), 0)

    def test_invalid_room(self):
        self.dojo.create_room("kenya", "kenya")
        self.assertEqual(len(self.dojo.rooms), 0)

    def test_create_office(self):
        self.dojo.create_room("office", ["blue"])
        self.assertEqual(len(self.dojo.offices), 1)

    def test_create_living_space(self):
        self.dojo.create_room("living", ["green"])
        self.assertEqual(len(self.dojo.living_space), 1)

    def test_create_multiple_offices(self):
        self.dojo.create_room('office', ["green", "blue"])
        self.assertEqual(len(self.dojo.offices), 2)

    def test_add_persons_invalid_role(self):
        self.dojo.create_room("office", ["blue"])
        self.dojo.add_persons("Farhan Abdi", 'ljjlll', "N")
        self.assertEqual(len(self.dojo.persons_total), 0)

    def test_add_persons_Fellow(self):
        self.dojo.create_room(["blue"], "office")
        self.dojo.create_room(["blue"], "living space")
        self.dojo.add_persons("Farhan Abdi", 'FELLOW', 'Y')
        self.assertEqual(len(self.dojo.persons_fellow), 1)

    def test_add_persons_staff(self):
        self.dojo.create_room(["blue"], "office")
        self.dojo.create_room(["blue"], "living space")
        self.dojo.add_persons("Farhan Abdi", "STAFF", "N")
        self.assertEqual(len(self.dojo.persons_staff), 1)

    def test_add_persons_staff_to_offices(self):
        self.dojo.create_room("office", ['blue'])
        self.dojo.add_persons("farhan", "STAFF", "Y")
        self.assertEqual(len(self.dojo.offices), 1)
        self.assertEqual(len(self.dojo.living_space), 0)

    def test_add_persons_fellow_to_offices_and_living_spaces(self):
        self.dojo.create_room("office", ['blue'])
        self.dojo.create_room("living", ['green'])
        self.dojo.add_persons("farhan", "FELLOW", "Y")
        self.assertEqual(len(self.dojo.offices), 1)
        self.assertEqual(len(self.dojo.living_space), 1)
        self.dojo.add_persons("farhan", "FELLOW", "N")
        self.assertEqual(len(self.dojo.offices), 1)
        self.assertEqual(len(self.dojo.living_space), 1)

    def test_duplicate_room_names(self):
        self.dojo.create_room("office", ["blue"])
        self.dojo.create_room("office", ["blue"])
        self.assertEqual(len(self.dojo.offices), 1)

    def test_print_rooms(self):
        self.dojo.create_room("office", ["blue"])
        self.dojo.add_persons("eldi", "STAFF", "N")
        self.dojo.print_room("blue")
        value = sys.stdout
        output = value.getvalue()
        self.assertIn('eldi', output)

    def test_print_allocations_on_screen(self):
        self.dojo.create_room("office", ["blue"])
        self.dojo.add_persons("eldi", "STAFF", "N")
        self.dojo.print_allocations()
        value = sys.stdout
        output = value.getvalue()
        self.assertIn('eldi', output)