Пример #1
0
class ExportPermissionsTest(SimpleTestCase):
    @classmethod
    def setUpClass(cls):
        super(ExportPermissionsTest, cls).setUpClass()
        cls.domain = 'export-permissions-test'
        cls.web_user = WebUser(username='******',
                               domains=[cls.domain])
        cls.web_user.domain_memberships = [
            DomainMembership(domain=cls.domain, role_id='MYROLE')
        ]
        cls.permissions = Permissions()

    def setUp(self):
        super(ExportPermissionsTest, self).setUp()
        test_self = self

        def get_role(self):
            return UserRole(domain=test_self.domain,
                            permissions=test_self.permissions)

        patches = [
            mock.patch.object(DomainMembership, 'role', property(get_role)),
            mock.patch.object(
                Memoized, '__call__',
                lambda self, *args, **kwargs: self.func(*args, **kwargs))
        ]
        for patch in patches:
            patch.start()
            self.addCleanup(patch.stop)

    def tearDown(self):
        self.permissions = Permissions()
        super(ExportPermissionsTest, self).tearDown()

    def test_deid_permission(self):
        self.assertFalse(user_can_view_deid_exports(self.domain,
                                                    self.web_user))
        self.permissions = Permissions(
            view_report_list=[DEID_EXPORT_PERMISSION])
        self.assertTrue(
            self.permissions.has(get_permission_name(Permissions.view_report),
                                 data=DEID_EXPORT_PERMISSION))
        self.assertTrue(
            self.web_user.has_permission(self.domain,
                                         get_permission_name(
                                             Permissions.view_report),
                                         data=DEID_EXPORT_PERMISSION))

        self.assertTrue(user_can_view_deid_exports(self.domain, self.web_user))

    def test_view_reports(self):
        self.assertFalse(self.web_user.can_view_reports(self.domain))
        self.permissions = Permissions(view_reports=True)
        self.assertTrue(self.web_user.can_view_reports(self.domain))
Пример #2
0
class ExportPermissionsTest(SimpleTestCase):

    @classmethod
    def setUpClass(cls):
        super(ExportPermissionsTest, cls).setUpClass()
        cls.domain = 'export-permissions-test'
        cls.web_user = WebUser(username='******', domains=[cls.domain])
        cls.web_user.domain_memberships = [DomainMembership(domain=cls.domain, role_id='MYROLE')]
        cls.permissions = Permissions()

    def setUp(self):
        super(ExportPermissionsTest, self).setUp()
        test_self = self

        def get_role(self):
            return UserRole(
                domain=test_self.domain,
                permissions=test_self.permissions
            )

        patches = [
            mock.patch.object(DomainMembership, 'role', property(get_role)),
            mock.patch.object(Memoized, '__call__',
                              lambda self, *args, **kwargs: self.func(*args, **kwargs))
        ]
        for patch in patches:
            patch.start()
            self.addCleanup(patch.stop)

    def tearDown(self):
        self.permissions = Permissions()
        super(ExportPermissionsTest, self).tearDown()

    def test_deid_permission(self):
        self.assertFalse(user_can_view_deid_exports(self.domain, self.web_user))
        self.permissions = Permissions(view_report_list=[DEID_EXPORT_PERMISSION])
        self.assertTrue(
            self.permissions.has(get_permission_name(Permissions.view_report),
                                 data=DEID_EXPORT_PERMISSION))
        self.assertTrue(
            self.web_user.has_permission(
                self.domain, get_permission_name(Permissions.view_report),
                data=DEID_EXPORT_PERMISSION)
        )

        self.assertTrue(user_can_view_deid_exports(self.domain, self.web_user))

    def test_view_reports(self):
        self.assertFalse(self.web_user.can_view_reports(self.domain))
        self.permissions = Permissions(view_reports=True)
        self.assertTrue(self.web_user.can_view_reports(self.domain))
Пример #3
0
class PermissionsHelpersTest(SimpleTestCase):
    @classmethod
    def setUpClass(cls):
        super(PermissionsHelpersTest, cls).setUpClass()
        cls.domain = 'export-permissions-test'
        cls.admin_domain = 'export-permissions-test-admin'
        cls.web_user = WebUser(username='******',
                               domains=[cls.domain, cls.admin_domain])
        cls.web_user.domain_memberships = [
            DomainMembership(domain=cls.domain, role_id='MYROLE'),
            DomainMembership(domain=cls.admin_domain, is_admin=True)
        ]
        cls.permissions = Permissions()

    def setUp(self):
        super(PermissionsHelpersTest, self).setUp()
        test_self = self

        def get_role(self, domain=None):
            return mock.Mock(domain=test_self.domain,
                             permissions=test_self.permissions,
                             spec=["domain", "permissions"])

        assert hasattr(WebUser.has_permission, "get_cache"), "not memoized?"
        patches = [
            mock.patch.object(DomainMembership, 'role', property(get_role)),
            mock.patch.object(WebUser, 'get_role', get_role),
            mock.patch.object(WebUser, 'has_permission',
                              WebUser.has_permission.__wrapped__),
        ]
        for patch in patches:
            patch.start()
            self.addCleanup(patch.stop)

    def tearDown(self):
        self.permissions = Permissions()
        super(PermissionsHelpersTest, self).tearDown()

    def test_deid_permission(self):
        self.assertFalse(user_can_view_deid_exports(self.domain,
                                                    self.web_user))
        self.permissions = Permissions(
            view_report_list=[DEID_EXPORT_PERMISSION])
        self.assertTrue(
            self.permissions.has(get_permission_name(Permissions.view_report),
                                 data=DEID_EXPORT_PERMISSION))
        self.assertTrue(
            self.web_user.has_permission(self.domain,
                                         get_permission_name(
                                             Permissions.view_report),
                                         data=DEID_EXPORT_PERMISSION))

        self.assertTrue(user_can_view_deid_exports(self.domain, self.web_user))

    def test_view_reports(self):
        self.assertFalse(self.web_user.can_view_reports(self.domain))
        self.permissions = Permissions(view_reports=True)
        self.assertTrue(self.web_user.can_view_reports(self.domain))

    def test_has_permission_to_view_report_all(self):
        self.assertFalse(
            has_permission_to_view_report(self.web_user, self.domain,
                                          ODATA_FEED_PERMISSION))
        self.permissions = Permissions(view_reports=True)
        self.assertTrue(
            has_permission_to_view_report(self.web_user, self.domain,
                                          ODATA_FEED_PERMISSION))

    def test_has_permission_to_view_report(self):
        self.assertFalse(
            has_permission_to_view_report(self.web_user, self.domain,
                                          ODATA_FEED_PERMISSION))
        self.permissions = Permissions(
            view_report_list=[ODATA_FEED_PERMISSION])
        self.assertTrue(
            has_permission_to_view_report(self.web_user, self.domain,
                                          ODATA_FEED_PERMISSION))