forked from DGNum/gestioCOF
cof -- Add tests for some views
This commit is contained in:
parent
bd89dce11d
commit
91162addb9
2 changed files with 132 additions and 0 deletions
131
gestioncof/tests/test_views.py
Normal file
131
gestioncof/tests/test_views.py
Normal file
|
@ -0,0 +1,131 @@
|
|||
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)
|
|
@ -9,6 +9,7 @@ from django.http import Http404, HttpResponse, HttpResponseForbidden
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import (
|
||||
login as django_login_view, logout as django_logout_view,
|
||||
redirect_to_login,
|
||||
)
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
|
|
Loading…
Reference in a new issue