tests.py 23.5 KB
Newer Older
1
import os
2
import re
3

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
4
5
from django.conf import settings
from django.contrib.auth import get_user_model
6
7
from django.contrib.auth.models import AnonymousUser, Group
from django.core import mail
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
8
9
from django.core.cache import cache
from django.core.exceptions import ValidationError
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
10
from django.test import TestCase, RequestFactory, override_settings
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
11
12
from django.urls import reverse

13
from basetheme_bootstrap import user_preferences, tokens
14
from basetheme_bootstrap.user_preferences import get_user_preferences_for_user
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
15
16
17
18
19
20
21
22


class AboutPageTests(TestCase):
    def test_works(self):
        response = self.client.get(reverse('basetheme_bootstrap:about_page'))
        self.assertEqual(response.status_code, 200)


23
24
25
26
27
28
29
30
31
class AccountPageTests(TestCase):
    def test_works(self):
        response = self.client.get(reverse('basetheme_bootstrap:account'))
        self.assertRedirects(
            response,
            expected_url=reverse('basetheme_bootstrap:login') + "?next=" + reverse('basetheme_bootstrap:account'),
        )


Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
32
33
class SignUpTests(TestCase):

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
34
35
36
    def setUp(self):
        cache.clear()

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
37
38
39
40
41
42
    def test_works(self):
        response = self.client.get(reverse('basetheme_bootstrap:signup'))
        self.assertEqual(response.status_code, 200)

    def test_sign_up_form_view(self):
        user_count = get_user_model().objects.count()
43
        data = {
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
44
45
46
47
48
            'username': "userAAA",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('home'), )
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
        user = get_user_model().objects.last()
        self.assertEqual(user.username, data["username"])
        self.assertEqual(user.email, data["email"])


@override_settings(
    BASETHEME_BOOTSTRAP_USERNAME_IS_EMAIL=True,
)
class SignUpWithoutUsernameTests(TestCase):

    def test_sign_up_form_view(self):
        user_count = get_user_model().objects.count()
        data = {
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
73
74
75
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('home'), )
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
76
77
78
79
80
        user = get_user_model().objects.last()
        self.assertEqual(user.username, data["email"])
        self.assertEqual(user.email, data["email"])

    def test_sign_up_detecte_duplicate_email(self):
81
        get_user_model().objects.create(username="toto", email="userAAA@mp.com")
