[Podcasts] make Episode.duration a BigInteger
[mygpo.git] / mygpo / test.py
blob692260a2361aa74b1c9d3e5e8fa2098d29af8b6c
1 import os.path
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):
12 import base64
13 credentials = base64.encodestring("%s:%s" % (username, password)).rstrip()
14 auth_string = 'Basic %s' % credentials
15 return auth_string
18 def anon_request(url):
19 """ Emulates an anonymous request, returns the response
21 """
22 factory = RequestFactory()
23 request = factory.get(url)
24 request.user = AnonymousUser()
25 view = resolve(url)
27 response = view.func(request, *view.args, **view.kwargs)
28 return response
31 def create_user():
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)
38 user.is_active = True
39 user.save()
40 return user, password