2017-04-24 15:51:12 +00:00
|
|
|
# -*- coding:utf-8 -*
|
|
|
|
#
|
2023-04-04 17:17:44 +00:00
|
|
|
# Copyright 2023 © AE UTBM
|
|
|
|
# ae@utbm.fr / ae.info@utbm.fr
|
2017-04-24 15:51:12 +00:00
|
|
|
#
|
2023-04-04 17:17:44 +00:00
|
|
|
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
|
|
|
# https://ae.utbm.fr.
|
2017-04-24 15:51:12 +00:00
|
|
|
#
|
2023-04-04 17:17:44 +00:00
|
|
|
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
2017-04-24 15:51:12 +00:00
|
|
|
#
|
2023-04-04 17:17:44 +00:00
|
|
|
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE"
|
2017-04-24 15:51:12 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2016-12-21 01:38:21 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.conf import settings
|
2019-10-06 11:28:56 +00:00
|
|
|
from django.urls import reverse
|
2016-12-21 01:38:21 +00:00
|
|
|
from django.core.management import call_command
|
2019-08-16 14:59:13 +00:00
|
|
|
from django.utils import html
|
2022-08-03 22:26:43 +00:00
|
|
|
from django.utils.translation import gettext as _
|
2019-08-16 14:59:13 +00:00
|
|
|
|
2016-12-21 01:38:21 +00:00
|
|
|
|
|
|
|
from core.models import User, RealGroup
|
2017-06-12 06:59:03 +00:00
|
|
|
|
2016-12-21 01:38:21 +00:00
|
|
|
|
2019-08-29 15:29:38 +00:00
|
|
|
class ComAlertTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
|
|
|
|
|
|
|
def test_page_is_working(self):
|
|
|
|
self.client.login(username="comunity", password="plop")
|
|
|
|
response = self.client.get(reverse("com:alert_edit"))
|
2022-08-03 19:48:37 +00:00
|
|
|
self.assertNotEqual(response.status_code, 500)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-08-29 15:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ComInfoTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
|
|
|
|
|
|
|
def test_page_is_working(self):
|
|
|
|
self.client.login(username="comunity", password="plop")
|
|
|
|
response = self.client.get(reverse("com:info_edit"))
|
2022-08-03 19:48:37 +00:00
|
|
|
self.assertNotEqual(response.status_code, 500)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-08-29 15:29:38 +00:00
|
|
|
|
|
|
|
|
2016-12-21 01:38:21 +00:00
|
|
|
class ComTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
|
|
|
self.skia = User.objects.filter(username="skia").first()
|
2018-10-04 19:29:19 +00:00
|
|
|
self.com_group = RealGroup.objects.filter(
|
|
|
|
id=settings.SITH_GROUP_COM_ADMIN_ID
|
|
|
|
).first()
|
2019-10-06 00:15:18 +00:00
|
|
|
self.skia.groups.set([self.com_group])
|
2016-12-21 01:38:21 +00:00
|
|
|
self.skia.save()
|
2018-10-04 19:29:19 +00:00
|
|
|
self.client.login(username=self.skia.username, password="plop")
|
2016-12-21 01:38:21 +00:00
|
|
|
|
|
|
|
def test_alert_msg(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("com:alert_edit"),
|
|
|
|
{
|
|
|
|
"alert_msg": """
|
2016-12-21 01:38:21 +00:00
|
|
|
### ALERTE!
|
|
|
|
|
|
|
|
**Caaaataaaapuuuulte!!!!**
|
2018-10-04 19:29:19 +00:00
|
|
|
"""
|
|
|
|
},
|
|
|
|
)
|
2016-12-21 01:38:21 +00:00
|
|
|
r = self.client.get(reverse("core:index"))
|
|
|
|
self.assertTrue(r.status_code == 200)
|
2021-09-25 00:52:13 +00:00
|
|
|
self.assertContains(
|
|
|
|
r,
|
|
|
|
"""<div id="alert_box">
|
2023-04-04 17:17:44 +00:00
|
|
|
<div class="markdown"><h3>ALERTE!</h3>
|
2021-09-25 00:52:13 +00:00
|
|
|
<p><strong>Caaaataaaapuuuulte!!!!</strong></p>""",
|
2018-10-04 19:29:19 +00:00
|
|
|
)
|
2016-12-21 01:38:21 +00:00
|
|
|
|
|
|
|
def test_info_msg(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("com:info_edit"),
|
|
|
|
{
|
|
|
|
"info_msg": """
|
2016-12-21 01:38:21 +00:00
|
|
|
### INFO: **Caaaataaaapuuuulte!!!!**
|
2018-10-04 19:29:19 +00:00
|
|
|
"""
|
|
|
|
},
|
|
|
|
)
|
2016-12-21 01:38:21 +00:00
|
|
|
r = self.client.get(reverse("core:index"))
|
|
|
|
self.assertTrue(r.status_code == 200)
|
2021-09-25 00:52:13 +00:00
|
|
|
self.assertContains(
|
|
|
|
r,
|
|
|
|
"""<div id="info_box">
|
2023-04-04 17:17:44 +00:00
|
|
|
<div class="markdown"><h3>INFO: <strong>Caaaataaaapuuuulte!!!!</strong></h3>""",
|
2018-10-04 19:29:19 +00:00
|
|
|
)
|
2019-08-16 14:59:13 +00:00
|
|
|
|
|
|
|
def test_birthday_non_subscribed_user(self):
|
|
|
|
self.client.login(username="guy", password="plop")
|
|
|
|
response = self.client.get(reverse("core:index"))
|
|
|
|
self.assertContains(
|
|
|
|
response,
|
|
|
|
text=html.escape(
|
|
|
|
_("You need an up to date subscription to access this content")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_birthday_subscibed_user(self):
|
|
|
|
response = self.client.get(reverse("core:index"))
|
|
|
|
|
|
|
|
self.assertNotContains(
|
|
|
|
response,
|
|
|
|
text=html.escape(
|
|
|
|
_("You need an up to date subscription to access this content")
|
|
|
|
),
|
|
|
|
)
|