3 from django
.core
.urlresolvers
import resolve
4 from django
.contrib
.auth
.models
import AnonymousUser
5 from django
.test
.client
import RequestFactory
6 from django
.contrib
.auth
import get_user_model
8 from mygpo
.utils
import random_token
11 def create_auth_string(username
, password
):
13 credentials
= base64
.encodestring("%s:%s" % (username
, password
)).rstrip()
14 auth_string
= 'Basic %s' % credentials
18 def anon_request(url
):
19 """ Emulates an anonymous request, returns the response
22 factory
= RequestFactory()
23 request
= factory
.get(url
)
24 request
.user
= AnonymousUser()
27 response
= view
.func(request
, *view
.args
, **view
.kwargs
)
32 """ Create a user with random data """
33 User
= get_user_model()
34 password
= random_token(10)
35 username
= random_token(8)
36 user
= User(username
=username
, email
=username
+ '@example.com')
37 user
.set_password(password
)