Esempio n. 1
0
    def test_add_group_with_callable(self):
        def codenames_callable():
            return [
                "edc_auth.add_subjectrequisition",
                "edc_auth.change_subjectrequisition",
                "edc_auth.delete_subjectrequisition",
                "edc_auth.view_subjectrequisition",
            ]

        codenames = [
            "edc_auth.add_testmodel",
            "edc_auth.change_testmodel",
            "edc_auth.delete_testmodel",
            "edc_auth.view_testmodel",
        ]
        codenames_with_callable = copy(codenames)
        codenames_with_callable.append(codenames_callable)
        site_auths.clear()
        site_auths.add_group(*codenames_with_callable, name="GROUP")
        AuthUpdater()
        group = Group.objects.get(name="GROUP")

        codenames.extend(codenames_callable())
        codenames.sort()
        self.assertEqual(
            [
                p.codename for p in group.permissions.filter(
                    content_type__app_label="edc_auth").order_by("codename")
            ],
            [c.split(".")[1] for c in codenames],
        )
Esempio n. 2
0
    def test_add_group_convert_to_export_with_callable(self):
        def more_codenames():
            return [
                "edc_auth.add_subjectrequisition",
                "edc_auth.change_subjectrequisition",
                "edc_auth.delete_subjectrequisition",
                "edc_auth.view_subjectrequisition",
            ]

        codenames = [
            "edc_auth.add_testmodel",
            "edc_auth.change_testmodel",
            "edc_auth.delete_testmodel",
            "edc_auth.view_testmodel",
            more_codenames,
        ]
        site_auths.clear()
        site_auths.add_group(*codenames,
                             name="GROUP_EXPORT",
                             convert_to_export=True)
        AuthUpdater()
        group = Group.objects.get(name="GROUP_EXPORT")
        self.assertEqual(
            [
                p.codename for p in group.permissions.filter(
                    content_type__app_label="edc_auth")
            ],
            ["export_subjectrequisition", "export_testmodel"],
        )
 def setUpTestData(cls):
     url_names.register("dashboard_url", "dashboard_url", "edc_dashboard")
     site_auths.clear()
     site_auths.add_group("edc_dashboard.view_my_listboard", name=CLINIC)
     site_auths.add_custom_permissions_tuples(
         model="edc_dashboard.dashboard",
         codename_tuples=(("edc_dashboard.view_my_listboard",
                           "View my listboard"), ),
     )
     AuthUpdater(verbose=False, warn_only=True)
     return super().setUpTestData()
Esempio n. 4
0
 def test_add_group(self):
     codenames = [
         "edc_auth.add_testmodel",
         "edc_auth.change_testmodel",
         "edc_auth.delete_testmodel",
         "edc_auth.view_testmodel",
     ]
     site_auths.clear()
     site_auths.add_group(*codenames, name="GROUP")
     AuthUpdater()
     group = Group.objects.get(name="GROUP")
     self.assertEqual(
         [
             p.codename for p in group.permissions.filter(
                 content_type__app_label="edc_auth")
         ],
         [c.split(".")[1] for c in codenames],
     )
Esempio n. 5
0
 def test_add_group_view_only(self):
     codenames = [
         "edc_auth.add_testmodel",
         "edc_auth.change_testmodel",
         "edc_auth.delete_testmodel",
         "edc_auth.view_testmodel",
     ]
     site_auths.clear()
     site_auths.add_group(*codenames,
                          name="GROUP_VIEW_ONLY",
                          view_only=True)
     AuthUpdater()
     group = Group.objects.get(name="GROUP_VIEW_ONLY")
     self.assertEqual(
         [
             p.codename for p in group.permissions.filter(
                 content_type__app_label="edc_auth")
         ],
         ["view_testmodel"],
     )
Esempio n. 6
0
    def test_add_group_remove_delete_with_callable(self):
        def more_codenames():
            return [
                "edc_auth.add_subjectrequisition",
                "edc_auth.change_subjectrequisition",
                "edc_auth.delete_subjectrequisition",
                "edc_auth.view_subjectrequisition",
            ]

        codenames = [
            "edc_auth.add_testmodel",
            "edc_auth.change_testmodel",
            "edc_auth.delete_testmodel",
            "edc_auth.view_testmodel",
            more_codenames,
        ]
        site_auths.clear()
        site_auths.add_group(*codenames,
                             name="GROUP_NO_DELETE",
                             no_delete=True)
        AuthUpdater()
        group = Group.objects.get(name="GROUP_NO_DELETE")

        codenames = [
            "add_subjectrequisition",
            "add_testmodel",
            "change_subjectrequisition",
            "change_testmodel",
            "view_subjectrequisition",
            "view_testmodel",
        ]
        self.assertEqual(
            [
                p.codename for p in group.permissions.filter(
                    content_type__app_label="edc_auth").order_by("codename")
            ],
            codenames,
        )
Esempio n. 7
0
 def test_load(self):
     site_auths.clear()
     import_module("edc_appointment.auths")
     AuthUpdater(verbose=True)