Exemple #1
0
class TestCreateRoom(unittest.TestCase):
    """create_room command test cases"""
    def setUp(self):
        """create Dojo() object"""
        self.dojo = Dojo()

    def test_room_type_can_only_be_office_or_livingspace(self):
        room1 = self.dojo.create_room("room1", "room")
        error = "Only offices and livingrooms allowed!"
        self.assertEqual(error, room1[0])

    def test_room_name_only_string(self):
        room2 = self.dojo.create_room(1212, 1212)
        err = 'names and person type should be a strings!'
        self.assertTrue(err, room2[0])

    def test_cannot_create_duplicate_rooms(self):
        room = self.dojo.create_room("stive", "office")
        dup = self.dojo.create_room("stive", "office")
        err = "Room stive already exists!"
        self.assertEqual(err, dup[0])

    def test_room_created_successfully(self):
        initial_room_count = len(self.dojo.rooms)
        blue_office = self.dojo.create_room("Blue", "office")
        self.assertTrue(blue_office)
        new_room_count = len(self.dojo.rooms)
        self.assertEqual(new_room_count - initial_room_count, 1)
Exemple #2
0
	def add(cls, livingspace):
		cls.filter_livingspace(livingspace)
		Dojo.add_room(livingspace)
		cls.__livingspaces_set.add("%s-%s" % (livingspace.name, livingspace.type_))
		cls.__livingspaces.update({livingspace.name: 
									[{"capacity": livingspace.capacity}, 
										{"type_": livingspace.type_}]})
Exemple #3
0
class TestPrint(unittest.TestCase):
    def setUp(self):
        """ SetUp Dojo instance and populate test data"""
        self.instance = Dojo()
        self.instance.offices = {
            'Blue':
            ['Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau'],
            'Brown': ['Morris Kimani', 'Elizabeth Mabishi'],
            'Band': ['Joy Warugu', 'Evans Musomi', 'Jackson Saya']
        }
        self.instance.livingspaces = {
            'Black': ['Loice Andia'],
            'Bold': [],
            'Blueberry': ['Elizabeth Mabishi', 'Joy Warugu']
        }
        self.instance.fellows = [
            'Joshua Ondieki', 'Loice Andia', 'Morris Kimani',
            'Elizabeth Mabishi', 'Joy Warugu'
        ]
        self.instance.staff = [
            'James Ndiga', 'Annette Kamau', 'Evans Musomi', 'Jackson Saya'
        ]
        self.instance.fellows.append('Lost Guy')
        self.instance.all_people.append(
            'Lost Guy'
        )  # add a person without getting allocations :: LOST GUY FELLOW Y
        self.instance.all_rooms = {
            'Blue': [
                'office',
                [
                    'Joshua Ondieki', 'Loice Andia', 'James Ndiga',
                    'Annette Kamau'
                ]
            ],
            'Brown': ['office', ['Morris Kimani', 'Elizabeth Mabishi']],
            'Band': ['office', ['Joy Warugu', 'Evans Musomi', 'Jackson Saya']],
            'Black': ['livingspace', ['Loice Andia']],
            'Bold': ['livingspace', []],
            'Blueberry': ['office', ['Elizabeth Mabishi', 'Joy Warugu']]
        }

    def test_print_names_of_people_in_specific_room(self):
        people_in_blue = {
            'Blue':
            ['Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau']
        }
        query_with_room_name = self.instance.print_room('Blue')
        self.assertEqual(query_with_room_name, people_in_blue)

    def test_print_allocations_with_file(self):
        self.instance.print_allocations('test.txt')
        test_file = Path("test.txt")
        self.assertTrue(test_file.is_file())

    def test_print_unallocations_with_file(self):
        self.instance.print_unallocations('test1.txt')
        test_file = Path("test1.txt")
        self.assertTrue(test_file.is_file())
Exemple #4
0
 def test_add_office(self):
     office = Office('MyOffice78')
     initial_room_count = len(Dojo.rooms())
     initial_office_count = len(Office.rooms())
     Office.add(office)
     new_room_count = len(Dojo.rooms())
     new_office_count = len(Office.rooms())
     self.assertEqual([initial_room_count + 1, initial_office_count + 1],
                      [new_room_count, new_office_count])
