Esempio n. 1
0
 def setUp(self):
     pre_populate.populate()
     self.room = Office('gold')
     self.staff1 = Staff('tosin', 'ade')
Esempio n. 2
0
class OfficeTestCase(unittest.TestCase):

    def setUp(self):
        pre_populate.populate()
        self.room = Office('gold')
        self.staff1 = Staff('tosin', 'ade')

    def tearDown(self):
        del self.room
        reset.reset()

    def test_class(self):
        '''test object is instance of Office'''
        self.assertTrue(isinstance(self.room, Office),
                        'is not an instance of Office')

    def test_subclass(self):
        '''test object is subclass of Room'''
        self.assertTrue(issubclass(type(self.room), Room),
                        'is not a subclass of Room')

    def test_roomname_correct(self):
        '''test correct room name is set'''
        self.assertEqual(self.room.room_name, 'gold',
                         'incorrect room name was set')

    def test_space_count(self):
        '''test space limit is only 6'''
        self.assertLessEqual(self.room.space_count, 6,
                             'office space_count exceeds 6')

    def test_occupants(self):
        '''test occupants initially empty'''
        self.assertEqual(len(self.room.occupants), 0,
                         'list of occupants not initially empty')

    def test_get_occupants(self):
        '''test occupant list'''
        self.assertIsNone(self.room.get_occupants())


    def get_office_room(self, room):
        '''gets list of an office occupants from database'''

        con = lite.connect('amity.db')
        with con:
            con.row_factory = lite.Row
            cur = con.cursor()
            sql = "SELECT Occupants from Office where Room_name = '%s'" % room
            cur.execute(sql)
            result = cur.fetchone()

            if result is not None:
                # unpickle the data
                unpickled_result = pickle.loads(str(result['Occupants']))
            else:
                # return empty list
                unpickled_result = []
        return unpickled_result

    def test_occupants_in_room(self):
        '''test occupant added to office'''

        # assign staff to an ofiice
        self.staff1.assign_office('staff')
        # get office staff was assigned to
        staff_office = self.staff1.office_room

        # get occupants list of the office
        room_occupants = self.get_office_room(staff_office)

        # check staff is in office
        self.assertIn('tosin ade', room_occupants,
                      'Person not in occupants list of an office')