4 from django
.urls
import resolve
5 from django
.contrib
.auth
.models
import AnonymousUser
6 from django
.test
.client
import RequestFactory
7 from django
.contrib
.auth
import get_user_model
9 from mygpo
.utils
import random_token
12 def create_auth_string(username
, password
):
13 pwdstr
= '{0}:{1}'.format(username
, password
).rstrip()
14 credentials
= base64
.b64encode(pwdstr
.encode('utf-8'))
15 auth_string
= 'Basic ' + credentials
.decode('ascii')
19 def anon_request(url
):
20 """ Emulates an anonymous request, returns the response
23 factory
= RequestFactory()
24 request
= factory
.get(url
)
25 request
.user
= AnonymousUser()
28 response
= view
.func(request
, *view
.args
, **view
.kwargs
)
33 """ Create a user with random data """
34 User
= get_user_model()
35 password
= random_token(10)
36 username
= random_token(8)
37 user
= User(username
=username
, email
=username
+ '@example.com')
38 user
.set_password(password
)