當前位置: 首頁>>代碼示例>>Python>>正文


Python authentication.BasicAuthentication方法代碼示例

本文整理匯總了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 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:23,代碼來源:authentication.py

示例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) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:28,代碼來源:test_connect_viewset.py


注:本文中的rest_framework.authentication.BasicAuthentication方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。