当前位置: 首页>>代码示例>>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;未经允许,请勿转载。