Python rest_framework.authentication.BasicAuthentication() Examples
The following are 2
code examples of rest_framework.authentication.BasicAuthentication().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.authentication
, or try the search function
.
Example #1
Source File: authentication.py From py2swagger with MIT License | 6 votes |
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
Example #2
Source File: test_connect_viewset.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
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)