本文整理汇总了Python中rest_framework.authentication.BasicAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Python authentication.BasicAuthentication方法的具体用法?Python authentication.BasicAuthentication怎么用?Python authentication.BasicAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.authentication
的用法示例。
在下文中一共展示了authentication.BasicAuthentication方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_authentication_introspectors
# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import BasicAuthentication [as 别名]
def get_authentication_introspectors(view):
"""
Get View Authentication Introspectors
:param view: DjangoRestFramework View
:return: list of authentication introspectors
:rtype: list
"""
from rest_framework import authentication
authenticators_map = {
authentication.BasicAuthentication: BasicAuthenticationIntrospector,
authentication.TokenAuthentication: TokenAuthenticationIntrospector,
}
authenticators = getattr(view, 'authentication_classes', [])
introspectors = []
for authenticator in authenticators:
introspectors.append(
authenticators_map.get(authenticator, BaseAuthenticationIntrospector)(authenticator)
)
return introspectors
示例2: test_user_list_with_basic_and_digest
# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import BasicAuthentication [as 别名]
def test_user_list_with_basic_and_digest(self):
view = ConnectViewSet.as_view(
{'get': 'list'},
authentication_classes=(
DigestAuthentication,
authentication.BasicAuthentication
))
request = self.factory.get('/')
auth = BasicAuth('bob', 'bob')
request.META.update(auth(request.META))
request.session = self.client.session
response = view(request)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.data['detail'],
u"Invalid username/password.")
auth = BasicAuth('bob', 'bobbob')
# redo the request
request = self.factory.get('/')
request.META.update(auth(request.META))
request.session = self.client.session
response = view(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, self.data)