Esempio n. 1
0
    def test_function_has_report_perm(self):
        first_user = UserCreationForm(
            data = dict(
                username = '******',
                password1 = '123456',
                password2 = '123456',
            )
        ).save()

        first_role = SGRSRole(
            name = 'first_role',
            description = 'first role for test',
            can_download = True,
        )
        first_role.save()

        first_perm = ReportPermission(
            name = 'first-perm',
            description = 'first perm',
            db_conf = 'default',
            SQL_conf = """
                SELECT count(*) FROM tablename
            """,
            filter_conf = '{}',
        )
        first_perm.save()

        second_perm = ReportPermission(
            name = 'second-perm',
            description = 'second perm',
            db_conf = 'default',
            SQL_conf = """
                SELECT count(*) FROM tablename
            """,
            filter_conf = '{}',
        )
        second_perm.save()

        first_role.report_permissions = [first_perm,]
        first_role.save()

        first_user_assignment = SGRSUserAssignment(user = first_user)
        first_user_assignment.save()
        first_user_assignment.roles = [first_role, ]
        first_user_assignment.save()

        self.assertEqual(first_user.has_report_perm(first_perm), True)
        self.assertEqual(first_user.has_report_perm('first-perm'), True)
        self.assertEqual(first_user.has_report_perm(second_perm), False)
        self.assertEqual(first_user.has_report_perm('second-perm'), False)