- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在单元测试中使用我的 Django Rest Framework API 进行身份验证时遇到问题。通过浏览器访问时,系统按预期工作。但是,在以下端点向以下类发送放置请求时,我收到 401 HTTP 状态:
class UserDetail(RetrieveModelMixin, DestroyModelMixin, UpdateModelMixin, GenericViewSet):
authentication_classes = (BasicAuthentication, TokenAuthentication)
permission_classes = IsAuthenticated,
queryset = CustomUser.objects.all()
serializer_class = UserSerializer
class AccountTests(APITestCase):
def setUp(self):
self.user = CustomUser.objects.create_user(email="user1@test.com", password="password1", is_staff=True)
self.user.save()
self.user = CustomUser.objects.get(email="user1@test.com")
self.client = APIClient()
def test_add_name(self):
self.client.login(email="user1@test.com", password='password1')
url = reverse('customuser-detail', args=(self.user.id,))
data = {'first_name': 'test', 'last_name': 'user'}
self.client.login(email="user1@test.com", password='password1')
response = self.client.put(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
{u'detail': u'Authentication credentials were not provided.'}
最佳答案
一、{u'detail': u'Authentication credentials were not provided.'}
当您“提供”的凭证与模型不匹配时发生。 (我认为这是错误的错误信息)
因此,您应该通过 set_password()
设置用户密码方法,因为加密。
self.user = CustomUser.objects.create_user(email="user1@test.com", is_staff=True)
self.user.set_password("password1")
self.user.save()
force_login()
用于检测。
self.client.force_login(
user=User.objects.first(),
backend='django.contrib.auth.backends.ModelBackend' # one of your AUTHENTICATION_BACKENDS
)
关于Django APIClient 登录不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37513050/
我在单元测试中使用我的 Django Rest Framework API 进行身份验证时遇到问题。通过浏览器访问时,系统按预期工作。但是,在以下端点向以下类发送放置请求时,我收到 401 HTTP
当我尝试使用 JS FB.api([...] 执行操作时,我得到 No callback passed to the ApiClient [...]我在哪里可以设置这个回调? 最佳答案 只需在 API
我不久前制作了这个页面,但我回来后发现很多标签已经贬值了。谁能给我一些关于用什么来代替它们的帮助?我希望情况并非如此,但我希望现在标签需要更改,其余代码将毫无用处。 这里是未使用的标签列表(在 and
我正在为帖 subview 编写测试。它确实有效,但是当我尝试使用 APIClient.post 发布到它时,我得到 QueryDict: {}。这是测试: class SMSCreateData(A
我有以下代码 setCOnfig([ 'apiKey' => 'YOUR_API_KEY', 'server' => 'YOUR_SERVER_PREF
我想知道请求是否实际上是通过 http 发出的。在我的应用程序中,我有一个看起来像的测试 class Authenticate(APITestCase): def setUp(self):
作为测试新手,我希望在 Django (Django-rest-framework) 中测试我的 API。 我正在为我的 View 设置测试,即我的 API 端点。现在查看文档,我可以使用 APIRe
我有一个 API 端点,我想对其进行 PUT 调用,该调用需要正文和查询参数。我使用 Django 的测试客户端在测试用例 ( docs ) 中调用我的端点。 我在文档中读到,对于 GET 调用,查询
我正在尝试在我的 iOS 应用程序中使用 TwitterKit 框架(在 Swift 中)。但是,当我使用 Twitter.sharedInstance().APIClient 时,会出现错误,提示“
我正在测试应该在 Django 模型中引发 ValidationError 的 API 端点(请注意,异常是 Django 异常,而不是 DRF,因为它在模型中)。 from rest_framewo
我已经安装了 Visual Studio 2015 Community 和 Visual Studio 的 Python 工具。但我无法让 Intellisense 识别我通过 pip install
我使用 APIClient() 进行测试。我使用 Token 认证,所以我需要使用 THIS 如果我们深入研究源代码,我们将看到接下来的内容: # rest_framework/test.py cla
我已经为 Docker ApiClient 实现了一个包装器像这样 type DockerClient struct { cli client.APIClient } 我还定义了我自己的接口(
我已经读过:Django REST Framework - Set request in serializer test? 。而且这对我不起作用!因为我使用的是 APIClient 而不是像他那样使用
我已经读过:Django REST Framework - Set request in serializer test? 。而且这对我不起作用!因为我使用的是 APIClient 而不是像他那样使用
我关注了these instructions在我的后端服务器上使用 Android 登录。 Android 登录有效,我得到一个带有我的服务器客户端 ID 的 ID token : // Config
我将 python 用于我的服务器 Google App Engine API 代码和我的客户端。我已经有很多客户端-服务器 GET 请求在工作,现在是 POST 请求的时候了,我被卡住了。我的相关客
我正在尝试使用来自发布请求的序列化程序创建对象,但在尝试将对象列表传递给嵌套序列化程序时出现错误。在以 JSON 格式传递 ('id', 'name', 'description') 数据时,bars
使用 ApacheAPIClientBuilder 创建的 APIClient 时,APIClient 是线程安全的,还是应该为每个线程创建一个新的 APIClient? 最佳答案 APIClient
我在我的应用程序中使用这种记录到服务器的机制:将用户凭据发布到服务器,如果成功,它会返回给我签署我 future 的 API 调用所需的 token 。问题是如何在我的应用程序的所有类之间共享此 to
我是一名优秀的程序员,十分优秀!