コード例 #1
0
    def test_api_permission_user_granted_permission(self):
        user = UserFactory()
        permission = PermissionFactory(
            codename='can_deactivate_users',
            content_type=ContentTypeFactory(app_label='student'))
        user.user_permissions.add(permission)
        self.request.user = user

        result = CanDeactivateUser().has_permission(self.request, None)
        self.assertTrue(result)
コード例 #2
0
 def test_user_with_permission_deactivates_user(self):
     """
     Verify a user is deactivated when a user with permission posts to the deactivation endpoint.
     """
     user = UserFactory()
     permission = PermissionFactory(
         codename='can_deactivate_users',
         content_type=ContentTypeFactory(app_label='student'))
     user.user_permissions.add(permission)  # pylint: disable=no-member
     headers = self.build_jwt_headers(user)
     self.assertTrue(self.test_user.has_usable_password())  # pylint: disable=no-member
     self.assert_activation_status(headers)