forked from benadida/helios-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
120 lines (86 loc) · 4.5 KB
/
tests.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
Unit Tests for Auth Systems
"""
import unittest
import models
from django.db import IntegrityError, transaction
from django.test.client import Client
from django.test import TestCase
from django.core import mail
from auth_systems import AUTH_SYSTEMS
class UserModelTests(unittest.TestCase):
def setUp(self):
pass
def test_unique_users(self):
"""
there should not be two users with the same user_type and user_id
"""
for auth_system, auth_system_module in AUTH_SYSTEMS.iteritems():
models.User.objects.create(user_type = auth_system, user_id = 'foobar', info={'name':'Foo Bar'})
def double_insert():
models.User.objects.create(user_type = auth_system, user_id = 'foobar', info={'name': 'Foo2 Bar'})
self.assertRaises(IntegrityError, double_insert)
transaction.rollback()
def test_create_or_update(self):
"""
shouldn't create two users, and should reset the password
"""
for auth_system, auth_system_module in AUTH_SYSTEMS.iteritems():
u = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_cou', info={'name':'Foo Bar'})
def double_update_or_create():
new_name = 'Foo2 Bar'
u2 = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_cou', info={'name': new_name})
self.assertEquals(u.id, u2.id)
self.assertEquals(u2.info['name'], new_name)
def test_status_update(self):
"""
check that a user set up with status update ability reports it as such,
and otherwise does not report it
"""
for auth_system, auth_system_module in AUTH_SYSTEMS.iteritems():
u = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_status_update', info={'name':'Foo Bar Status Update'})
if hasattr(auth_system_module, 'send_message'):
self.assertNotEquals(u.update_status_template, None)
else:
self.assertEquals(u.update_status_template, None)
def test_eligibility(self):
"""
test that users are reported as eligible for something
FIXME: also test constraints on eligibility
"""
for auth_system, auth_system_module in AUTH_SYSTEMS.iteritems():
u = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_status_update', info={'name':'Foo Bar Status Update'})
self.assertTrue(u.is_eligible_for({'auth_system': auth_system}))
def test_eq(self):
for auth_system, auth_system_module in AUTH_SYSTEMS.iteritems():
u = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_eq', info={'name':'Foo Bar Status Update'})
u2 = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_eq', info={'name':'Foo Bar Status Update'})
self.assertEquals(u, u2)
import views
import auth_systems.password as password_views
from django.core.urlresolvers import reverse
# FIXME: login CSRF should make these tests more complicated
# and should be tested for
class UserBlackboxTests(TestCase):
def setUp(self):
# create a bogus user
self.test_user = models.User.objects.create(user_type='password',user_id='[email protected]',name="Foobar User", info={'password':'foobaz'})
def test_password_login(self):
## we can't test this anymore until it's election specific
pass
# get to the login page
# login_page_response = self.client.get(reverse(views.start, kwargs={'system_name':'password'}), follow=True)
# log in and follow all redirects
# response = self.client.post(reverse(password_views.password_login_view), {'username' : 'foobar_user', 'password': 'foobaz'}, follow=True)
# self.assertContains(response, "logged in as")
# self.assertContains(response, "Foobar User")
def test_logout(self):
response = self.client.post(reverse(views.logout), follow=True)
self.assertContains(response, "not logged in")
self.assertNotContains(response, "Foobar User")
def test_email(self):
"""using the test email backend"""
self.test_user.send_message("testing subject", "testing body")
self.assertEquals(len(mail.outbox), 1)
self.assertEquals(mail.outbox[0].subject, "testing subject")
self.assertEquals(mail.outbox[0].to[0], "Foobar User <[email protected]>")