diff --git a/club/tests/__init__.py b/club/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/club/tests/base.py b/club/tests/base.py
new file mode 100644
index 00000000..47f50264
--- /dev/null
+++ b/club/tests/base.py
@@ -0,0 +1,71 @@
+from datetime import timedelta
+
+from django.conf import settings
+from django.core.cache import cache
+from django.test import TestCase
+from django.urls import reverse
+from django.utils.timezone import now
+from model_bakery import baker
+
+from club.models import Club, Membership
+from core.models import User
+
+
+class TestClub(TestCase):
+ """Set up data for test cases related to clubs and membership.
+
+ The generated dataset is the one created by the populate command,
+ plus the following modifications :
+
+ - `self.club` is a dummy club recreated for each test
+ - `self.club` has two board members : skia (role 3) and comptable (role 10)
+ - `self.club` has one regular member : richard
+ - `self.club` has one former member : sli (who had role 2)
+ - None of the `self.club` members are in the AE club.
+ """
+
+ @classmethod
+ def setUpTestData(cls):
+ # subscribed users - initial members
+ cls.skia = User.objects.get(username="skia")
+ # by default, Skia is in the AE, which creates side effect
+ cls.skia.memberships.all().delete()
+ cls.richard = User.objects.get(username="rbatsbak")
+ cls.comptable = User.objects.get(username="comptable")
+ cls.sli = User.objects.get(username="sli")
+ cls.root = User.objects.get(username="root")
+
+ # subscribed users - not initial members
+ cls.krophil = User.objects.get(username="krophil")
+ cls.subscriber = User.objects.get(username="subscriber")
+
+ # old subscriber
+ cls.old_subscriber = User.objects.get(username="old_subscriber")
+
+ # not subscribed
+ cls.public = User.objects.get(username="public")
+
+ cls.ae = Club.objects.get(pk=settings.SITH_MAIN_CLUB_ID)
+ cls.club = baker.make(Club)
+ cls.members_url = reverse("club:club_members", kwargs={"club_id": cls.club.id})
+ a_month_ago = now() - timedelta(days=30)
+ yesterday = now() - timedelta(days=1)
+ Membership.objects.create(
+ club=cls.club, user=cls.skia, start_date=a_month_ago, role=3
+ )
+ Membership.objects.create(club=cls.club, user=cls.richard, role=1)
+ Membership.objects.create(
+ club=cls.club, user=cls.comptable, start_date=a_month_ago, role=10
+ )
+
+ # sli was a member but isn't anymore
+ Membership.objects.create(
+ club=cls.club,
+ user=cls.sli,
+ start_date=a_month_ago,
+ end_date=yesterday,
+ role=2,
+ )
+
+ def setUp(self):
+ cache.clear()
diff --git a/club/tests/test_edit.py b/club/tests/test_edit.py
new file mode 100644
index 00000000..9da327ea
--- /dev/null
+++ b/club/tests/test_edit.py
@@ -0,0 +1,38 @@
+import pytest
+from django.test import Client
+from django.urls import reverse
+from model_bakery import baker
+from pytest_django.asserts import assertRedirects
+
+from club.models import Club, Membership
+from core.baker_recipes import subscriber_user
+
+
+@pytest.mark.django_db
+def test_club_board_member_cannot_edit_club_properties(client: Client):
+ user = subscriber_user.make()
+ club = baker.make(Club, name="old name", is_active=True, address="old address")
+ baker.make(Membership, club=club, user=user, role=7)
+ client.force_login(user)
+ res = client.post(
+ reverse("club:club_edit", kwargs={"club_id": club.id}),
+ {"name": "new name", "is_active": False, "address": "new address"},
+ )
+ # The request should success,
+ # but admin-only fields shouldn't be taken into account
+ assertRedirects(res, club.get_absolute_url())
+ club.refresh_from_db()
+ assert club.name == "old name"
+ assert club.is_active
+ assert club.address == "new address"
+
+
+@pytest.mark.django_db
+def test_edit_club_page_doesnt_crash(client: Client):
+ """crash test for club:club_edit"""
+ club = baker.make(Club)
+ user = subscriber_user.make()
+ baker.make(Membership, club=club, user=user, role=3)
+ client.force_login(user)
+ res = client.get(reverse("club:club_edit", kwargs={"club_id": club.id}))
+ assert res.status_code == 200
diff --git a/club/tests/test_mailing.py b/club/tests/test_mailing.py
new file mode 100644
index 00000000..7076ac0c
--- /dev/null
+++ b/club/tests/test_mailing.py
@@ -0,0 +1,327 @@
+from django.conf import settings
+from django.test import TestCase
+from django.urls import reverse
+from django.utils import timezone
+from django.utils.translation import gettext as _
+
+from club.forms import MailingForm
+from club.models import Club, Mailing, Membership
+from core.models import User
+
+
+class TestMailingForm(TestCase):
+ """Perform validation tests for MailingForm."""
+
+ @classmethod
+ def setUpTestData(cls):
+ cls.skia = User.objects.get(username="skia")
+ cls.rbatsbak = User.objects.get(username="rbatsbak")
+ cls.krophil = User.objects.get(username="krophil")
+ cls.comunity = User.objects.get(username="comunity")
+ cls.root = User.objects.get(username="root")
+ cls.club = Club.objects.get(id=settings.SITH_PDF_CLUB_ID)
+ cls.mail_url = reverse("club:mailing", kwargs={"club_id": cls.club.id})
+ Membership(
+ user=cls.rbatsbak,
+ club=cls.club,
+ start_date=timezone.now(),
+ role=settings.SITH_CLUB_ROLES_ID["Board member"],
+ ).save()
+
+ def test_mailing_list_add_no_moderation(self):
+ # Test with Communication admin
+ self.client.force_login(self.comunity)
+ response = self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "foyer"},
+ )
+ self.assertRedirects(response, self.mail_url)
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ assert "Liste de diffusion foyer@utbm.fr" in response.content.decode()
+
+ # Test with Root
+ self.client.force_login(self.root)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ assert "Liste de diffusion mde@utbm.fr" in response.content.decode()
+
+ def test_mailing_list_add_moderation(self):
+ self.client.force_login(self.rbatsbak)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+ assert "Liste de diffusion mde@utbm.fr" not in content
+ assert "
Listes de diffusions en attente de modération
" in content
+ assert "mde@utbm.fr" in content
+
+ def test_mailing_list_forbidden(self):
+ # With anonymous user
+ response = self.client.get(self.mail_url)
+ self.assertContains(response, "", status_code=403)
+
+ # With user not in club
+ self.client.force_login(self.krophil)
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 403
+
+ def test_add_new_subscription_fail_not_moderated(self):
+ self.client.force_login(self.rbatsbak)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.skia.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ assert "skia@git.an" not in response.content.decode()
+
+ def test_add_new_subscription_success(self):
+ # Prepare mailing list
+ self.client.force_login(self.comunity)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+
+ # Add single user
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.skia.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ assert "skia@git.an" in response.content.decode()
+
+ # Add multiple users
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": (self.comunity.id, self.rbatsbak.id),
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+ assert "richard@git.an" in content
+ assert "comunity@git.an" in content
+ assert "skia@git.an" in content
+
+ # Add arbitrary email
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_email": "arbitrary@git.an",
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+ assert "richard@git.an" in content
+ assert "comunity@git.an" in content
+ assert "skia@git.an" in content
+ assert "arbitrary@git.an" in content
+
+ # Add user and arbitrary email
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_email": "more.arbitrary@git.an",
+ "subscription_users": self.krophil.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+ assert "richard@git.an" in content
+ assert "comunity@git.an" in content
+ assert "skia@git.an" in content
+ assert "arbitrary@git.an" in content
+ assert "more.arbitrary@git.an" in content
+ assert "krophil@git.an" in content
+
+ def test_add_new_subscription_fail_form_errors(self):
+ # Prepare mailing list
+ self.client.force_login(self.comunity)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+
+ # Neither email or email is specified
+ response = self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ assert response.status_code
+ self.assertInHTML(
+ _("You must specify at least an user or an email address"),
+ response.content.decode(),
+ )
+
+ # No mailing specified
+ response = self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.krophil.id,
+ },
+ )
+ assert response.status_code == 200
+ assert _("This field is required") in response.content.decode()
+
+ # One of the selected users doesn't exist
+ response = self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": [789],
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ assert response.status_code == 200
+ self.assertInHTML(
+ _("You must specify at least an user or an email address"),
+ response.content.decode(),
+ )
+
+ # An user has no email address
+ self.krophil.email = ""
+ self.krophil.save()
+
+ response = self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.krophil.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ assert response.status_code == 200
+ self.assertInHTML(
+ _("One of the selected users doesn't have an email address"),
+ response.content.decode(),
+ )
+
+ self.krophil.email = "krophil@git.an"
+ self.krophil.save()
+
+ # An user is added twice
+
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.krophil.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+
+ response = self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": self.krophil.id,
+ "subscription_mailing": Mailing.objects.get(email="mde").id,
+ },
+ )
+ assert response.status_code == 200
+ self.assertInHTML(
+ _("This email is already suscribed in this mailing"),
+ response.content.decode(),
+ )
+
+ def test_remove_subscription_success(self):
+ # Prepare mailing list
+ self.client.force_login(self.comunity)
+ self.client.post(
+ self.mail_url,
+ {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
+ )
+ mde = Mailing.objects.get(email="mde")
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
+ "subscription_users": (
+ self.comunity.id,
+ self.rbatsbak.id,
+ self.krophil.id,
+ ),
+ "subscription_mailing": mde.id,
+ },
+ )
+
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+
+ assert "comunity@git.an" in content
+ assert "richard@git.an" in content
+ assert "krophil@git.an" in content
+
+ # Delete one user
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
+ "removal_%d" % mde.id: mde.subscriptions.get(user=self.krophil).id,
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+
+ assert "comunity@git.an" in content
+ assert "richard@git.an" in content
+ assert "krophil@git.an" not in content
+
+ # Delete multiple users
+ self.client.post(
+ self.mail_url,
+ {
+ "action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
+ "removal_%d" % mde.id: [
+ user.id
+ for user in mde.subscriptions.filter(
+ user__in=[self.rbatsbak, self.comunity]
+ ).all()
+ ],
+ },
+ )
+ response = self.client.get(self.mail_url)
+ assert response.status_code == 200
+ content = response.content.decode()
+
+ assert "comunity@git.an" not in content
+ assert "richard@git.an" not in content
+ assert "krophil@git.an" not in content
diff --git a/club/tests.py b/club/tests/test_membership.py
similarity index 56%
rename from club/tests.py
rename to club/tests/test_membership.py
index 217f29f6..dd77e52e 100644
--- a/club/tests.py
+++ b/club/tests/test_membership.py
@@ -1,96 +1,15 @@
-#
-# Copyright 2023 © AE UTBM
-# ae@utbm.fr / ae.info@utbm.fr
-#
-# This file is part of the website of the UTBM Student Association (AE UTBM),
-# https://ae.utbm.fr.
-#
-# You can find the source code of the website at https://github.com/ae-utbm/sith
-#
-# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
-# SEE : https://raw.githubusercontent.com/ae-utbm/sith/master/LICENSE
-# OR WITHIN THE LOCAL FILE "LICENSE"
-#
-#
-from datetime import timedelta
-
-import pytest
from django.conf import settings
from django.core.cache import cache
-from django.test import Client, TestCase
from django.urls import reverse
-from django.utils import timezone
from django.utils.timezone import localdate, localtime, now
-from django.utils.translation import gettext as _
from model_bakery import baker
-from pytest_django.asserts import assertRedirects
-from club.forms import MailingForm
-from club.models import Club, Mailing, Membership
+from club.models import Membership
+from club.tests.base import TestClub
from core.baker_recipes import subscriber_user
from core.models import AnonymousUser, User
-class TestClub(TestCase):
- """Set up data for test cases related to clubs and membership.
-
- The generated dataset is the one created by the populate command,
- plus the following modifications :
-
- - `self.club` is a dummy club recreated for each test
- - `self.club` has two board members : skia (role 3) and comptable (role 10)
- - `self.club` has one regular member : richard
- - `self.club` has one former member : sli (who had role 2)
- - None of the `self.club` members are in the AE club.
- """
-
- @classmethod
- def setUpTestData(cls):
- # subscribed users - initial members
- cls.skia = User.objects.get(username="skia")
- # by default, Skia is in the AE, which creates side effect
- cls.skia.memberships.all().delete()
- cls.richard = User.objects.get(username="rbatsbak")
- cls.comptable = User.objects.get(username="comptable")
- cls.sli = User.objects.get(username="sli")
- cls.root = User.objects.get(username="root")
-
- # subscribed users - not initial members
- cls.krophil = User.objects.get(username="krophil")
- cls.subscriber = User.objects.get(username="subscriber")
-
- # old subscriber
- cls.old_subscriber = User.objects.get(username="old_subscriber")
-
- # not subscribed
- cls.public = User.objects.get(username="public")
-
- cls.ae = Club.objects.get(pk=settings.SITH_MAIN_CLUB_ID)
- cls.club = baker.make(Club)
- cls.members_url = reverse("club:club_members", kwargs={"club_id": cls.club.id})
- a_month_ago = now() - timedelta(days=30)
- yesterday = now() - timedelta(days=1)
- Membership.objects.create(
- club=cls.club, user=cls.skia, start_date=a_month_ago, role=3
- )
- Membership.objects.create(club=cls.club, user=cls.richard, role=1)
- Membership.objects.create(
- club=cls.club, user=cls.comptable, start_date=a_month_ago, role=10
- )
-
- # sli was a member but isn't anymore
- Membership.objects.create(
- club=cls.club,
- user=cls.sli,
- start_date=a_month_ago,
- end_date=yesterday,
- role=2,
- )
-
- def setUp(self):
- cache.clear()
-
-
class TestMembershipQuerySet(TestClub):
def test_ongoing(self):
"""Test that the ongoing queryset method returns the memberships that
@@ -215,7 +134,7 @@ class TestMembershipQuerySet(TestClub):
assert set(user.groups.all()).isdisjoint(club_groups)
-class TestClubModel(TestClub):
+class TestMembership(TestClub):
def assert_membership_started_today(self, user: User, role: int):
"""Assert that the given membership is active and started today."""
membership = user.memberships.ongoing().filter(club=self.club).first()
@@ -564,368 +483,3 @@ class TestClubModel(TestClub):
new_board = set(self.club.board_group.users.values_list("id", flat=True))
assert new_members == initial_members
assert new_board == initial_board
-
-
-class TestMailingForm(TestCase):
- """Perform validation tests for MailingForm."""
-
- @classmethod
- def setUpTestData(cls):
- cls.skia = User.objects.get(username="skia")
- cls.rbatsbak = User.objects.get(username="rbatsbak")
- cls.krophil = User.objects.get(username="krophil")
- cls.comunity = User.objects.get(username="comunity")
- cls.root = User.objects.get(username="root")
- cls.club = Club.objects.get(id=settings.SITH_PDF_CLUB_ID)
- cls.mail_url = reverse("club:mailing", kwargs={"club_id": cls.club.id})
- Membership(
- user=cls.rbatsbak,
- club=cls.club,
- start_date=timezone.now(),
- role=settings.SITH_CLUB_ROLES_ID["Board member"],
- ).save()
-
- def test_mailing_list_add_no_moderation(self):
- # Test with Communication admin
- self.client.force_login(self.comunity)
- response = self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "foyer"},
- )
- self.assertRedirects(response, self.mail_url)
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- assert "Liste de diffusion foyer@utbm.fr" in response.content.decode()
-
- # Test with Root
- self.client.force_login(self.root)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- assert "Liste de diffusion mde@utbm.fr" in response.content.decode()
-
- def test_mailing_list_add_moderation(self):
- self.client.force_login(self.rbatsbak)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
- assert "Liste de diffusion mde@utbm.fr" not in content
- assert "Listes de diffusions en attente de modération
" in content
- assert "mde@utbm.fr" in content
-
- def test_mailing_list_forbidden(self):
- # With anonymous user
- response = self.client.get(self.mail_url)
- self.assertContains(response, "", status_code=403)
-
- # With user not in club
- self.client.force_login(self.krophil)
- response = self.client.get(self.mail_url)
- assert response.status_code == 403
-
- def test_add_new_subscription_fail_not_moderated(self):
- self.client.force_login(self.rbatsbak)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
-
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.skia.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- assert "skia@git.an" not in response.content.decode()
-
- def test_add_new_subscription_success(self):
- # Prepare mailing list
- self.client.force_login(self.comunity)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
-
- # Add single user
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.skia.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- assert "skia@git.an" in response.content.decode()
-
- # Add multiple users
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": (self.comunity.id, self.rbatsbak.id),
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
- assert "richard@git.an" in content
- assert "comunity@git.an" in content
- assert "skia@git.an" in content
-
- # Add arbitrary email
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_email": "arbitrary@git.an",
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
- assert "richard@git.an" in content
- assert "comunity@git.an" in content
- assert "skia@git.an" in content
- assert "arbitrary@git.an" in content
-
- # Add user and arbitrary email
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_email": "more.arbitrary@git.an",
- "subscription_users": self.krophil.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
- assert "richard@git.an" in content
- assert "comunity@git.an" in content
- assert "skia@git.an" in content
- assert "arbitrary@git.an" in content
- assert "more.arbitrary@git.an" in content
- assert "krophil@git.an" in content
-
- def test_add_new_subscription_fail_form_errors(self):
- # Prepare mailing list
- self.client.force_login(self.comunity)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
-
- # Neither email or email is specified
- response = self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- assert response.status_code
- self.assertInHTML(
- _("You must specify at least an user or an email address"),
- response.content.decode(),
- )
-
- # No mailing specified
- response = self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.krophil.id,
- },
- )
- assert response.status_code == 200
- assert _("This field is required") in response.content.decode()
-
- # One of the selected users doesn't exist
- response = self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": [789],
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- assert response.status_code == 200
- self.assertInHTML(
- _("You must specify at least an user or an email address"),
- response.content.decode(),
- )
-
- # An user has no email address
- self.krophil.email = ""
- self.krophil.save()
-
- response = self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.krophil.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- assert response.status_code == 200
- self.assertInHTML(
- _("One of the selected users doesn't have an email address"),
- response.content.decode(),
- )
-
- self.krophil.email = "krophil@git.an"
- self.krophil.save()
-
- # An user is added twice
-
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.krophil.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
-
- response = self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": self.krophil.id,
- "subscription_mailing": Mailing.objects.get(email="mde").id,
- },
- )
- assert response.status_code == 200
- self.assertInHTML(
- _("This email is already suscribed in this mailing"),
- response.content.decode(),
- )
-
- def test_remove_subscription_success(self):
- # Prepare mailing list
- self.client.force_login(self.comunity)
- self.client.post(
- self.mail_url,
- {"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
- )
- mde = Mailing.objects.get(email="mde")
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_NEW_SUBSCRIPTION,
- "subscription_users": (
- self.comunity.id,
- self.rbatsbak.id,
- self.krophil.id,
- ),
- "subscription_mailing": mde.id,
- },
- )
-
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
-
- assert "comunity@git.an" in content
- assert "richard@git.an" in content
- assert "krophil@git.an" in content
-
- # Delete one user
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
- "removal_%d" % mde.id: mde.subscriptions.get(user=self.krophil).id,
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
-
- assert "comunity@git.an" in content
- assert "richard@git.an" in content
- assert "krophil@git.an" not in content
-
- # Delete multiple users
- self.client.post(
- self.mail_url,
- {
- "action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
- "removal_%d" % mde.id: [
- user.id
- for user in mde.subscriptions.filter(
- user__in=[self.rbatsbak, self.comunity]
- ).all()
- ],
- },
- )
- response = self.client.get(self.mail_url)
- assert response.status_code == 200
- content = response.content.decode()
-
- assert "comunity@git.an" not in content
- assert "richard@git.an" not in content
- assert "krophil@git.an" not in content
-
-
-class TestClubSellingView(TestCase):
- """Perform basics tests to ensure that the page is available."""
-
- @classmethod
- def setUpTestData(cls):
- cls.club = baker.make(Club)
- cls.admin = baker.make(User, is_superuser=True)
-
- def test_page_not_internal_error(self):
- """Test that the page does not return and internal error."""
- self.client.force_login(self.admin)
- response = self.client.get(
- reverse("club:club_sellings", kwargs={"club_id": self.club.id})
- )
- assert response.status_code == 200
-
-
-@pytest.mark.django_db
-def test_club_board_member_cannot_edit_club_properties(client: Client):
- user = subscriber_user.make()
- club = baker.make(Club, name="old name", is_active=True, address="old address")
- baker.make(Membership, club=club, user=user, role=7)
- client.force_login(user)
- res = client.post(
- reverse("club:club_edit", kwargs={"club_id": club.id}),
- {"name": "new name", "is_active": False, "address": "new address"},
- )
- # The request should success,
- # but admin-only fields shouldn't be taken into account
- assertRedirects(res, club.get_absolute_url())
- club.refresh_from_db()
- assert club.name == "old name"
- assert club.is_active
- assert club.address == "new address"
-
-
-@pytest.mark.django_db
-def test_edit_club_page_doesnt_crash(client: Client):
- """crash test for club:club_edit"""
- club = baker.make(Club)
- user = subscriber_user.make()
- baker.make(Membership, club=club, user=user, role=3)
- client.force_login(user)
- res = client.get(reverse("club:club_edit", kwargs={"club_id": club.id}))
- assert res.status_code == 200
diff --git a/club/tests/test_sales.py b/club/tests/test_sales.py
new file mode 100644
index 00000000..ad4733de
--- /dev/null
+++ b/club/tests/test_sales.py
@@ -0,0 +1,16 @@
+import pytest
+from django.test import Client
+from django.urls import reverse
+from model_bakery import baker
+
+from club.models import Club
+from core.models import User
+
+
+@pytest.mark.django_db
+def test_sales_page_doesnt_crash(client: Client):
+ club = baker.make(Club)
+ admin = baker.make(User, is_superuser=True)
+ client.force_login(admin)
+ response = client.get(reverse("club:club_sellings", kwargs={"club_id": club.id}))
+ assert response.status_code == 200