Example #1
0
class TestSaveState(unittest.TestCase):
    ''' The test suite for the functionalities,
    save state and load state in the Dojo
    class'''
    def setUp(self):
        self.dojo = Dojo()

    def test_empty_session_not_persisted(self):
        self.dojo.save_state()
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result,
                         'Session has no data to persist to the database.')

    def test_session_with_data_saved_successfully(self):
        self.dojo.create_room('office', ['Valala'])
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.add_person('pet', 'sampras', 'staff')
        self.dojo.save_state('test_dojo.db')
        result = sys.stdout.getvalue().strip()
        self.assertTrue(result)
        self.assertEqual(result[237:280],
                         'Your session has been saved to the database')

    def tearDown(self):
        del self.dojo
class TestPrintAllocations(unittest.TestCase):
    """This test suite tests the Print Allocations functionality."""
    def setUp(self):
        self.dojo = Dojo()
        self.HOME_DIR = expanduser('~')

    def test_print_allocations_when_no_room(self):
        self.dojo.print_allocations()
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result, 'There are currently no rooms in Dojo.')

    def test_print_allocations_to_screen(self):
        self.dojo.create_room('office', ['idanre'])
        self.dojo.print_allocations()
        result = sys.stdout.getvalue().strip()
        self.assertTrue(result)
        self.assertEqual(result[104:], 'IDANRE has no occupants')

    def test_print_allocations_to_file(self):
        # test that file is valid and was written into.
        self.dojo.create_room('office', ['Blue'])
        self.dojo.add_person('ladi', 'ade', 'fellow')
        result = self.dojo.print_allocations('allocations')
        self.assertTrue(result)
        file_name = self.HOME_DIR + '/.dojo_data/allocations.txt'
        self.assertEqual(result, file_name)
        room_name = linecache.getline(result, 1).strip()
        allocations_line = linecache.getline(result, 3).strip()
        self.assertEqual(room_name, 'BLUE office')
        self.assertEqual(allocations_line, 'Ladi Ade (FELLOW)')

    def tearDown(self):
        del self.dojo
class TestPrintUnallocated(unittest.TestCase):
    """Test suite for the print_unallocated dojo function"""
    def setUp(self):
        self.dojo = Dojo()
        self.HOME_DIR = expanduser('~')

    def test_print_unallocated_for_no_people(self):
        result = self.dojo.print_unallocated()
        self.assertTrue(result)
        self.assertEqual(result, 'No person in the System Yet!')

    def test_print_no_unallocated_person(self):
        self.dojo.create_room('office', ['QB'])
        self.dojo.add_person('nas', 'escobar', 'fellow')
        result = self.dojo.print_unallocated()
        self.assertFalse(result)

    def test_print_unallocated_to_screen(self):
        self.dojo.add_person('rukky', 'remy', 'staff')
        self.dojo.print_unallocated()
        result = sys.stdout.getvalue().strip()
        self.assertTrue(result)
        self.assertEqual(result[108:128], '1 Rukky Remy (STAFF)')

    def test_print_unallocated_to_file(self):
        self.dojo.add_person('ric', 'hassani', 'fellow')
        value = self.dojo.print_unallocated('unallocated.txt')
        self.assertTrue(value)
        filename = self.HOME_DIR + '/.dojo_data/unallocated.txt'
        self.assertEqual(value, filename)
        unallocated_line1 = linecache.getline(value, 1).strip()
        unallocated_line2 = linecache.getline(value, 2).strip()
        self.assertEqual(unallocated_line1,
                         '(ID) UNALLOCATED LIST OFFICE SPACE')
        self.assertEqual(unallocated_line2, '1 Ric Hassani (FELLOW)')

    def test_valid_people_id(self):
        self.dojo.add_person('remy', 'ma', 'staff')
        self.dojo.add_person('travis', 'greene', 'staff')
        self.dojo.add_person('temmy', 'orwase', 'fellow')
        self.dojo.people_id()
        result = sys.stdout.getvalue().strip()
        self.assertTrue(result)

    def tearDown(self):
        del self.dojo
