tests.py 11.5 KB
Newer Older
Skia's avatar
Skia committed
1 2
from django.test import SimpleTestCase, Client
from django.core.urlresolvers import reverse
Skia's avatar
Skia committed
3
from django.contrib.auth.models import Group
Skia's avatar
Skia committed
4

Skia's avatar
Skia committed
5 6
from core.models import User
from core.views.forms import RegisteringForm, LoginForm
Skia's avatar
Skia committed
7 8

class UserRegistrationTest(SimpleTestCase):
Skia's avatar
Skia committed
9 10 11 12 13 14
    def setUp(self):
        try:
            Group.objects.create(name="root")
        except:
            pass

Skia's avatar
Skia committed
15 16 17 18 19 20 21 22
    def test_register_user_form_ok(self):
        """
        Should register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': 'Guy',
                                                     'last_name': 'Carlier',
                                                     'email': 'guy@git.an',
Skia's avatar
Skia committed
23
                                                     'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
        self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))

    def test_register_user_form_fail_password(self):
        """
        Should not register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': 'Guy',
                                                     'last_name': 'Carlier',
                                                     'email': 'bibou@git.an',
Skia's avatar
Skia committed
38
                                                     'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
39 40 41 42
                                                     'password1': 'plop',
                                                     'password2': 'plop2',
                                                    })
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
43
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
Skia's avatar
Skia committed
44 45 46 47 48 49 50 51 52

    def test_register_user_form_fail_email(self):
        """
        Should not register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': 'Guy',
                                                     'last_name': 'Carlier',
                                                     'email': 'bibou.git.an',
Skia's avatar
Skia committed
53
                                                     'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
54 55 56 57
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
58
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
Skia's avatar
Skia committed
59 60 61 62 63 64 65 66 67

    def test_register_user_form_fail_missing_name(self):
        """
        Should not register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': 'Guy',
                                                     'last_name': '',
                                                     'email': 'bibou@git.an',
Skia's avatar
Skia committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
                                                     'date_of_birth': '12/6/1942',
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))

    def test_register_user_form_fail_missing_date_of_birth(self):
        """
        Should not register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': '',
                                                     'last_name': 'Carlier',
                                                     'email': 'bibou@git.an',
                                                     'date_of_birth': '',
Skia's avatar
Skia committed
84 85 86 87
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
88
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
Skia's avatar
Skia committed
89 90 91 92 93 94 95 96 97

    def test_register_user_form_fail_missing_first_name(self):
        """
        Should not register a user correctly
        """
        c = Client()
        response = c.post(reverse('core:register'), {'first_name': '',
                                                     'last_name': 'Carlier',
                                                     'email': 'bibou@git.an',
Skia's avatar
Skia committed
98
                                                     'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
99 100 101 102
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
103
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
Skia's avatar
Skia committed
104 105 106 107 108 109 110 111 112

    def test_register_user_form_fail_already_exists(self):
        """
        Should not register a user correctly
        """
        c = Client()
        c.post(reverse('core:register'), {'first_name': 'Guy',
                                          'last_name': 'Carlier',
                                          'email': 'bibou@git.an',
Skia's avatar
Skia committed
113
                                          'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
114 115 116 117 118 119
                                          'password1': 'plop',
                                          'password2': 'plop',
                                         })
        response = c.post(reverse('core:register'), {'first_name': 'Bibou',
                                                     'last_name': 'Carlier',
                                                     'email': 'bibou@git.an',
Skia's avatar
Skia committed
120
                                                     'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
121 122 123 124
                                                     'password1': 'plop',
                                                     'password2': 'plop',
                                                    })
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
125
        self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
Skia's avatar
Skia committed
126

Skia's avatar
Skia committed
127 128 129 130 131 132 133 134
    def test_login_success(self):
        """
        Should login a user correctly
        """
        c = Client()
        c.post(reverse('core:register'), {'first_name': 'Guy',
                                          'last_name': 'Carlier',
                                          'email': 'bibou@git.an',
Skia's avatar
Skia committed
135
                                          'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
                                          'password1': 'plop',
                                          'password2': 'plop',
                                         })
        response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'})
        self.assertTrue(response.status_code == 200)
        self.assertTrue('LOGIN_OK' in str(response.content))

    def test_login_fail(self):
        """
        Should not login a user correctly
        """
        c = Client()
        c.post(reverse('core:register'), {'first_name': 'Guy',
                                          'last_name': 'Carlier',
                                          'email': 'bibou@git.an',
Skia's avatar
Skia committed
151
                                          'date_of_birth': '12/6/1942',
Skia's avatar
Skia committed
152 153 154 155 156 157
                                          'password1': 'plop',
                                          'password2': 'plop',
                                         })
        response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'})
        self.assertTrue(response.status_code == 200)
        self.assertTrue('LOGIN_FAIL' in str(response.content))
Skia's avatar
Skia committed
158 159 160 161 162 163

    def test_create_page_ok(self):
        """
        Should create a page correctly
        """
        c = Client()
164
        response = c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
Skia's avatar
Skia committed
165 166 167 168 169 170 171 172 173 174 175 176
                                                                                   'name': 'guy',
                                                                                   'title': 'Guy',
                                                                                   'Content': 'Guyéuyuyé',
                                                                                  })
        self.assertTrue(response.status_code == 200)
        self.assertTrue('PAGE_SAVED' in str(response.content))

    def test_create_child_page_ok(self):
        """
        Should create a page correctly
        """
        c = Client()
177
        c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
Skia's avatar
Skia committed
178 179 180 181
                                                                        'name': 'guy',
                                                                        'title': 'Guy',
                                                                        'Content': 'Guyéuyuyé',
                                                                       })
182
        response = c.post(reverse('core:page_prop', kwargs={'page_name': 'guy/bibou'}), {'parent': '1',
Skia's avatar
Skia committed
183 184 185 186 187 188 189 190 191 192 193 194 195
                                                                                         'name': 'bibou',
                                                                                         'title': 'Bibou',
                                                                                         'Content':
                                                                                         'Bibibibiblblblblblbouuuuuuuuu',
                                                                                        })
        self.assertTrue(response.status_code == 200)
        self.assertTrue('PAGE_SAVED' in str(response.content))

    def test_access_child_page_ok(self):
        """
        Should display a page correctly
        """
        c = Client()
196
        c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
Skia's avatar
Skia committed
197 198 199 200
                                                                        'name': 'guy',
                                                                        'title': 'Guy',
                                                                        'Content': 'Guyéuyuyé',
                                                                       })
201
        c.post(reverse('core:page_prop', kwargs={'page_name': 'guy/bibou'}), {'parent': '1',
Skia's avatar
Skia committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
                                                                              'name': 'bibou',
                                                                              'title': 'Bibou',
                                                                              'Content':
                                                                              'Bibibibiblblblblblbouuuuuuuuu',
                                                                             })
        response = c.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'}))
        self.assertTrue(response.status_code == 200)
        self.assertTrue('PAGE_FOUND : Bibou' in str(response.content))

    def test_access_page_not_found(self):
        """
        Should not display a page correctly
        """
        c = Client()
        response = c.get(reverse('core:page', kwargs={'page_name': 'swagg'}))
        self.assertTrue(response.status_code == 200)
        self.assertTrue('PAGE_NOT_FOUND' in str(response.content))
Skia's avatar
Skia committed
219 220 221 222 223

#TODO: many tests on the pages:
#   - renaming a page
#   - changing a page's parent --> check that page's children's full_name
#   - changing the different groups of the page