本文整理匯總了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)