|
1
|
|
|
''' |
|
2
|
|
|
Helpers for the test suite that deal with users. |
|
3
|
|
|
''' |
|
4
|
|
|
|
|
5
|
|
|
from django.contrib.auth.hashers import make_password |
|
6
|
|
|
from django.contrib.auth.models import User |
|
7
|
|
|
|
|
8
|
|
|
from opensubmit.models import UserProfile |
|
9
|
|
|
from opensubmit.tests import uccrap |
|
10
|
|
|
|
|
11
|
|
|
admin_dict = { |
|
12
|
|
|
'username': uccrap + 'testrunner_admin', |
|
13
|
|
|
'password': uccrap + 'PNZabhExaL6H', |
|
14
|
|
|
'email': uccrap + '[email protected]', |
|
15
|
|
|
'is_staff': True, |
|
16
|
|
|
'is_superuser': True |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
teacher_dict = { |
|
20
|
|
|
'username': uccrap + 'testrunner_teacher', |
|
21
|
|
|
'password': uccrap + '2tVvWzdknP56', |
|
22
|
|
|
'email': uccrap + '[email protected]', |
|
23
|
|
|
'is_staff': True, |
|
24
|
|
|
'is_superuser': False |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
another_teacher_dict = { |
|
28
|
|
|
'username': uccrap + 'testrunner_anotherTeacher', |
|
29
|
|
|
'password': uccrap + 'LW8vhgQWz5kT', |
|
30
|
|
|
'email': uccrap + '[email protected]', |
|
31
|
|
|
'is_staff': True, |
|
32
|
|
|
'is_superuser': False |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
tutor_dict = { |
|
36
|
|
|
'username': uccrap + 'testrunner_tutor', |
|
37
|
|
|
'password': uccrap + '2tVP56vMadkn', |
|
38
|
|
|
'email': uccrap + '[email protected]', |
|
39
|
|
|
'is_staff': True, |
|
40
|
|
|
'is_superuser': False |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def get_student_dict(index): |
|
45
|
|
|
return { |
|
46
|
|
|
'username': uccrap + 'testrunner_enrolled_student{}'.format(index), |
|
47
|
|
|
'password': uccrap + 'very{}secret'.format(index), |
|
48
|
|
|
'email': uccrap + |
|
49
|
|
|
'testrunner_enrolled_student{}@django.localhost.local'.format(index), |
|
50
|
|
|
'is_staff': False, |
|
51
|
|
|
'is_superuser': False, |
|
52
|
|
|
'first_name': uccrap + 'Harold', |
|
53
|
|
|
'last_name': uccrap + 'Finch' |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
class AnonStruct(object): |
|
58
|
|
|
def __init__(self, entries): |
|
59
|
|
|
self.__dict__.update(entries) |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
def create_user(user_dict): |
|
63
|
|
|
args = dict(user_dict) |
|
64
|
|
|
args['password'] = make_password(args['password']) |
|
65
|
|
|
user_obj = User(**args) |
|
66
|
|
|
user_obj.save() |
|
67
|
|
|
|
|
68
|
|
|
UserProfile.objects.get_or_create(user=user_obj) |
|
69
|
|
|
return user_obj |
|
70
|
|
|
|