Ejemplo n.º 1
0
    def test_saving_and_retrieving_perm_combination(self):
        report_type = ReportType(name='first_report_type')
        report_type.save()

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

        perm_comb = ReportPermissionCombination(
            name = 'first_perm_comb',
            description = 'first perm comb',
        )
        perm_comb.save()
        perm_comb.report_permissions = [first_perm, second_perm]
        perm_comb.save()

        saved_perm_comb = ReportPermissionCombination.objects.get(
            name='first_perm_comb')
        self.assertEqual(saved_perm_comb, perm_comb)
        self.assertEqual(
            len(saved_perm_comb.report_permissions.all()),
            len(perm_comb.report_permissions.all())
        )
        sort_key_function = lambda x:x.id
        self.assertEqual(
            sorted(saved_perm_comb.report_permissions.all(),
                key=sort_key_function),
            sorted(perm_comb.report_permissions.all(),
                key=sort_key_function)
        )
Ejemplo n.º 2
0
    def test_saving_and_retrieving_role_perm_relation(self):
        first_perm = ReportPermission(
            name = 'first-perm',
            description = 'first perm',
            db_conf = 'default',
            SQL_conf = """
                SELECT count(*) FROM tablename
            """,
            filter_conf = '{}',
        )
        first_perm.save()

        perm_comb = ReportPermissionCombination(
            name = 'first_perm_comb',
            description = 'first perm comb',
        )
        perm_comb.save()
        perm_comb.report_permissions = [first_perm,]
        perm_comb.save()

        first_role = SGRSRole(
            name = 'first_role',
            description = 'first role for test',
            can_download = True,
        )
        first_role.save()
        first_role.report_permissions = [first_perm,]
        first_role.report_permission_combinations = [perm_comb,]
        first_role.save()

        saved_role = SGRSRole.objects.get(name='first_role')
        self.assertEqual(
            saved_role.report_permissions,
            first_role.report_permissions
        )
        self.assertEqual(len(saved_role.report_permissions.all()), 1)
        self.assertEqual(
            saved_role.report_permission_combinations,
            first_role.report_permission_combinations
        )
        self.assertEqual(
            len(saved_role.report_permission_combinations.all()), 1)
Ejemplo n.º 3
0
    def test_function_get_all_report_combination_permissions(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()

        perm_comb = ReportPermissionCombination(
            name = 'first_perm_comb',
            description = 'first perm comb',
        )
        perm_comb.save()
        perm_comb.report_permissions = [first_perm, second_perm]
        perm_comb.save()

        first_role.report_permission_combinations = [perm_comb,]
        first_role.save()

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

        sort_key_function = lambda x:x.id
        self.assertEqual(
            sorted(ReportPermissionCombination.objects.filter(
                    sgrsrole__in=[first_role, ]),
                key=sort_key_function),
            sorted(first_user.get_all_report_combination_permissions(),
                key=sort_key_function)
        )