forked from DGNum/gestioCOF
131 lines
3.5 KiB
Python
131 lines
3.5 KiB
Python
from django.contrib import messages
|
|
from django.contrib.messages.api import get_messages
|
|
from django.contrib.messages.storage.base import Message
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
|
|
from gestioncof.tests.testcases import ViewTestCaseMixin
|
|
|
|
from .utils import create_member, create_root, create_user
|
|
|
|
|
|
class HomeViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'home'
|
|
url_expected = '/'
|
|
|
|
auth_user = 'user'
|
|
auth_forbidden = [None]
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
|
|
class ProfileViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'profile'
|
|
url_expected = '/profile'
|
|
|
|
http_methods = ['GET', 'POST']
|
|
|
|
auth_user = 'member'
|
|
auth_forbidden = [None, 'user']
|
|
|
|
def test_get(self):
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
def test_post(self):
|
|
u = self.users['member']
|
|
|
|
r = self.client.post(self.url, {
|
|
'first_name': 'First',
|
|
'last_name': 'Last',
|
|
'phone': '',
|
|
# 'mailing_cof': '1',
|
|
# 'mailing_bda': '1',
|
|
# 'mailing_bda_revente': '1',
|
|
})
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
expected_message = Message(messages.SUCCESS, (
|
|
"Votre profil a été mis à jour avec succès !"
|
|
))
|
|
self.assertIn(expected_message, get_messages(r.wsgi_request))
|
|
u.refresh_from_db()
|
|
self.assertEqual(u.first_name, 'First')
|
|
self.assertEqual(u.last_name, 'Last')
|
|
self.assertFalse(u.profile.mailing_cof)
|
|
self.assertFalse(u.profile.mailing_bda)
|
|
self.assertFalse(u.profile.mailing_bda_revente)
|
|
|
|
|
|
class UtilsViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'utile_cof'
|
|
url_expected = '/utile_cof'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
|
|
class MailingListDiffCof(ViewTestCaseMixin, TestCase):
|
|
url_name = 'gestioncof.views.liste_diffcof'
|
|
url_expected = '/utile_cof/diff_cof'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
|
|
self.u1 = create_member('u1', attrs={'mailing_cof': True})
|
|
self.u2 = create_member('u2', attrs={'mailing_cof': False})
|
|
self.u3 = create_user('u3', attrs={'mailing_cof': True})
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
self.assertEqual(r.context['personnes'].get(), self.u1.profile)
|
|
|
|
|
|
class ConfigUpdateViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'config.edit'
|
|
url_expected = '/config'
|
|
|
|
http_methods = ['GET', 'POST']
|
|
|
|
auth_user = 'root'
|
|
auth_forbidden = [None, 'user', 'member', 'staff']
|
|
|
|
def get_users_extra(self):
|
|
return {
|
|
'root': create_root('root'),
|
|
}
|
|
|
|
def test_get(self):
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
def test_post(self):
|
|
r = self.client.post(self.url, {
|
|
'gestion_banner': 'Announcement !',
|
|
})
|
|
|
|
self.assertRedirects(r, reverse('home'))
|
|
|
|
|
|
class UserAutocompleteViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'cof-user-autocomplete'
|
|
url_expected = '/user/autocomplete'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url, {'q': 'user'})
|
|
|
|
self.assertEqual(r.status_code, 200)
|