def setUp(self, *args, **kwargs):
        super(UserPermissionsTestCase, self).setUp(*args, **kwargs)

        self.user = MojUser(5, generate_tokens(), {
            'first_name': 'Sam',
            'last_name': 'Hall',
            'permissions': [
                'allowed_permission_1',
                'allowed_permission_2',
                'allowed_permission_3'
            ]
        })
class UserPermissionsTestCase(SimpleTestCase):

    def setUp(self, *args, **kwargs):
        super(UserPermissionsTestCase, self).setUp(*args, **kwargs)

        self.user = MojUser(5, generate_tokens(), {
            'first_name': 'Sam',
            'last_name': 'Hall',
            'permissions': [
                'allowed_permission_1',
                'allowed_permission_2',
                'allowed_permission_3'
            ]
        })

    def test_has_perm_succeeds_if_present(self):
        self.assertTrue(self.user.has_perm('allowed_permission_1'))

    def test_has_perm_fails_if_absent(self):
        self.assertFalse(self.user.has_perm('forbidden_permission'))

    def test_has_perms_succeeds_if_all_present(self):
        self.assertTrue(self.user.has_perms([
            'allowed_permission_1',
            'allowed_permission_2'
        ]))

    def test_has_perms_fails_if_any_absent(self):
        self.assertFalse(self.user.has_perms([
            'allowed_permission_1',
            'forbidden_permission'
        ]))

    def test_no_permissions_fails_gracefully(self):
        user = MojUser(6, generate_tokens(), {
            'first_name': 'Sam',
            'last_name': 'Halle',
        })

        user.get_all_permissions()
        self.assertFalse(user.has_perm('forbidden_permission'))
        self.assertFalse(user.has_perms([
            'allowed_permission_1',
            'forbidden_permission'
        ]))
Exemplo n.º 3
0
 def get_api_session(self, **kwargs):
     request = self.factory.get(
         reverse('bank_admin:download_bank_statement'), **kwargs)
     request.user = MojUser(1, '', {
         'first_name': 'John',
         'last_name': 'Smith',
         'username': '******'
     })
     request.session = mock.MagicMock()
     return get_api_session(request)
    def test_no_permissions_fails_gracefully(self):
        user = MojUser(6, generate_tokens(), {
            'first_name': 'Sam',
            'last_name': 'Halle',
        })

        user.get_all_permissions()
        self.assertFalse(user.has_perm('forbidden_permission'))
        self.assertFalse(user.has_perms([
            'allowed_permission_1',
            'forbidden_permission'
        ]))
Exemplo n.º 5
0
 def get_user(self):
     return MojUser(1, '', {
         'first_name': 'John',
         'last_name': 'Smith',
         'username': '******'
     })