This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 681
/
__init__.py
66 lines (46 loc) · 1.78 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from nose.tools import ok_
from django.contrib.auth import get_user_model
from django.utils.crypto import get_random_string
from allauth.account.models import EmailAddress
from kuma.core.tests import KumaTestCase, KumaTransactionTestCase
from ..models import UserProfile
class UserTestMixin(object):
"""Base TestCase for the users app test cases."""
fixtures = ['test_users.json']
def setUp(self):
super(UserTestMixin, self).setUp()
self.user_model = get_user_model()
class UserTestCase(UserTestMixin, KumaTestCase):
pass
class UserTransactionTestCase(UserTestMixin, KumaTransactionTestCase):
pass
def profile(user, **kwargs):
"""Return a saved profile for a given user."""
return UserProfile.objects.get(user=user)
def user(save=False, **kwargs):
if 'username' not in kwargs:
kwargs['username'] = get_random_string(length=15)
password = kwargs.pop('password', 'password')
user = get_user_model()(**kwargs)
user.set_password(password)
if save:
user.save()
return user
def email(save=False, **kwargs):
if 'user' not in kwargs:
kwargs['user'] = user(save=True)
if 'email' not in kwargs:
kwargs['email'] = '%s@%s.com' % (get_random_string(),
get_random_string())
email = EmailAddress(**kwargs)
if save:
email.save()
return email
def verify_strings_in_response(test_strings, response):
for test_string in test_strings:
ok_(test_string in response.content,
msg="Expected '%s' in content." % test_string)
def verify_strings_not_in_response(test_strings, response):
for test_string in test_strings:
ok_(test_string not in response.content,
msg="Found unexpected '%s' in content." % test_string)