82
83
84
85
86
87
88
89
90
        user_count = get_user_model().objects.count()
        data = {
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
        self.assertEqual(response.status_code, 200)
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@override_settings(
    BASETHEME_BOOTSTRAP_FIRST_LAST_NAME_REQUIRED=True,
)
class SignUpWithFirstLastNameRequiredTests(TestCase):

    def test_sign_up_form_view(self):
        user_count = get_user_model().objects.count()
        data = {
            'username': "userAAA@mp.com",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "my_first_name",
            'last_name': "my_last_name",
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('home'), )
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
        user = get_user_model().objects.last()
        self.assertEqual(user.username, data["email"])
        self.assertEqual(user.email, data["email"])
        self.assertEqual(user.first_name, data["first_name"])
        self.assertEqual(user.last_name, data["last_name"])

    def test_sign_up_detect_missing_last_name(self):
        data = {
            'username': "userAAA@mp.com",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "my_first_name",
            'last_name': "",
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
        self.assertEqual(response.status_code, 200)

    def test_sign_up_detect_missing_first_name(self):
        data = {
            'username': "userAAA@mp.com",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "",
            'last_name': "my_last_name",
        }
        response = self.client.post(reverse('basetheme_bootstrap:signup'), data)
        self.assertEqual(response.status_code, 200)


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
@override_settings(
    BASETHEME_BOOTSTRAP_VALIDATE_EMAIL_BEFORE_ACTIVATION=True,
    PASSWORD_RESET_TIMEOUT_DAYS=1,
)
class SignUpWithValidationTests(TestCase):

    def setUp(self):
        cache.clear()
        get_user_model().objects.create(
            username="root",
        )
        self.data = {
            'username': "userAAA",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        }

    def test_sign_up_form_view(self):
        response = self.client.post(reverse('basetheme_bootstrap:signup'), self.data)
        self.assertEqual(response.status_code, 200)

        user = get_user_model().objects.last()
        self.assertFalse(user.is_active)
        self.assertIn(Group.objects.get(name="PendingAccountUser"), user.groups.all())

        self.assertEqual(len(mail.outbox), 1)
        activate_link_example = reverse('basetheme_bootstrap:activate', args=["AAA", "AAA-AAA"])
        activate_link_example = activate_link_example.replace("AAA", "([a-zA-Z0-9]+)")
        m = re.findall(activate_link_example, mail.outbox[0].body)
        self.assertEqual(len(m), 1)
        self.client.post(reverse('basetheme_bootstrap:activate', args=[m[0][0], m[0][1] + "-" + m[0][2]]))
        user = get_user_model().objects.last()
        self.assertTrue(user.is_active)
        self.assertNotIn(Group.objects.get(name="PendingAccountUser"), user.groups.all())

        ## test an account cannot be re-activated with the link:
        user.is_active=False
        user.save()
        self.client.post(reverse('basetheme_bootstrap:activate', args=[m[0][0], m[0][1] + "-" + m[0][2]]))
        self.assertFalse(get_user_model().objects.last().is_active)

    def test_sign_up_with_user_pending_resend_email(self):
        user_count = get_user_model().objects.count()
        response = self.client.post(reverse('basetheme_bootstrap:signup'), self.data)
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 1)

        response = self.client.post(reverse('basetheme_bootstrap:signup'), self.data)
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 2)
        activate_link_example = reverse('basetheme_bootstrap:activate', args=["AAA", "AAA-AAA"])
        activate_link_example = activate_link_example.replace("AAA", "([a-zA-Z0-9]+)")
        m = re.findall(activate_link_example, mail.outbox[-1].body)
        self.assertEqual(len(m), 1)

    def test_activate_too_late_with_user_pending_resend_email(self):
        actual_account_activation_token = tokens.account_activation_token

        class MockedTokenGenerator(tokens.TokenGenerator):
            def _today(self):
                from datetime import date, timedelta
                # Used for mocking in tests
                return date.today() - timedelta(days=2)

        tokens.account_activation_token = MockedTokenGenerator()

        user_count = get_user_model().objects.count()
        response = self.client.post(reverse('basetheme_bootstrap:signup'), self.data)
        self.assertEqual(get_user_model().objects.count(), user_count + 1)
        self.assertEqual(response.status_code, 200)
        self.assertFalse(get_user_model().objects.last().is_active)

        tokens.account_activation_token = actual_account_activation_token

        self.assertEqual(len(mail.outbox), 1)
        activate_link_example = reverse('basetheme_bootstrap:activate', args=["AAA", "AAA-AAA"])
        activate_link_example = activate_link_example.replace("AAA", "([a-zA-Z0-9]+)")
        m = re.findall(activate_link_example, mail.outbox[0].body)
        self.assertEqual(len(m), 1)
        self.client.post(reverse('basetheme_bootstrap:activate', args=[m[0][0], m[0][1] + "-" + m[0][2]]))

        self.assertFalse(get_user_model().objects.last().is_active)
        self.assertEqual(len(mail.outbox), 2)
        activate_link_example = reverse('basetheme_bootstrap:activate', args=["AAA", "AAA-AAA"])
        activate_link_example = activate_link_example.replace("AAA", "([a-zA-Z0-9]+)")
        m = re.findall(activate_link_example, mail.outbox[1].body)
        self.assertEqual(len(m), 1)


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
class TestWithTemplatesInPlace(SignUpTests):

    def setUp(self):
        super().setUp()

    def test_with_templates(self):
        templates = [
            "test_app_1/templates/test_app_1/fork_me.html",
            "test_app_1/templates/test_app_1/nav_bar.html",
            "test_app_1/templates/test_app_1/last_update.html",
        ]

        for t in templates:
            open(t, 'a').close()
        self.test_works()
        self.test_sign_up_form_view()
        for t in templates:
            os.remove(t)


Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
256
257
class SuperuserSignUpTests(TestCase):

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
258
259
260
    def setUp(self):
        cache.clear()

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    def test_sign_up_for_superuser(self):
        response = self.client.post(reverse('basetheme_bootstrap:signup'), {
            'username': "userAAA",
            'email': "bryan.brancotte@pasteur.fr",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('home'), )
        self.assertTrue(get_user_model().objects.get(username="userAAA").is_superuser)

        response = self.client.post(reverse('basetheme_bootstrap:signup'), {
            'username': "userAAAZZZ",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('home'), )
        self.assertEqual(get_user_model().objects.count(), 2)
        self.assertFalse(get_user_model().objects.get(username="userAAAZZZ").is_superuser)


class ChangePasswordTests(TestCase):

    def setUp(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
289
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
        self.user_pwd = "eil2guj4cuSho2Vai3hu"
        self.user_pwd_2 = "aig7thah4eethahdaDae"
        self.user = get_user_model().objects.create(
            username="a",
            email="a@a.a",
        )
        self.user.set_password(self.user_pwd)
        self.user.save()

    def test_works(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))
        response = self.client.get(reverse('basetheme_bootstrap:change_password'))
        self.assertEqual(response.status_code, 200)

    def test_changepassword_ok_view(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))

        response = self.client.post(reverse('basetheme_bootstrap:change_password'), {
            'old_password': self.user_pwd,
            'new_password1': self.user_pwd_2,
            'new_password2': self.user_pwd_2,
        })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('basetheme_bootstrap:account'), )
        self.client.logout()
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd_2))

    def test_changepassword_fail_view(self):
        user_login = self.client.login(username="a", email="a@a.a", password=self.user_pwd)
        self.assertTrue(user_login)
        response = self.client.post(reverse('basetheme_bootstrap:change_password'), {
            'old_password': "A",
            'new_password1': "Z",
            'new_password2': "E",
        })
        self.assertEqual(response.status_code, 200)
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))

        user_login = self.client.login(username="a", email="a@a.a", password=self.user_pwd)
        self.assertTrue(user_login)
        response = self.client.post(reverse('basetheme_bootstrap:change_password'), {
            'old_password': self.user_pwd,
            'new_password1': "Z",
            'new_password2': "E",
        })
        self.assertEqual(response.status_code, 200)
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))