Example #4
0
class TestLoadState(unittest.TestCase):
    def setUp(self):
        self.dojo = Dojo()

    def test_load_file_successfully(self):
        self.dojo.create_room('office', ['Valala'])
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.add_person('pet', 'sampras', 'staff')
        self.dojo.save_state('test_dojo.db')
        self.dojo.load_state('test_dojo.db')
        room = self.dojo.all_rooms[0]
        fellow = self.dojo.people[0]
        staff = self.dojo.people[1]
        self.assertEqual(room.name, 'VALALA')
        self.assertTrue(fellow.fname, 'Ladi')
        self.assertTrue(staff.fname, 'Pet')

    def test_handle_bad_db(self):
        self.dojo.append_valid_extension_to_data_path('bad', '.db')
        self.dojo.load_state('bad.db')
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result, 'Does not exist or Invalid')
class TestPrintRoom(unittest.TestCase):
    """Test suite for the print_room functionality"""
    def setUp(self):
        self.dojo = Dojo()

    def test_print_room_when_no_rooms(self):
        self.dojo.print_room('Blue')
        value = sys.stdout.getvalue().strip()
        self.assertEqual(value, 'BLUE not a room in Dojo.')

    def test_print_room_invalid_room(self):
        self.dojo.print_room('Valor')
        value = sys.stdout.getvalue().strip()
        self.assertEqual(value, 'VALOR not a room in Dojo.')

    def test_print_room_valid_empty_room(self):
        self.dojo.create_room('living_space', ['Maze'])
        self.dojo.print_room('Maze')
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result[61:], 'MAZE currently has no occupant(s)!')

    def test_print_room_with_office_occupants(self):
        self.dojo.create_room('office', ['Blue'])
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.add_person('ab', 'soul', 'staff')
        self.dojo.print_room('Blue')
        result = sys.stdout.getvalue().strip()
        self.assertTrue(result)
        self.assertEqual(result[226:],
                         'Ladi Adeniran (FELLOW), Ab Soul (STAFF)')

    def test_print_room_with_living_space_occupants(self):
        self.dojo.create_room('living_space', ['orion'])
        self.dojo.add_person('ladi', 'adeniran', 'fellow', 'y')
        self.dojo.print_room('Orion')
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result[185:], 'Ladi Adeniran (FELLOW)')

    def tearDown(self):
        del self.dojo
Example #6
0
class TestAddPerson(unittest.TestCase):
    """Test suite for the add_person Dojo functonality
    """
    def setUp(self):
        self.dojo = Dojo()
        self.room_manager = RoomManager()
        self.person_manager = PersonManager()

    def test_create_fellow_successfully(self):
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        result = self.dojo.people[0]
        self.assertTrue(result)
        self.assertEqual(result.fname, 'Ladi')
        self.assertEqual(result.lname, 'Adeniran')
        self.assertEqual(result.role, 'fellow')

    def test_create_staff_successfully(self):
        self.dojo.add_person('Nas', 'Jones', 'staff')
        result = self.dojo.people[0]
        self.assertTrue(result)
        self.assertEqual(result.fname, 'Nas')
        self.assertEqual(result.lname, 'Jones')
        self.assertEqual(result.role, 'staff')

    def test_add_fellow_staff_to_office_successfully(self):
        self.dojo.create_room('office', ['Blue'])
        self.dojo.add_person('Ab', 'Soul', 'fellow')
        self.dojo.add_person('Jeremih', 'Camp', 'staff')
        fellow = self.dojo.people[0]
        staff = self.dojo.people[1]
        room = self.room_manager.get_room_with_a_room_name(
            'Blue', self.dojo.all_rooms)
        self.assertTrue(fellow)
        self.assertTrue(staff)
        self.assertEqual(fellow.office, 'BLUE')
        self.assertEqual(staff.office, 'BLUE')
        self.assertTrue(room.occupants)
        self.assertEqual(str(room.occupants[0]), 'Ab Soul')
        self.assertEqual(str(room.occupants[1]), 'Jeremih Camp')

    def test_add_fellow_to_living_space(self):
        self.dojo.create_room('living_space', ['Amity'])
        self.dojo.add_person('Jeremiah', 'Camp', 'fellow', 'y')
        fellow = self.dojo.people[0]
        room = self.room_manager.get_room_with_a_room_name(
            'Amity', self.dojo.all_rooms)
        self.assertEqual(fellow.living_space, 'AMITY')
        self.assertEqual(str(room.occupants[0]), 'Jeremiah Camp')

    def test_only_add_fellow_or_staff(self):
        self.dojo.add_person('Joshua', 'Emmsong', 'Engineer')
        engineer = self.dojo.people
        self.assertFalse(engineer)

    def test_staff_not_have_living_space(self):
        self.dojo.create_room('living_space', ['UPPERROOM'])
        self.dojo.add_person('ladi', 'adeniran', 'staff', 'y')
        staff = self.dojo.people[0]
        self.assertTrue(staff)
        self.assertEqual(staff.office, None)
        room = self.room_manager.get_room_with_a_room_name(
            'Upperroom', self.dojo.all_rooms)
        self.assertFalse(room.occupants)
