Exemple #1
0
    def testNoProfileAccessDenied(self):
        """Tests that error is raised if profile does not exist."""
        self.data._profile = None

        access_checker = access.IsUserOrgAdminForUrlOrg()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.FORBIDDEN)
        self.assertEqual(context.exception.message, access._MESSAGE_NO_PROFILE)
Exemple #2
0
    def testOrgAdminAccessGranted(self):
        """Tests that an organization administrator is granted access."""
        profile_properties = {
            'is_org_admin': True,
            'org_admin_for': [self.organization.key()],
            'is_mentor': True,
            'mentor_for': [self.organization.key()],
            'is_student': False,
        }
        self.data._profile = seeder_logic.seed(profile_model.Profile,
                                               properties=profile_properties)
        self.data._url_org = self.organization

        access_checker = access.IsUserOrgAdminForUrlOrg()
        access_checker.checkAccess(self.data, None)
Exemple #3
0
    def testStudentAccessDenied(self):
        """Tests that a student is denied access."""
        profile_properties = {
            'is_org_admin': False,
            'org_admin_for': [],
            'is_mentor': False,
            'mentor_for': [],
            'is_student': True,
        }
        self.data._profile = seeder_logic.seed(profile_model.Profile,
                                               properties=profile_properties)
        self.data._url_org = self.organization

        access_checker = access.IsUserOrgAdminForUrlOrg()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.FORBIDDEN)
Exemple #4
0
    def testForNonExistingOrg(self):
        """Tests that error is raised when organization does not exist."""
        profile_properties = {
            'is_org_admin': True,
            'org_admin_for': [self.organization.key()],
            'is_mentor': True,
            'mentor_for': [self.organization.key()],
            'is_student': False,
        }
        self.data._profile = seeder_logic.seed(profile_model.Profile,
                                               properties=profile_properties)

        self.data.kwargs['organization'] = 'non_existing_org_id'

        access_checker = access.IsUserOrgAdminForUrlOrg()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.NOT_FOUND)