Commit 4078466e69318660721e9f11e5f5850f0b248d9b
1 parent
6b16badb
Exists in
dev
Refactorisation tests user_manager
Showing
1 changed file
with
9 additions
and
48 deletions
Show diff stats
src/user_manager/tests.py
... | ... | @@ -2,43 +2,32 @@ from django.test import TestCase |
2 | 2 | from common.models import * |
3 | 3 | from django.contrib.auth.models import User |
4 | 4 | |
5 | -from pprint import pprint | |
5 | + | |
6 | 6 | |
7 | 7 | class UserManagerTests(TestCase): |
8 | 8 | |
9 | 9 | def setUp(self): |
10 | 10 | UserLevel.objects.create() |
11 | 11 | Country.objects.create() |
12 | - | |
13 | - def test_creation(self): | |
14 | - self.assertEqual(Country.objects.count(), 1, "There should be 1 Country") | |
15 | - self.assertEqual(UserLevel.objects.count(), 1, "There should be 1 UserLevel") | |
16 | 12 | self.assertEqual(PyrosUser.objects.count(), 0, "There should be no User") |
17 | - #print("country is", Country.objects.count()) | |
18 | - print("country id is", Country.objects.all()[0].id) | |
19 | 13 | path = "/user_manager/creation_validate" |
20 | 14 | response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", |
21 | 15 | "first_name": "toto", "last_name": "titi", "tel": "0123456789", |
22 | 16 | "laboratory": "IRAP", "address": "ici"}) |
23 | 17 | self.assertTrue("success" in response.context.keys(), "There should be a success") |
24 | - self.assertEqual(PyrosUser.objects.count(), 1, "There should be one User") | |
25 | - #self.assertEqual(PyrosUser.objects.count(), 1, "There should be one PyrosUser") | |
18 | + self.assertEqual(PyrosUser.objects.count(), 1, "Theroue shld be one User") | |
19 | + | |
20 | + def test_creation(self): | |
21 | + self.assertEqual(Country.objects.count(), 1, "There should be 1 Country") | |
22 | + self.assertEqual(UserLevel.objects.count(), 1, "There should be 1 UserLevel") | |
23 | + | |
26 | 24 | self.assertEqual(PyrosUser.objects.all()[0].first_name, 'toto') |
27 | 25 | self.assertEqual(PyrosUser.objects.all()[0].email, 'toto@titi.fr') |
28 | 26 | |
29 | 27 | def test_login(self): |
30 | 28 | self.assertEqual(Country.objects.count(), 1, "There should be 1 Country") |
31 | 29 | self.assertEqual(UserLevel.objects.count(), 1, "There should be 1 UserLevel") |
32 | - self.assertEqual(PyrosUser.objects.count(), 0, "There should be no User") | |
33 | - | |
34 | - # Create user | |
35 | - path = "/user_manager/creation_validate" | |
36 | - response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
37 | - "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
38 | - "laboratory": "IRAP", "address": "ici"}) | |
39 | - self.assertTrue("success" in response.context.keys(), "There should be a success") | |
40 | - self.assertEqual(PyrosUser.objects.count(), 1, "There should be one User") | |
41 | - | |
30 | + | |
42 | 31 | # Activate user |
43 | 32 | # La variable qui régit l'activation d'un compte est contenue dans pyrosUsers |
44 | 33 | # et s'appelle is_active, il suffit de passer cette variable à True |
... | ... | @@ -50,67 +39,39 @@ class UserManagerTests(TestCase): |
50 | 39 | # Log user |
51 | 40 | path = "/user_manager/login" |
52 | 41 | response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze"}) |
53 | - | |
54 | - """ Note that we use .has_key() because the login phase change the httpresponse context """ | |
55 | - #print(response.context) | |
56 | 42 | self.assertTrue(response.context.get("success")) |
57 | 43 | self.assertIn('_auth_user_id', self.client.session, "The user should be logged in") |
58 | 44 | |
59 | 45 | def test_login_not_active(self): |
60 | 46 | self.assertEqual(Country.objects.count(), 1, "There should be 1 Country") |
61 | 47 | self.assertEqual(UserLevel.objects.count(), 1, "There should be 1 UserLevel") |
62 | - self.assertEqual(PyrosUser.objects.count(), 0, "There should be no User") | |
63 | - | |
64 | - # Create user | |
65 | - path = "/user_manager/creation_validate" | |
66 | - response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
67 | - "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
68 | - "laboratory": "IRAP", "address": "ici"}) | |
69 | - self.assertTrue("success" in response.context.keys(), "There should be a success") | |
70 | - self.assertEqual(PyrosUser.objects.count(), 1, "There should be one User") | |
71 | 48 | |
72 | 49 | # Activate user |
73 | 50 | # La variable qui régit l'activation d'un compte est contenue dans pyrosUsers |
74 | 51 | # et s'appelle is_active, il suffit de passer cette variable à True |
75 | - current_user = PyrosUser.objects.all()[0] | |
76 | - current_user.save() | |
52 | + | |
77 | 53 | self.assertEqual(PyrosUser.objects.all()[0].is_active, False, "user should not be active") |
78 | 54 | |
79 | 55 | # Log user |
80 | 56 | path = "/user_manager/login" |
81 | 57 | response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze"}) |
82 | 58 | |
83 | - """ Note that we use .has_key() because the login phase change the httpresponse context """ | |
84 | - # print(response.context) | |
85 | 59 | self.assertFalse(response.context.get("success")) |
86 | 60 | self.assertNotIn('_auth_user_id', self.client.session, "The user should be logged in") |
87 | 61 | |
88 | 62 | def test_wrong_email(self): |
89 | - path = "/user_manager/creation_validate" | |
90 | - response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
91 | - "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
92 | - "laboratory": "IRAP", "address": "ici"}) | |
93 | - | |
94 | 63 | path = "/user_manager/login" |
95 | 64 | response = self.client.post(path, {"email": "toto@tti.fr", "password": "aze"}) |
96 | 65 | self.assertIn("error", response.context.keys(), "There should be an error") |
97 | 66 | self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user") |
98 | 67 | |
99 | 68 | def test_wrong_password(self): |
100 | - path = "/user_manager/creation_validate" | |
101 | - response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
102 | - "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
103 | - "laboratory": "IRAP", "address": "ici"}) | |
104 | 69 | path = "/user_manager/login" |
105 | 70 | response = self.client.post(path, {"email": "toto@titi.fr", "password": "azee"}) |
106 | 71 | self.assertIn("error", response.context.keys(), "There should be an error") |
107 | 72 | self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user") |
108 | 73 | |
109 | 74 | def test_logout(self): |
110 | - path = "/user_manager/creation_validate" | |
111 | - response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
112 | - "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
113 | - "laboratory": "IRAP", "address": "ici"}) | |
114 | 75 | self.client.login(username="toto@titi.fr", password="aze") |
115 | 76 | path = "/user_manager/logout" |
116 | 77 | self.client.get(path) | ... | ... |