Example #7
0
class TestCreateRoom(unittest.TestCase):
    """Write Docstring here """
    def setUp(self):
        self.dojo = Dojo()
        self.room_manager = RoomManager()
        self.person_manager = PersonManager()

    def test_created_office_successfully(self):
        initial_room_count = len(self.dojo.all_rooms)
        self.dojo.create_room("office", ['BLUE'])
        value = self.room_manager.get_room_with_a_room_name(
            'Blue', self.dojo.all_rooms)
        self.assertTrue(value)
        self.assertEqual(value.name, 'BLUE')
        self.assertEqual(value.room_type, 'office')
        new_room_count = len(self.dojo.all_rooms)
        room_count_diff = new_room_count - initial_room_count
        self.assertEqual(room_count_diff, 1)

    def test_created_living_space_successfully(self):
        initial_room_count = len(self.dojo.all_rooms)
        self.dojo.create_room('living_space', ['ORANGE'])
        value = self.room_manager.get_room_with_a_room_name(
            'orange', self.dojo.all_rooms)
        self.assertTrue(value)
        self.assertEqual(value.name, 'ORANGE')
        self.assertEqual(value.room_type, 'living_space')
        new_room_count = len(self.dojo.all_rooms)
        room_count_diff = new_room_count - initial_room_count
        self.assertEqual(room_count_diff, 1)

    def test_created_multi_offices_or_living_spaces(self):
        initial_room_count = len(self.dojo.all_rooms)
        self.dojo.create_room('office', ['Orion', 'Dev', 'fly'])
        new_room_count = len(self.dojo.all_rooms)
        room_count_diff = new_room_count - initial_room_count
        self.assertEqual(room_count_diff, 3)

    def test_room_uniqueness(self):
        initial_room_count = len(self.dojo.all_rooms)
        amigo_office = self.dojo.create_room('office', ['amigo', 'amigo'])
        new_room_count = len(self.dojo.all_rooms)
        room_count_diff = new_room_count - initial_room_count
        self.assertEqual(room_count_diff, 1)

    def test_create_room_is_only_for_offices_living_spaces(self):
        initial_room_count = len(self.dojo.all_rooms)
        self.dojo.create_room('kitchen', ['Puerto'])
        new_room_count = len(self.dojo.all_rooms)
        room_count_diff = new_room_count - initial_room_count
        self.assertEqual(room_count_diff, 0)

    def test_max_office_size(self):
        self.dojo.create_room('office', ['MAZE'])
        room = self.room_manager.get_room_with_a_room_name(
            'Maze', self.dojo.all_rooms)
        self.assertEqual(room.max_size, 6)
        self.assertEqual(len(room.occupants), 0)

    def test_max_living_space_size(self):
        self.dojo.create_room('living_space', ['ORION'])
        room = self.room_manager.get_room_with_a_room_name(
            'orion', self.dojo.all_rooms)
        self.assertEqual(room.max_size, 4)
        self.assertEqual(len(room.occupants), 0)

    def test_max_limit_added_office(self):
        self.dojo.create_room('office', ['DEV'])
        room = self.room_manager.get_room_with_a_room_name(
            'Dev', self.dojo.all_rooms)
        self.assertEqual(len(room.occupants), 0)
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.add_person('ade', 'poju', 'staff')
        self.dojo.add_person('ginu', 'whyne', 'fellow')
        self.dojo.add_person('mark', 'anthony', 'fellow')
        self.dojo.add_person('anthony', 'hamilton', 'fellow')
        self.dojo.add_person('game', 'truce', 'fellow')
        self.dojo.add_person('saliu', 'bryan', 'fellow')
        self.dojo.add_person('zuck', 'beast', 'fellow')
        self.assertEqual(len(room.occupants), 6)

    def tearDown(self):
        del self.dojo
        del self.room_manager
        del self.person_manager
