2018-01-06 12:13:15 +01:00
|
|
|
import json
|
|
|
|
from datetime import timedelta
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
from django.test import TestCase
|
2018-01-06 12:13:15 +01:00
|
|
|
from django.utils import timezone
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
from .testcases import BdATestHelpers, BdAViewTestCaseMixin
|
2018-01-06 12:13:15 +01:00
|
|
|
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class InscriptionViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-tirage-inscription"
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
http_methods = ["GET", "POST"]
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
auth_user = "bda_member"
|
|
|
|
auth_forbidden = [None, "bda_other"]
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
bda_testdata = True
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/inscription/{}".format(self.tirage.id)
|
2018-01-06 12:13:15 +01:00
|
|
|
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class PlacesViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-places-attribuees"
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
auth_user = "bda_member"
|
|
|
|
auth_forbidden = [None, "bda_other"]
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
bda_testdata = True
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/places/{}".format(self.tirage.id)
|
2018-01-06 12:13:15 +01:00
|
|
|
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class EtatPlacesViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-etat-places"
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
auth_user = "bda_member"
|
|
|
|
auth_forbidden = [None, "bda_other"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/etat-places/{}".format(self.tirage.id)
|
|
|
|
|
|
|
|
|
|
|
|
class TirageViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-tirage"
|
|
|
|
|
|
|
|
http_methods = ["GET", "POST"]
|
|
|
|
|
|
|
|
auth_user = "bda_staff"
|
|
|
|
auth_forbidden = [None, "bda_other", "bda_member"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/tirage/{}".format(self.tirage.id)
|
|
|
|
|
|
|
|
def test_perform_tirage_disabled(self):
|
2018-01-06 12:13:15 +01:00
|
|
|
# Cannot be performed if disabled
|
|
|
|
self.tirage.enable_do_tirage = False
|
|
|
|
self.tirage.save()
|
2018-10-28 14:31:10 +01:00
|
|
|
resp = self.client.get(self.url)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertTemplateUsed(resp, "tirage-failed.html")
|
2018-10-28 14:31:10 +01:00
|
|
|
|
|
|
|
def test_perform_tirage_opened_registrations(self):
|
2018-01-06 12:13:15 +01:00
|
|
|
# Cannot be performed if registrations are still open
|
|
|
|
self.tirage.enable_do_tirage = True
|
|
|
|
self.tirage.fermeture = timezone.now() + timedelta(seconds=3600)
|
|
|
|
self.tirage.save()
|
2018-10-28 14:31:10 +01:00
|
|
|
resp = self.client.get(self.url)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertTemplateUsed(resp, "tirage-failed.html")
|
2018-10-28 14:31:10 +01:00
|
|
|
|
|
|
|
def test_perform_tirage(self):
|
2018-01-06 12:13:15 +01:00
|
|
|
# Otherwise, perform the tirage
|
2018-10-28 14:31:10 +01:00
|
|
|
self.tirage.enable_do_tirage = True
|
2018-01-06 12:13:15 +01:00
|
|
|
self.tirage.fermeture = timezone.now()
|
|
|
|
self.tirage.save()
|
2018-10-28 14:31:10 +01:00
|
|
|
resp = self.client.get(self.url)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertTemplateNotUsed(resp, "tirage-failed.html")
|
|
|
|
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class SpectacleListViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-liste-spectacles"
|
|
|
|
|
|
|
|
auth_user = "bda_staff"
|
|
|
|
auth_forbidden = [None, "bda_other", "bda_member"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/spectacles/{}".format(self.tirage.id)
|
|
|
|
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class SpectacleViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-spectacle"
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
auth_user = "bda_staff"
|
|
|
|
auth_forbidden = [None, "bda_other", "bda_member"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id, "spectacle_id": self.show1.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/spectacles/{}/{}".format(self.tirage.id, self.show1.id)
|
|
|
|
|
|
|
|
|
|
|
|
class UnpaidViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-unpaid"
|
|
|
|
|
|
|
|
auth_user = "bda_staff"
|
|
|
|
auth_forbidden = [None, "bda_other", "bda_member"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"tirage_id": self.tirage.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/spectacles/unpaid/{}".format(self.tirage.id)
|
|
|
|
|
|
|
|
|
|
|
|
class SendRemindersViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
url_name = "bda-rappels"
|
|
|
|
|
|
|
|
auth_user = "bda_staff"
|
|
|
|
auth_forbidden = [None, "bda_other", "bda_member"]
|
|
|
|
|
|
|
|
bda_testdata = True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_kwargs(self):
|
|
|
|
return {"spectacle_id": self.show1.id}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url_expected(self):
|
|
|
|
return "/bda/mails-rappel/{}".format(self.show1.id)
|
|
|
|
|
|
|
|
def test_post(self):
|
2018-01-07 14:30:33 +01:00
|
|
|
self.require_custommails()
|
2018-10-28 14:31:10 +01:00
|
|
|
resp = self.client.post(self.url)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertEqual(200, resp.status_code)
|
|
|
|
# TODO: check that emails are sent
|
|
|
|
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
class CatalogueViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase):
|
|
|
|
auth_user = None
|
|
|
|
auth_forbidden = []
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
bda_testdata = True
|
2018-01-06 12:13:15 +01:00
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
def test_api_list(self):
|
|
|
|
url_list = "/bda/catalogue/list"
|
|
|
|
resp = self.client.get(url_list)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertJSONEqual(
|
|
|
|
resp.content.decode("utf-8"),
|
2018-10-06 12:35:49 +02:00
|
|
|
[{"id": self.tirage.id, "title": self.tirage.title}],
|
2018-01-06 12:13:15 +01:00
|
|
|
)
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
def test_api_details(self):
|
|
|
|
url_details = "/bda/catalogue/details?id={}".format(self.tirage.id)
|
|
|
|
resp = self.client.get(url_details)
|
2018-01-06 12:13:15 +01:00
|
|
|
self.assertJSONEqual(
|
|
|
|
resp.content.decode("utf-8"),
|
|
|
|
{
|
2018-10-06 12:35:49 +02:00
|
|
|
"categories": [{"id": self.category.id, "name": self.category.name}],
|
|
|
|
"locations": [{"id": self.location.id, "name": self.location.name}],
|
|
|
|
},
|
2018-01-06 12:13:15 +01:00
|
|
|
)
|
|
|
|
|
2018-10-28 14:31:10 +01:00
|
|
|
def test_api_descriptions(self):
|
|
|
|
url_descriptions = "/bda/catalogue/descriptions?id={}".format(self.tirage.id)
|
|
|
|
resp = self.client.get(url_descriptions)
|
2018-01-06 12:13:15 +01:00
|
|
|
raw = resp.content.decode("utf-8")
|
|
|
|
try:
|
|
|
|
results = json.loads(raw)
|
|
|
|
except ValueError:
|
|
|
|
self.fail("Not valid JSON: {}".format(raw))
|
|
|
|
self.assertEqual(len(results), 3)
|
|
|
|
self.assertEqual(
|
|
|
|
{(s["title"], s["price"], s["slots"]) for s in results},
|
2018-10-06 12:35:49 +02:00
|
|
|
{("foo", 0, 42), ("bar", 1, 142), ("baz", 2, 242)},
|
2018-01-06 12:13:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestBdaRevente:
|
|
|
|
pass
|
|
|
|
# TODO
|