Exemple #5
0
 def test_remove_office(self):
     office = Office('MyOffice89')
     Office.add(office)
     initial_room_count = len(Dojo.rooms())
     initial_office_count = len(Office.rooms())
     Office.remove(office)
     new_room_count = len(Dojo.rooms())
     new_office_count = len(Office.rooms())
     self.assertEqual([initial_room_count - 1, initial_office_count - 1],
                      [new_room_count, new_office_count])
Exemple #6
0
	def test_print_populated_room(self):
		self.clear_stores()
		office = Office("NDO")
		Dojo.add_room(office)
		fellow = Fellow("Xone", "Ndobile", "0856443334", "y")
		fellow.register()
		office.allocate_to(fellow)
		allocations = office.allocations()
		output = Room.members(allocations)
		self.assertEqual(output, " 0856443334, NDOBILE, XONE, FELLOW\n")
Exemple #7
0
 def add(cls, office):
     cls.filter_office(office)
     Dojo.add_room(office)
     cls.__offices_set.add("%s-%s" % (office.name, office.type_))
     cls.__offices.update({
         office.name: [{
             "capacity": office.capacity
         }, {
             "type_": office.type_
         }]
     })
Exemple #8
0
	def test_print_existing_allocations_to_screen(self):
		self.clear_stores()
		office = Office("NDO2")
		Dojo.add_room(office)
		fellow = Fellow("Xone2", "Ndobile2", "0856443324", "y")
		fellow.register()
		office.allocate_to(fellow)
		allocations_ = Room.all_allocations()
		output = Room.members(allocations_, room_tag=True)
		expected_output = " NDO2-OFFICE, 0856443324, NDOBILE2, XONE2, FELLOW\n"
		self.assertEqual(output, expected_output)
Exemple #9
0
	def test_print_existing_allocations_to_default_file(self):
		self.clear_stores()
		office = Office("ND2")
		Dojo.add_room(office)
		fellow = Fellow("Xne2", "Ndoile2", "0868443324", "y")
		fellow.register()
		office.allocate_to(fellow)
		allocations_ = Room.all_allocations()
		expected_output = Room.members(allocations_, room_tag=True)
		Room.to_file(expected_output)
		path = "output/"
		f = open(path+"File.txt", "r")
		output = f.read() #"NDO2-Office, 0856443324, NDOBILE2, XONE2, FELLOW"
		f.close()
		self.assertEqual(expected_output, output)
Exemple #10
0
	def test_print_existing_unallocated_to_screen(self):
		self.clear_stores()
		office = Office("NDO4")
		Dojo.add_room(office)
		fellow = Fellow("Xone4", "Ndobile4", "0856443354", "y")
		fellow.register()
		office.allocate_to(fellow)
		fellow = Fellow("Xone5", "Ndobile6", "0856443009", "n")
		fellow.register()
		office.allocate_to(fellow)
		fellow = Fellow("Xone3", "Ndobile3", "0856443344", "y")
		fellow.register()
		output = Room.all_unallocated_persons()
		expected_output = "0856443344, NDOBILE3, XONE3, FELLOW\n"
		self.assertEqual(output, expected_output)
Exemple #11
0
	def test_print_existing_allocations_to_specific_file(self):
		self.clear_stores()
		office = Office("ND88")
		Dojo.add_room(office)
		fellow = Fellow("Xne88", "Ndoile88", "086800000", "y")
		fellow.register()
		office.allocate_to(fellow)
		allocations_ = Room.all_allocations()
		expected_output = Room.members(allocations_, room_tag=True)
		file_name = office.name+"-Allocations"
		Room.to_file(expected_output, file_name)
		path = "output/"
		f = open(path+file_name+".txt", "r")
		output = f.read() 
		f.close()
		self.assertEqual(expected_output, output)