class TestReallocatePerson(unittest.TestCase):
    """Test suite for the reallocate person functionality"""
    def setUp(self):
        self.dojo = Dojo()

    def test_index_id_room(self):
        self.dojo.reallocate_person(1, 'Blue')
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result, 'Id/Room_Name not found!')

    def test_not_reallocate_to_present_room(self):
        self.dojo.create_room('office', ['Orion'])
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.reallocate_person(1, 'ORION')
        result = sys.stdout.getvalue().strip()
        self.assertEqual(result[147:],
                         'You cannot reallocate person to current room.')

    def test_reallocate_fellow_staff_with_office(self):
        self.dojo.create_room('office', ['Naples'])
        self.dojo.add_person('brian', 'houston', 'fellow')
        self.dojo.add_person('ben', 'ayade', 'staff')
        fellow = self.dojo.people[0]
        staff = self.dojo.people[1]
        self.assertEqual(fellow.office, 'NAPLES')
        self.assertEqual(staff.office, 'NAPLES')
        self.dojo.create_room('office', ['Vienna'])
        self.dojo.reallocate_person(1, 'Vienna')
        self.dojo.reallocate_person(2, 'Vienna')
        self.assertEqual(fellow.office, 'VIENNA')
        self.assertEqual(staff.office, 'VIENNA')

    def test_reallocate_fellow_staff_with_no_office(self):
        self.dojo.add_person('ladi', 'adeniran', 'fellow')
        self.dojo.add_person('bayo', 'emmanuel', 'staff')
        fellow = self.dojo.people[0]
        staff = self.dojo.people[1]
        self.dojo.create_room('office', ['Blue'])
        self.assertFalse(fellow.office)
        self.assertFalse(staff.office)
        self.dojo.reallocate_person(1, 'Blue')
        self.dojo.reallocate_person(2, 'Blue')
        self.assertEqual(fellow.office, 'BLUE')
        self.assertEqual(staff.office, 'BLUE')

    def test_cannot_reallocate_to_full_room(self):
        self.dojo.create_room('office', ['Orion'])
        self.dojo.add_person('vie', 'ajah', 'fellow')
        self.dojo.add_person('dave', 'ajah', 'fellow')
        self.dojo.add_person('vie', 'emma', 'fellow')
        self.dojo.add_person('sojay', 'ajah', 'fellow')
        self.dojo.add_person('vie', 'beor', 'fellow')
        self.dojo.add_person('victor', 'anichebe', 'staff')
        self.dojo.add_person('kuti', 'mane', 'fellow')
        fellow = self.dojo.people[6]
        self.assertFalse(fellow.office)

    def test_invalid_person_id(self):
        self.dojo.add_person('ladi', 'adeniran', 'staff')
        self.dojo.create_room('office', ['Mane'])
        self.dojo.reallocate_person('1', 'orion')
        msg = sys.stdout.getvalue().strip()
        self.assertEqual(msg[130:], 'Person cannot be reallocated the room')

    def tearDown(self):
        del self.dojo