class ChangeFirstnameTests(TestCase):

    def setUp(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
342
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
        self.user_pwd = "eil2guj4cuSho2Vai3hu"
        self.user_pwd_2 = "aig7thah4eethahdaDae"
        self.user = get_user_model().objects.create(
            username="a",
            email="aa@aa.aa",
            first_name="tata",
        )
        self.user.set_password(self.user_pwd)
        self.user.save()

    def test_works(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))
        response = self.client.get(reverse('basetheme_bootstrap:user-update'))
        self.assertEqual(response.status_code, 200)

    def test_empty_username(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))
        user = get_user_model().objects.get(username="a")
        response = self.client.post(reverse('basetheme_bootstrap:user-update'), {
            'username': "",
            'email': user.email,
            'first_name': "toto",
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(get_user_model().objects.get(pk=user.pk).username, "a")

    def test_change_firstname(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))

        self.assertEqual(get_user_model().objects.get(username="a").first_name, "tata")
        response = self.client.post(reverse('basetheme_bootstrap:user-update'), {
            'username': get_user_model().objects.get(username="a").username,
            'email': get_user_model().objects.get(username="a").email,
            'first_name': "toto",
        })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, expected_url=reverse('basetheme_bootstrap:account'), )
        self.client.logout()
        self.assertEqual(get_user_model().objects.get(username="a").first_name, "toto")