class TestDojo(unittest.TestCase):
    """Test cases for the dojo class"""

    # Instantiating objects for using in the tests
    def setUp(self):
        self.blue_office = Room('Office', 'Blue')
        self.pink_living_space = Room('Living Space', 'Pink')
        self.rooms = {self.blue_office.name: self.blue_office, self.pink_living_space.name: self.pink_living_space}
        self.the_dojo = Dojo('Nairobi', self.rooms)

    # Test if the class creates an instance of itself
    def test_dojo_instance(self):
        self.assertIsInstance(self.the_dojo, Dojo, msg='The object should be an instance of the `Dojo` class')

    # Test if the class creates a type of itself
    def test_type(self):
        self.assertTrue((type(self.the_dojo) is Dojo), msg='The object should be of type `Dojo`')

    # Test if the class creates an accurate default model
    def test_default_model_for_dojo(self):
        default_dojo = Dojo()
        self.assertEqual('Nairobi', default_dojo.location, msg='The default location for the dojo should be `Nairobi`')

    # Test if the properties of the class are arranged in the proper order
    def test_dojo_properties(self):
        kampala = Dojo('Kampala', self.rooms)
        self.assertListEqual(['Kampala', 2], [kampala.location, len(kampala.rooms)],
                             msg='The location and rooms of the Dojo should be properties arranged '
                                 'respectively')

    # Test if the get_vacant_rooms method returns the right value for the given inputs
    def test_vacant_rooms(self):
        self.assertEqual(2, len(self.the_dojo.get_vacant_rooms()), msg='The class has to return a dictionary of 2 rooms')
Exemple #13
0
class TestPrintAllocations(unittest.TestCase):
    def setUp(self):
        self.dojo = Dojo()

    def test_no_allocations_available(self):
        msg = colored("No allocations available", "cyan")
        allocations = self.dojo.print_allocations()
        self.assertEqual(msg, allocations)
Exemple #14
0
 def test_remove_existing_room(self):
     room = LivingSpace("xd")
     Dojo.add_room(room)
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     Dojo.remove_room(room)
     new_room_count = Dojo.room_count()
     new_found_state = Dojo.has_room(room)
     self.assertEqual([new_room_count, new_found_state],
                      [initial_room_count - 1, not initial_found_state])
Exemple #15
0
class TestPrintRoom(unittest.TestCase):
    """testcase for print room"""
    def setUp(self):
        self.dojo = Dojo()   
    def test_print_room(self):
        '''test that members of a room are printed'''
        self.dojo.create_room('blue', 'office')
        self.dojo.add_person('mwenda', 'fellow', 'Y')
        self.dojo.add_person('miriti', 'staff')
        self.dojo.add_person('Eric', 'fellow')
        results = self.dojo.print_room('blue')
        expected = "3 names printed"
        self.assertEqual(results, expected)    
    def test_room_must_be_avialable(self):
        """test that cannot print rooms not available"""
        room = self.dojo.print_room('bluered')
        msg = colored("Room bluered does not exist!", "red")
        self.assertEqual(room, msg)
Exemple #16
0
 def test_add_existing_room(self):
     room = Office("yc")
     Dojo.add_room(room)
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     with self.assertRaises(ValueError):
         Dojo.add_room(room)
     new_room_count = Dojo.room_count()
     new_found_state = Dojo.has_room(room)
     self.assertEqual([new_room_count, new_found_state],
                      [initial_room_count, initial_found_state])
Exemple #17
0
 def from_name(cls, name):
     room = cls(name)
     if Dojo.has_room(room):
         room_name_type = room.name + "-" + room.type_
         if room_name_type in cls.__offices_set:
             return room
         else:
             raise ValueError("Room not found")
     else:
         raise ValueError("Room not found")
Exemple #18
0
class TestAddPerson(unittest.TestCase):
    """add_person command testcases"""
    def setUp(self):
        self.dojo=Dojo()

    def test_person_can_only_be_staff_or_fellow(self):
        person1=self.dojo.add_person('mwenda','1213','Y')
        self.assertEqual('Person type can only be a fellow or a staff!',person1)

    def test_person_name_only_string(self):
        person2=self.dojo.add_person('mwenda',1213,'Y')
        person3=self.dojo.add_person(123,'office','Y')
        error='names and person type should be a strings!'
        self.assertEqual(error,person2)
        self.assertEqual(error,person3)

    def test_person_created_successfully(self):
        employee_count = len(self.dojo.all_employees)
        mwenda = self.dojo.add_person("mwenda", "staff")
        new_count = len(self.dojo.all_employees)
        self.assertEqual((new_count - employee_count), 1)
