Exemplo n.º 1
0
class StaffTestCase(unittest.TestCase):

    def setUp(self):
        pre_populate.populate()
        self.me = Staff('john', 'doe')

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

    def test_class(self):
        '''test if object is of class Staff'''
        self.assertTrue(isinstance(self.me, Staff),
                        'object is not an instance of Staff')

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

    def test_names(self):
        '''test first and last names set correctly'''
        self.assertEqual(self.me.first_name, 'john',
                         'object first name incorrect')
        self.assertEqual(self.me.last_name, 'doe',
                         'object last name incorrect')

    def test_assign_staff_livingroom(self):
        '''test staff cannot be assigned living rooms'''

        with self.assertRaises(AttributeError):
            self.me.assign_living()
Exemplo n.º 2
0
 def setUp(self):
     pre_populate.populate()
     self.room = Office('gold')
     self.staff1 = Staff('tosin', 'ade')
Exemplo n.º 3
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')
Exemplo n.º 4
0
 def setUp(self):
     pre_populate.populate()
     self.me = Staff('john', 'doe')