Example #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)
        )
Example #2
0
    def test_saving_and_retrieving_reportpermission(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()

        saved_report_type = ReportType.objects.first()
        self.assertEqual(saved_report_type, report_type)

        saved_report_perms = ReportPermission.objects.all().order_by('id')
        self.assertEqual(saved_report_perms.count(), 2)

        first_saved_report_perm = saved_report_perms[0]
        second_saved_report_perm = saved_report_perms[1]
        self.assertEqual(first_saved_report_perm, first_perm)
        self.assertEqual(first_saved_report_perm.report_type, report_type)
        self.assertEqual(second_saved_report_perm, second_perm)
        self.assertEqual(second_saved_report_perm.report_type, report_type)