Exemple #19
0
 def setUp(self):
     """ SetUp Dojo instance and populate test data"""
     self.instance = Dojo()
     self.instance.offices = {
         'Blue':
         ['Joshua Ondieki', 'Loice Andia', 'James Ndiga', 'Annette Kamau'],
         'Brown': ['Morris Kimani', 'Elizabeth Mabishi'],
         'Band': ['Joy Warugu', 'Evans Musomi', 'Jackson Saya']
     }
     self.instance.livingspaces = {
         'Black': ['Loice Andia'],
         'Bold': [],
         'Blueberry': ['Elizabeth Mabishi', 'Joy Warugu']
     }
     self.instance.fellows = [
         'Joshua Ondieki', 'Loice Andia', 'Morris Kimani',
         'Elizabeth Mabishi', 'Joy Warugu'
     ]
     self.instance.staff = [
         'James Ndiga', 'Annette Kamau', 'Evans Musomi', 'Jackson Saya'
     ]
     self.instance.fellows.append('Lost Guy')
     self.instance.all_people.append(
         'Lost Guy'
     )  # add a person without getting allocations :: LOST GUY FELLOW Y
     self.instance.all_rooms = {
         'Blue': [
             'office',
             [
                 'Joshua Ondieki', 'Loice Andia', 'James Ndiga',
                 'Annette Kamau'
             ]
         ],
         'Brown': ['office', ['Morris Kimani', 'Elizabeth Mabishi']],
         'Band': ['office', ['Joy Warugu', 'Evans Musomi', 'Jackson Saya']],
         'Black': ['livingspace', ['Loice Andia']],
         'Bold': ['livingspace', []],
         'Blueberry': ['office', ['Elizabeth Mabishi', 'Joy Warugu']]
     }
Exemple #20
0
 def test_add_new_room(self):
     room = LivingSpace("hl")
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     Dojo.add_room(room)
     new_room_count = Dojo.room_count()
     new_found_state = Dojo.has_room(room)
     self.assertEqual([new_room_count, new_found_state],
                      [initial_room_count + 1, not initial_found_state])
Exemple #21
0
class TestPrintUnallocated(unittest.TestCase):
    """testcase for print unallocated"""
    def setUp(self):
        self.dojo = Dojo()

    def test_print_un_allocated(self):
        '''test_print_un_allocated'''
        self.dojo.create_room('blue', 'office')
        self.dojo.add_person('Ken', 'fellow', 'Y')
        unallocated = self.dojo.print_unallocated()
        outcome = "1 names printed"
        self.assertEqual(outcome, unallocated)

    def test_no_un_allocations(self):
        """test_no_un_allocations"""
        unallocated = self.dojo.print_unallocated()
        msg = colored("No unallocated Employeee at the moment!", "red")
        self.assertEqual(unallocated, msg)
Exemple #22
0
 def remove(cls, office):
     cls.filter_office(office)
     Dojo.remove_room(office)
     del cls.__offices[office.name]
     cls.__offices_set.remove("%s-%s" % (office.name, office.type_))
Exemple #23
0
 def setUp(self):
     """create Dojo() object"""
     self.dojo = Dojo()
Exemple #24
0
 def test_filter(self):
     with self.assertRaises(TypeError):
         Dojo.filter("xy")
Exemple #25
0
	def clear_stores(self):
		#Clean data stores to run print tests
		Dojo.clear()
		Room.clear()
		Person.clear()
