Blame view

src/user_manager/tests.py 3.56 KB
3df2d31a   haribo   #3430 : dates are...
1
from django.test import TestCase
ddf59dd4   haribo   Remaniement :
2
from common.models import *
fd99569d   haribo   Date: 22/06/2016
3
from django.contrib.auth.models import User
3df2d31a   haribo   #3430 : dates are...
4

fd99569d   haribo   Date: 22/06/2016
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from pprint import pprint

class UserManagerTests(TestCase):

    def setUp(self):
        UserLevel.objects.create()
        Country.objects.create()

    def test_creation(self):
        path = "/user_manager/creation_validate"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze",
                                           "first_name": "toto", "last_name": "titi", "tel": "0123456789",
                                           "laboratory": "IRAP", "address": "ici"})
        self.assertTrue("success" in response.context.keys(), "There should be a success")
53787d30   Jeremy   Alert now inherit...
19
        self.assertEqual(PyrosUser.objects.count(), 1, "There should be one User")
fd99569d   haribo   Date: 22/06/2016
20
21
22
23
24
25
26
27
28
29
30
31
        self.assertEqual(PyrosUser.objects.count(), 1, "There should be one PyrosUser")

    def test_login(self):
        path = "/user_manager/creation_validate"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze",
                                "first_name": "toto", "last_name": "titi", "tel": "0123456789",
                                "laboratory": "IRAP", "address": "ici"})

        path = "/user_manager/login"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze"})

        """ Note that we use .has_key() because the login phase change the httpresponse context """
661d7672   theopuhl   Unittest Fix
32
        self.assertIn("success", response.context, "There should be a success")
fd99569d   haribo   Date: 22/06/2016
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
        self.assertIn('_auth_user_id', self.client.session, "The user should be logged in")

    def test_wrong_email(self):
        path = "/user_manager/creation_validate"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze",
                                "first_name": "toto", "last_name": "titi", "tel": "0123456789",
                                "laboratory": "IRAP", "address": "ici"})

        path = "/user_manager/login"
        response = self.client.post(path, {"email": "toto@tti.fr", "password": "aze"})
        self.assertIn("error", response.context.keys(), "There should be an error")
        self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user")

    def test_wrong_password(self):
        path = "/user_manager/creation_validate"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze",
                                "first_name": "toto", "last_name": "titi", "tel": "0123456789",
                                "laboratory": "IRAP", "address": "ici"})
        path = "/user_manager/login"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "azee"})
        self.assertIn("error", response.context.keys(), "There should be an error")
        self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user")

    def test_logout(self):
        path = "/user_manager/creation_validate"
        response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze",
                                           "first_name": "toto", "last_name": "titi", "tel": "0123456789",
                                           "laboratory": "IRAP", "address": "ici"})
        self.client.login(username="toto@titi.fr", password="aze")
        path = "/user_manager/logout"
        self.client.get(path)
        self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user")