def newWorker():
    bob = Worker()
    bob.name = ('Bob')
    bob.does_nothing()
    bob.add_role('S')
    bob.add_role('B')
    testDate = date(2012, 12, 31)
    testDate2 = date(2011, 12, 31)
    bob.clear_blacklist()
    bob.blacklist_date(testDate)
    bob.blacklist_date(testDate2)
    bob.phone_number = '0115'
    bob.address = 'a'
    bob.email = 'b'
    return bob
Exemplo n.º 2
0
class WorkerTest(unittest.TestCase):
    def setUp(self):
        self.bob = Worker()
        self.bob.name = 'Bob'
        Roles.GlobalRoleList.add_role(Roles.Role('Plumber', 'P', 1))
        Roles.GlobalRoleList.add_role(Roles.Role('Sailor', 'S', 1))
        Roles.GlobalRoleList.add_role(Roles.Role('Treasurer', 'T', 9))

    def tearDown(self):
        self.bob = None
        Roles.GlobalRoleList.clear()

    def testName(self):
        self.assertEqual(self.bob.name, 'Bob')

    def testNoRole(self):
        self.bob.does_nothing()
        self.assertEqual(self.bob.number_of_roles(), 0)

    def testAddRole(self):
        self.bob.does_nothing()
        self.bob.add_role('S')
        self.assertEqual(self.bob.number_of_roles(), 1)
        self.bob.add_role('P')
        self.assertEqual(self.bob.number_of_roles(), 2)
        self.bob.add_role('S')
        self.assertEqual(self.bob.number_of_roles(), 2)

    def testRemoveRole(self):
        self.bob.does_nothing()
        self.bob.add_roles('S P T P')
        self.assertEqual(self.bob.number_of_roles(), 3)
        self.bob.remove_role('P')
        self.assertEqual(self.bob.number_of_roles(), 2)
        self.bob.remove_role('S')
        self.assertEqual(self.bob.number_of_roles(), 1)

    def testSuitableForRole(self):
        self.bob.does_nothing()
        self.bob.add_roles('S P T P')
        self.assertTrue(self.bob.suitable_for_role('P'))
        self.assertTrue(self.bob.suitable_for_role('S'))
        self.assertTrue(self.bob.suitable_for_role('T'))
        self.bob.remove_role('P')
        self.assertFalse(self.bob.suitable_for_role('P'))
        self.assertTrue(self.bob.suitable_for_role('S'))
        self.assertTrue(self.bob.suitable_for_role('T'))
        self.bob.remove_role('S')
        self.assertFalse(self.bob.suitable_for_role('P'))
        self.assertFalse(self.bob.suitable_for_role('S'))
        self.assertTrue(self.bob.suitable_for_role('T'))