Exemple #26
0
class TestReallocatePerson(unittest.TestCase):
    """Reallocation test cases"""
    def setUp(self):
        self.dojo = Dojo()

    def test_person_exists(self):
        """test_person_exists"""
        self.dojo.create_room("red", "office")
        reallocate = self.dojo.reallocate_person("mwenda", "red")
        msg = colored("Person Mwenda does not exist!", "red")
        self.assertEqual(reallocate, msg)

    def test_room_exists(self):
        """test_room_exists"""
        self.dojo.add_person("miriti", 'fellow')
        reallocate = self.dojo.reallocate_person("miriti", "red")
        error = colored("Room red does not exist!", "red")
        self.assertEqual(reallocate, error)

    def test_reallocated(self):
        """test_reallocated successfully"""
        self.dojo.add_person('miriti', 'staff')
        self.dojo.create_room('blue', 'office')
        first = self.dojo.print_room("blue")
        self.assertEqual("0 names printed", first)
        self.dojo.reallocate_person("miriti", "blue")
        results = self.dojo.print_room('blue')
        self.assertEqual(results, "1 names printed")
Exemple #27
0
class TestAddPerson(unittest.TestCase):
    def setUp(self):
        self.dojo = Dojo()
        self.initial_people = len(self.dojo.all_people)

    def test_create_people_successfully(self):
        self.fellow = self.dojo.add_person('Joshua', 'Ondieki', 'Fellow')
        self.staff = self.dojo.add_person('Annette', 'Kamau', 'Staff')
        new_people = len(self.dojo.all_people)
        self.assertEqual(new_people - self.initial_people, 2)

    def test_it_fails_with_existing_person(self):
        exist_person = self.dojo.add_person('Joshua', 'Ondieki', 'Fellow')
        try_overwrite_f = self.dojo.add_person('Joshua', 'Ondieki', 'Fellow')
        exist_person = self.dojo.add_person('Evans', 'Musomi', 'Staff')
        try_overwrite_s = self.dojo.add_person('Evans', 'Musomi', 'Staff')
        self.assertTrue(try_overwrite_f == error('Joshua Ondieki exists!')
                        and try_overwrite_s == error('Evans Musomi exists!'))

    def test_it_fails_with_invalid_person_type(self):
        invalid_type = self.dojo.add_person('Loice', 'Andia', 'BFA')
        self.assertEqual(error('Only fellow and staff allowed!'), invalid_type)

    def test_fails_with_person_name_not_string(self):
        invalid_person = self.dojo.add_person(['Oj'], 'Josh', 'Fellow')
        invalid_person1 = self.dojo.add_person({'Oj': 'Josh'}, {}, 'Fellow')
        invalid_person2 = self.dojo.add_person(['Oj'], ['Josh'], 'Staff')
        invalid_person3 = self.dojo.add_person({'Oj': 'Josh'}, {}, 'Staff')
        self.assertEqual(invalid_person,
                         error('People names can only be strings!'))
        self.assertEqual(invalid_person1,
                         error('People names can only be strings!'))
        self.assertEqual(invalid_person2,
                         error('People names can only be strings!'))
        self.assertEqual(invalid_person3,
                         error('People names can only be strings!'))
Exemple #28
0
import random
from models.dojo import Dojo
from models.room import Room
from models.office import Office
from models.living_space import LivingSpace
from models.person import Person
from models.fellow import Fellow
from models.staff import Staff
"""The file contains the methods that are critical for the functionality of the app"""

the_dojo = Dojo('Nairobi')
total_number_of_rooms = 100
unallocated_people = {}


# This is a helper function that returns a list of all names of occupants in offices
def get_all_office_occupants():
    all_office_occupants = []
    if the_dojo.rooms:
        for room in [
                a_room for a_room in the_dojo.get_vacant_rooms().values()
                if isinstance(a_room, Office)
        ]:
            all_office_occupants.extend(room.occupants.keys())
    return all_office_occupants


# This is a helper function that returns a list of all names of occupants in livingspaces
def get_all_livingspace_occupants():
    all_livingspace_occupants = []
    if the_dojo.rooms:
Exemple #29
0
 def setUp(self):
     self.dojo = Dojo()
     self.initial_people = len(self.dojo.all_people)
Exemple #30
0
 def setUp(self):
     self.dojo = Dojo()