Esempio n. 1
0
    def _loadInRolesTables(self):
        _c = self._connection.cursor()
        GlobalRoleList.clear()
        for row in _c.execute('SELECT * FROM Roles ORDER BY priority'):
            GlobalRoleList.add_role(Role(row[0], row[2], row[1]))

        for row in _c.execute('SELECT * FROM RolesCompatibility'):
            role1 = GlobalRoleList.role_from_desc(row[0])
            role2 = GlobalRoleList.role_from_desc(row[1])
            role1.compatibilities.add(role2)
    def testloadRoles(self):
        self.assertGreater(len(GlobalRoleList.roles), 0, 'The roles have not been defined')

        self.saver.createTables()
        self.saver.populateTables()

        GlobalRoleList.clear()
        self.assertEqual(len(GlobalRoleList.roles), 0)

        self.saver.loadRoles()

        self.assertGreater(len(GlobalRoleList.roles), 0, 'The roles have not been repopulated')

        role1 = GlobalRoleList.role_from_desc('Baker')
        role2 = GlobalRoleList.role_from_desc('Fisherman')
        self.assertFalse(role1.compatible_with(role2))
Esempio n. 3
0
    def _loadInPopulationTables(self):
        _c = self._connection.cursor()
        self._institution.people = []
        personCacheDict = {'Name': 'PersonObject'}
        for row in _c.execute('SELECT * FROM Population ORDER BY name'):
            p = Worker()
            p.name = row[0]
            p.address = row[1]
            p.email = row[2]
            p.phoneNumber = row[3]
            self._institution.people.append(p)
            personCacheDict[p.name] = p

        for row in _c.execute('SELECT * FROM PopulationAvailability'):
            personCacheDict[row[0]].blacklist_date(row[1])

        for row in _c.execute('SELECT * FROM PopulationQualifications'):
            r = GlobalRoleList.role_from_desc(row[1])
            personCacheDict[row[0]].roles().add(r)

        self._personCacheDict = personCacheDict
    def testloadRolesCompatibilities(self):
        self.assertGreater(len(GlobalRoleList.roles), 0, 'The roles have not been defined')

        role1 = GlobalRoleList.role_from_desc('Steward')
        role2 = GlobalRoleList.role_from_desc('Cook')
        role1.compatibilities.add(role2)
        role2.compatibilities.add(role1)

        role1 = GlobalRoleList.role_from_desc('Baker')
        role2 = GlobalRoleList.role_from_desc('Fisherman')
        role1.compatibilities.add(role2)
        role2.compatibilities.add(role1)

        self.saver.createTables()
        self.saver.populateTables()
        GlobalRoleList.clear()
        self.saver.loadRoles()

        role1 = GlobalRoleList.role_from_desc('Baker')
        role2 = GlobalRoleList.role_from_desc('Fisherman')
        self.assertTrue(role1.compatible_with(role2))

        role1 = GlobalRoleList.role_from_desc('Fisherman')
        role2 = GlobalRoleList.role_from_desc('Steward')
        self.assertFalse(role1.compatible_with(role2))

        role1 = GlobalRoleList.role_from_desc('Baker')
        role2 = GlobalRoleList.role_from_desc('Cook')
        self.assertFalse(role1.compatible_with(role2))

        role1 = GlobalRoleList.role_from_desc('Steward')
        role2 = GlobalRoleList.role_from_desc('Cook')
        self.assertTrue(role1.compatible_with(role2))