root / snf-astakos-app / astakos / im / tests / views.py @ 3d08cdca
History | View | Annotate | Download (4.5 kB)
1 |
# Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
import astakos.im.messages as astakos_messages |
35 |
|
36 |
from astakos.im.models import ApprovalTerms |
37 |
from astakos.im.tests.common import * |
38 |
|
39 |
from django.core import urlresolvers |
40 |
from django.utils.translation import ugettext as _ |
41 |
|
42 |
import os |
43 |
|
44 |
|
45 |
class TestViews(TestCase): |
46 |
|
47 |
def test_user_views(self): |
48 |
user = get_local_user('user@synnefo.org')
|
49 |
r = self.client.get(reverse('api_access'), follow=True) |
50 |
self.assertRedirects(r, reverse_with_next('api_access')) |
51 |
|
52 |
self.client.login(username='user@synnefo.org', password='password') |
53 |
r = self.client.get(reverse('api_access'), follow=True) |
54 |
self.assertEqual(r.status_code, 200) |
55 |
|
56 |
r = self.client.get(reverse('api_access_config')) |
57 |
self.assertContains(r, user.auth_token)
|
58 |
|
59 |
|
60 |
class TestApprovalTerms(TestCase): |
61 |
def tearDown(self): |
62 |
os.remove('terms')
|
63 |
|
64 |
ApprovalTerms.objects.get(location='terms').delete()
|
65 |
|
66 |
def test_approval_terms(self): |
67 |
r = self.client.get(reverse('latest_terms'), follow=True) |
68 |
self.assertEqual(r.status_code, 200) |
69 |
self.assertContains(r, _(astakos_messages.NO_APPROVAL_TERMS))
|
70 |
|
71 |
r = self.client.post(reverse('latest_terms'), follow=True) |
72 |
self.assertEqual(r.status_code, 200) |
73 |
self.assertContains(r, _(astakos_messages.NO_APPROVAL_TERMS))
|
74 |
|
75 |
# add terms
|
76 |
f = open('terms', 'w+') |
77 |
f.write('This are some terms')
|
78 |
f.close() |
79 |
|
80 |
terms = ApprovalTerms(location='terms')
|
81 |
terms.save() |
82 |
|
83 |
self.user = get_local_user('user@synnefo.org') |
84 |
self.assertTrue(not self.user.signed_terms) |
85 |
self.assertTrue(self.user.date_signed_terms is None) |
86 |
self.user_client = get_user_client(self.user.username) |
87 |
|
88 |
r = self.client.get(reverse('latest_terms')) |
89 |
self.assertEqual(r.status_code, 200) |
90 |
self.assertTemplateUsed(r, 'im/approval_terms.html') |
91 |
# assert there is no form
|
92 |
self.assertNotContains(r, 'I agree with the terms') |
93 |
|
94 |
r = self.client.post(reverse('latest_terms'), follow=False) |
95 |
self.assertEqual(r.status_code, 302) |
96 |
# assert redirect to login
|
97 |
self.assertTrue('Location' in r) |
98 |
self.assertTrue(r['Location'].find(reverse('login')) != -1) |
99 |
|
100 |
r = self.user_client.get(reverse('latest_terms'), follow=True) |
101 |
self.assertEqual(r.status_code, 200) |
102 |
self.assertTemplateUsed(r, 'im/approval_terms.html') |
103 |
# assert there is form
|
104 |
self.assertContains(r, 'I agree with the terms') |
105 |
|
106 |
r = self.user_client.post(reverse('latest_terms'), follow=True) |
107 |
self.assertEqual(r.status_code, 200) |
108 |
self.assertFormError(r, 'approval_terms_form', 'has_signed_terms', |
109 |
_(astakos_messages.SIGN_TERMS)) |
110 |
|
111 |
r = self.user_client.post(reverse('latest_terms'), |
112 |
{'has_signed_terms': True}, |
113 |
follow=True)
|
114 |
self.assertEqual(r.status_code, 200) |
115 |
|
116 |
user = AstakosUser.objects.get(username=self.user.username)
|
117 |
self.assertTrue(user.signed_terms)
|