Date: Mon, 22 Jan 2018 14:59:57 +0100
Subject: [PATCH 40/59] Name urls of export views (cof members, mega)
---
gestioncof/templates/gestioncof/utile_cof.html | 8 ++++----
gestioncof/tests/test_views.py | 10 +++++-----
gestioncof/urls.py | 15 ++++++++++-----
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/gestioncof/templates/gestioncof/utile_cof.html b/gestioncof/templates/gestioncof/utile_cof.html
index ae024949..8cea33df 100644
--- a/gestioncof/templates/gestioncof/utile_cof.html
+++ b/gestioncof/templates/gestioncof/utile_cof.html
@@ -7,15 +7,15 @@
Liens utiles du COF
COF
Mega
Note : pour ouvrir les fichiers .csv avec Excel, il faut
diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py
index 8cd323cc..02288e2b 100644
--- a/gestioncof/tests/test_views.py
+++ b/gestioncof/tests/test_views.py
@@ -9,7 +9,7 @@ from .utils import create_user
class ExportMembersViewTests(ViewTestCaseMixin, TestCase):
- url_name = 'gestioncof.views.export_members'
+ url_name = 'cof.membres_export'
url_expected = '/export/members'
auth_user = 'staff'
@@ -83,7 +83,7 @@ class MegaHelpers:
class ExportMegaViewTests(MegaHelpers, ViewTestCaseMixin, TestCase):
- url_name = 'gestioncof.views.export_mega'
+ url_name = 'cof.mega_export'
url_expected = '/export/mega'
auth_user = 'staff'
@@ -103,7 +103,7 @@ class ExportMegaViewTests(MegaHelpers, ViewTestCaseMixin, TestCase):
class ExportMegaOrgasViewTests(MegaHelpers, ViewTestCaseMixin, TestCase):
- url_name = 'gestioncof.views.export_mega_orgas'
+ url_name = 'cof.mega_export_orgas'
url_expected = '/export/mega/orgas'
auth_user = 'staff'
@@ -124,7 +124,7 @@ class ExportMegaOrgasViewTests(MegaHelpers, ViewTestCaseMixin, TestCase):
class ExportMegaParticipantsViewTests(
MegaHelpers, ViewTestCaseMixin, TestCase):
- url_name = 'gestioncof.views.export_mega_participants'
+ url_name = 'cof.mega_export_participants'
url_expected = '/export/mega/participants'
auth_user = 'staff'
@@ -141,7 +141,7 @@ class ExportMegaParticipantsViewTests(
class ExportMegaRemarksViewTests(
MegaHelpers, ViewTestCaseMixin, TestCase):
- url_name = 'gestioncof.views.export_mega_remarksonly'
+ url_name = 'cof.mega_export_remarks'
url_expected = '/export/mega/avecremarques'
auth_user = 'staff'
diff --git a/gestioncof/urls.py b/gestioncof/urls.py
index 2be609b3..ef3b4190 100644
--- a/gestioncof/urls.py
+++ b/gestioncof/urls.py
@@ -6,12 +6,17 @@ from gestioncof import views, petits_cours_views
from gestioncof.decorators import buro_required
export_patterns = [
- url(r'^members$', views.export_members),
- url(r'^mega/avecremarques$', views.export_mega_remarksonly),
- url(r'^mega/participants$', views.export_mega_participants),
- url(r'^mega/orgas$', views.export_mega_orgas),
+ url(r'^members$', views.export_members,
+ name='cof.membres_export'),
+ url(r'^mega/avecremarques$', views.export_mega_remarksonly,
+ name='cof.mega_export_remarks'),
+ url(r'^mega/participants$', views.export_mega_participants,
+ name='cof.mega_export_participants'),
+ url(r'^mega/orgas$', views.export_mega_orgas,
+ name='cof.mega_export_orgas'),
# url(r'^mega/(?P.+)$', views.export_mega_bytype),
- url(r'^mega$', views.export_mega),
+ url(r'^mega$', views.export_mega,
+ name='cof.mega_export'),
]
petitcours_patterns = [
From bd89dce11d72f6ecf86501cfaf920dac646c6914 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?=
Date: Mon, 22 Jan 2018 21:38:01 +0100
Subject: [PATCH 41/59] Add testing helpers to create superuser
---
gestioncof/tests/utils.py | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gestioncof/tests/utils.py b/gestioncof/tests/utils.py
index 8d55680a..7ba361b7 100644
--- a/gestioncof/tests/utils.py
+++ b/gestioncof/tests/utils.py
@@ -9,7 +9,9 @@ def _create_user(username, is_cof=False, is_staff=False, attrs=None):
password = attrs.pop('password', username)
- user_keys = ['first_name', 'last_name', 'email', 'is_staff']
+ user_keys = [
+ 'first_name', 'last_name', 'email', 'is_staff', 'is_superuser',
+ ]
user_attrs = {k: v for k, v in attrs.items() if k in user_keys}
profile_keys = [
@@ -49,3 +51,11 @@ def create_member(username, attrs=None):
def create_staff(username, attrs=None):
return _create_user(username, is_cof=True, is_staff=True, attrs=attrs)
+
+
+def create_root(username, attrs=None):
+ if attrs is None:
+ attrs = {}
+ attrs.setdefault('is_staff', True)
+ attrs.setdefault('is_superuser', True)
+ return _create_user(username, attrs=attrs)
From 91162addb95fcafbf555288cc7fdeafa6f910b4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?=
Date: Mon, 22 Jan 2018 21:41:02 +0100
Subject: [PATCH 42/59] cof -- Add tests for some views
---
gestioncof/tests/test_views.py | 131 +++++++++++++++++++++++++++++++++
gestioncof/views.py | 1 +
2 files changed, 132 insertions(+)
create mode 100644 gestioncof/tests/test_views.py
diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py
new file mode 100644
index 00000000..9f13fb36
--- /dev/null
+++ b/gestioncof/tests/test_views.py
@@ -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)
diff --git a/gestioncof/views.py b/gestioncof/views.py
index 5dfee83f..2039bb65 100644
--- a/gestioncof/views.py
+++ b/gestioncof/views.py
@@ -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
From 0876a004e55a04cf638903a2aa423e608a3654bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?=
Date: Mon, 22 Jan 2018 14:59:57 +0100
Subject: [PATCH 43/59] Name urls of export views (cof members, mega)
---
gestioncof/templates/gestioncof/utile_cof.html | 8 ++++----
gestioncof/urls.py | 15 ++++++++++-----
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/gestioncof/templates/gestioncof/utile_cof.html b/gestioncof/templates/gestioncof/utile_cof.html
index ae024949..8cea33df 100644
--- a/gestioncof/templates/gestioncof/utile_cof.html
+++ b/gestioncof/templates/gestioncof/utile_cof.html
@@ -7,15 +7,15 @@
Liens utiles du COF
COF
Mega
Note : pour ouvrir les fichiers .csv avec Excel, il faut
diff --git a/gestioncof/urls.py b/gestioncof/urls.py
index 2be609b3..ef3b4190 100644
--- a/gestioncof/urls.py
+++ b/gestioncof/urls.py
@@ -6,12 +6,17 @@ from gestioncof import views, petits_cours_views
from gestioncof.decorators import buro_required
export_patterns = [
- url(r'^members$', views.export_members),
- url(r'^mega/avecremarques$', views.export_mega_remarksonly),
- url(r'^mega/participants$', views.export_mega_participants),
- url(r'^mega/orgas$', views.export_mega_orgas),
+ url(r'^members$', views.export_members,
+ name='cof.membres_export'),
+ url(r'^mega/avecremarques$', views.export_mega_remarksonly,
+ name='cof.mega_export_remarks'),
+ url(r'^mega/participants$', views.export_mega_participants,
+ name='cof.mega_export_participants'),
+ url(r'^mega/orgas$', views.export_mega_orgas,
+ name='cof.mega_export_orgas'),
# url(r'^mega/(?P.+)$', views.export_mega_bytype),
- url(r'^mega$', views.export_mega),
+ url(r'^mega$', views.export_mega,
+ name='cof.mega_export'),
]
petitcours_patterns = [
From f8361b9114700facc4ebfcaa79d024be49496193 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?=
Date: Mon, 22 Jan 2018 21:53:19 +0100
Subject: [PATCH 44/59] Add & fix urls naming
---
cof/urls.py | 6 ++++--
gestioncof/templates/gestioncof/profile.html | 2 +-
gestioncof/templates/gestioncof/utile_cof.html | 2 +-
gestioncof/tests/test_views.py | 2 +-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/cof/urls.py b/cof/urls.py
index e6e5d313..33d4fbc6 100644
--- a/cof/urls.py
+++ b/cof/urls.py
@@ -86,13 +86,15 @@ urlpatterns = [
url(r'^utile_bda$', gestioncof_views.utile_bda,
name='utile_bda'),
url(r'^utile_bda/bda_diff$', gestioncof_views.liste_bdadiff),
- url(r'^utile_cof/diff_cof$', gestioncof_views.liste_diffcof),
+ url(r'^utile_cof/diff_cof$', gestioncof_views.liste_diffcof,
+ name='ml_diffcof'),
url(r'^utile_bda/bda_revente$', gestioncof_views.liste_bdarevente),
url(r'^k-fet/', include('kfet.urls')),
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
# djconfig
- url(r"^config", gestioncof_views.ConfigUpdate.as_view()),
+ url(r"^config", gestioncof_views.ConfigUpdate.as_view(),
+ name='config.edit'),
]
if 'debug_toolbar' in settings.INSTALLED_APPS:
diff --git a/gestioncof/templates/gestioncof/profile.html b/gestioncof/templates/gestioncof/profile.html
index 59358239..5decdfb3 100644
--- a/gestioncof/templates/gestioncof/profile.html
+++ b/gestioncof/templates/gestioncof/profile.html
@@ -5,7 +5,7 @@
{% block realcontent %}
Modifier mon profil
-