class DeleteAccountTests(TestCase):

    def setUp(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
387
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
        self.user_pwd = "eil2guj4cuSho2Vai3hu"
        self.user_pwd_2 = "aig7thah4eethahdaDae"
        self.user = get_user_model().objects.create(
            username="a",
            email="aa@aa.aa",
            first_name="tata",
        )
        self.user.set_password(self.user_pwd)
        self.user.save()

    def test_works(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))
        response = self.client.get(reverse('basetheme_bootstrap:user-delete'))
        self.assertEqual(response.status_code, 200)

    def test_works_post(self):
        self.assertTrue(self.client.login(username="a", email="a@a.a", password=self.user_pwd))
        response = self.client.post(reverse('basetheme_bootstrap:user-delete'), {})
        self.assertEqual(response.status_code, 302)
        self.assertIn(response.url, ['/', reverse('basetheme_bootstrap:login')])
        # self.assertRedirects(response, expected_url='/', )


class TemplatesTagsTests(TestCase):
    def setUp(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
413
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
        self.factory = RequestFactory()

    def test_is_active_or_desc(self):
        from basetheme_bootstrap.templatetags.basetheme_bootstrap import is_active_or_desc
        request = self.factory.get(reverse("basetheme_bootstrap:change_password"))
        self.assertEqual('active ', is_active_or_desc(
            request,
            "basetheme_bootstrap:account"
        ))
        self.assertEqual('active ', is_active_or_desc(
            request,
            "basetheme_bootstrap:change_password"
        ))
        request = self.factory.get(reverse("basetheme_bootstrap:account"))
        self.assertEqual('', is_active_or_desc(
            request,
            "basetheme_bootstrap:change_password"
        ))
        self.assertEqual('', is_active_or_desc(
            None,
            "basetheme_bootstrap:account"
        ))
        self.assertEqual('', is_active_or_desc(
            request,
            None
        ))

    def test_is_active(self):
        from basetheme_bootstrap.templatetags.basetheme_bootstrap import is_active
        request = self.factory.get(reverse("basetheme_bootstrap:change_password"))
        self.assertEqual('', is_active(
            request,
            "basetheme_bootstrap:account"
        ))
        self.assertEqual('active ', is_active(
            request,
            "basetheme_bootstrap:change_password"
        ))
        request = self.factory.get(reverse("basetheme_bootstrap:account"))
        self.assertEqual('', is_active(
            request,
            "basetheme_bootstrap:change_password"
        ))
        self.assertEqual('', is_active(
            None,
            "basetheme_bootstrap:account"
        ))
        self.assertEqual('', is_active(
            request,
            None
        ))

    def test_tags_to_bootstrap(self):
        from basetheme_bootstrap.templatetags.basetheme_bootstrap import tags_to_bootstrap
        self.assertEqual(tags_to_bootstrap("error"), "danger")
        self.assertEqual(tags_to_bootstrap("warning"), "warning")
        self.assertEqual(tags_to_bootstrap(""), "info")


class UserPreferencesTests(TestCase):

    def setUp(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
476
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
        self.user_pwd = "eil2guj4cuSho2Vai3hu"
        self.user = get_user_model().objects.create(
            username="user",
            email="aa@aa.aa",
            first_name="tata",
        )
        self.user.set_password(self.user_pwd)
        self.user.save()

    def test_when_enabled_that_it_works(self):
        if not getattr(settings, "BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED", False):
            return
        self.assertIsNotNone(user_preferences.get_user_preference_class())
        pref = user_preferences.get_user_preferences_for_user(self.user)
        self.assertIsNotNone(pref)
        default_pref = user_preferences.get_user_preferences_for_user(None)
        self.assertIsNotNone(default_pref)
        self.assertNotEqual(pref, default_pref)

    def test_when_enabled_that_it_works_2(self):
        if not getattr(settings, "BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED", False):
            return
        default_pref = user_preferences.get_user_preferences_for_user(None)
        self.assertIsNotNone(default_pref)
        pref = user_preferences.get_user_preferences_for_user(self.user)
        self.assertIsNotNone(pref)
        self.assertNotEqual(pref, default_pref)

        default_pref.user = self.user
        default_pref.save()
        default_pref.user = None
        default_pref.save()
        pref.save()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
510
        str(pref)
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524

        default_pref = user_preferences.get_user_preferences_for_user(None)
        self.assertIsNotNone(default_pref)
        pref = user_preferences.get_user_preferences_for_user(self.user)
        self.assertIsNotNone(pref)
        self.assertNotEqual(pref, default_pref)

    def test_only_one_default_pref(self):
        if not getattr(settings, "BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED", False):
            return
        pref = user_preferences.get_user_preferences_for_user(self.user)
        pref.user = None
        self.assertRaises(ValidationError, pref.save)

525
526
527
    def test_AnonymousUser_do_not_crash(self):
        get_user_preferences_for_user(AnonymousUser())

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
528
529
530
531
532
533
    def test_caching_disabled_status_when_it_is_the_case(self):
        user_preferences.get_user_preference_class()
        self.assertTrue(
            cache.get("has_no_user_preferences_model", False) or
            getattr(settings, "BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED", False)
        )
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
534
535
536
537
538
539
540
541
542


@override_settings(
    BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED=False,
)
class SignUpTestsUserPrefDown(SignUpTests):
    pass

    def test_dummy(self):
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
543
        cache.clear()
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
544
545
546
547
548
549
550
551
552
553
554
        self.client.post(reverse('basetheme_bootstrap:signup'), {
            'username': "userAAA",
            'email': "userAAA@mp.com",
            'password1': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'password2': "user@mp.comuser@mp.comuser@mp.comuser@mp.com",
            'first_name': "user"
        })
        user_preferences.get_user_preference_class()
        user_preferences.get_user_preference_class()
        user_preferences.get_user_preferences_for_user(get_user_model().objects.first())

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    def setUp(self):
        cache.clear()
        self.user_pwd = "eil2guj4cuSho2Vai3hu"
        self.user = get_user_model().objects.create(
            username="user",
            email="aa@aa.aa",
            first_name="tata",
        )
        self.user.set_password(self.user_pwd)
        self.user.save()

    def test_view_account_without_pref(self):
        cache.clear()
        self.client.force_login(self.user)
        response = self.client.get(reverse('basetheme_bootstrap:account'))
        self.assertEqual(response.status_code, 200)

Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE committed
572
573
574
575
576
577

@override_settings(
    BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_NAME="AAAAA",
)
class SignUpTestsUserWrongUserPrefLocation(SignUpTests):
    pass
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633


@override_settings(
    DEBUG=False,
)
class AboutPageTestsDebugFalse(AboutPageTests):
    pass


@override_settings(
    DEBUG=False,
)
class SignUpTestsDebugFalse(SignUpTests):
    pass


@override_settings(
    DEBUG=False,
)
class SuperuserSignUpTestsDebugFalse(SuperuserSignUpTests):
    pass


@override_settings(
    DEBUG=False,
)
class ChangePasswordTestsDebugFalse(ChangePasswordTests):
    pass


@override_settings(
    DEBUG=False,
)
class ChangeFirstnameTestsDebugFalse(ChangeFirstnameTests):
    pass


@override_settings(
    DEBUG=False,
)
class DeleteAccountTestsDebugFalse(DeleteAccountTests):
    pass


@override_settings(
    DEBUG=False,
)
class TemplatesTagsTestsDebugFalse(TemplatesTagsTests):
    pass


@override_settings(
    DEBUG=False,
)
class UserPreferencesTestsDebugFalse(UserPreferencesTests):
    pass