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)
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)
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_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')
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')
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_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_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_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')
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_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")
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_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_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')
def main(): dojo = Dojo(StockAgent, StockAgent, 'n7/5k2/8/8/8/8/8/3R3K w - - 0 1') (history, result) = dojo.play() mydir = 'results/svg/' filelist = [ f for f in os.listdir(mydir) if f.endswith(".svg") ] for f in filelist: os.remove(os.path.join(mydir, f)) for i in range(len(history)-1): with open('{}move_{}.svg'.format(mydir, i), 'w') as f: f.write(history[i]) print(result)
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")
class App(cmd.Cmd): intro = 'A Room Allocation system for Andela Kenya facility Known As the dojo' prompt = '(dojo_space)' dojo = Dojo() @docopt_cmd def do_create_room(self, arg): """ Usage: create_room <room_type> <room_name>... """ room_type = arg["<room_type>"] room_name = arg["<room_name>"] if room_type == "office" or room_type == "living": self.dojo.create_room(room_type, room_name) else: print( "You've entered an invalid room type. Please choose either office or living" ) @docopt_cmd def do_add_person(self, arg): """ Usage: add_person <first_name> <last_name> <role> [<wants_accommodation>] """ first_name = arg["<first_name>"] last_name = arg["<last_name>"] role = arg["<role>"] accommodation = arg["<wants_accommodation>"] self.dojo.add_person(first_name, last_name, role, accommodation) @docopt_cmd def do_print_room(self, arg): """ Usage: print_room <room_name> """ self.dojo.print_room(arg["<room_name>"]) @docopt_cmd def do_print_allocation(self, arg): """ Usage: print_allocation [<filename>] """ self.dojo.print_allocations(arg["<filename>"]) @docopt_cmd def do_print_unallocated(self, arg): """ Usage: print_unallocated [<filename>] """ self.dojo.print_unallocated(arg["<filename>"]) def do_quit(self, arg): """ Quits out of program""" print('See you next time!') exit()
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")
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):
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')
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')
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')
class DojoRoomAllocation(cmd.Cmd): os.system("clear") prompt = '\n ==== > DojoRoomAllocation: ' dojo = Dojo() @docopt_cmd def do_create_room(self, arg): """Usage: create_room <room_type> <room_names>... """ try: for room_name in arg['<room_names>']: print(dojo.create_room(arg['<room_type>'], room_name)) except Exception: msg = term.red + 'An error when running create_room command' + term.off @docopt_cmd def do_add_person(self, arg): """Usage: add_person <first_name> <last_name> <person_type> [--wants_accomodation=None] """ try: first_name = arg["<first_name>"] last_name = arg["<last_name>"] person_type = arg["<person_type>"] wants_accomodation = arg["--wants_accomodation"] print( person.add_person(first_name, last_name, person_type, wants_accomodation)) except Exception: msg = term.red + 'An error when running add_person command' + term.off def do_quit(self, arg): """Usage: quit """ os.system('clear') print('Thank you for using our app. Hope to see you back soon') exit()
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")
def test_saque_zero(self): dojo = Dojo() self.assertEqual(len(dojo.saque(0)), 0)
def test_saque_100(self): dojo = Dojo() self.assertEqual(len(dojo.saque(100)), 1) self.assertEqual(dojo.saque(100), {100:1})
def test_saque_70(self): dojo = Dojo() self.assertEqual(dojo.saque(70), {50:1,20:1})
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')
def test_saque_105(self): dojo = Dojo() self.assertEqual(dojo.saque(105),{})
from match import Match from tablefootball import TableFootballMatch from dojo import Dojo from project import Project import csv import random codecool_bp = CodecoolClass.generate_local() # for random: observed_class = codecool_bp all_students = codecool_bp.students all_mentors = codecool_bp.mentors all_matches = Match.generate_list('matches.csv') table_football_matches = TableFootballMatch.generate_list('tablefootball.csv') all_dojos = Dojo.generate_list('dojos.csv') all_projects = Project.generate_list('projects.csv') days_of_the_week = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday') # One week for day in days_of_the_week: # One day next_line = input("\nIt's " + day + ".\n") match_of_yesterday = random.choice(all_matches) was_it_expected = bool(match_of_yesterday.expected_result) print("Yesterday there was a match: " + match_of_yesterday.match_name) if match_of_yesterday.important == True: next_line = input("It was a really interesting match, a lot of students placed a bet on it.\n") else:
def setUp(self): """setup defaults""" self.held, sys.stdout = sys.stdout, StringIO() self.my_instance = Dojo()
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')
def test_saque_40(self): dojo = Dojo() self.assertEqual(dojo.saque(40), {20:2})
def setUp(self): self.dojo = Dojo()
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)