Verified Commit 5a965045 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Blacken and reorder imports



On events tests and commands

Signed-off-by: VAN ZUIJLEN Nils's avatarNils VAN ZUIJLEN <nils.van-zuijlen@mailo.com>
parent 888344f8
import datetime
from zoneinfo import ZoneInfo
from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone
import datetime
from events.models import RecurrentEvent
......
import datetime
import uuid
from datetime import timezone
from freezegun import freeze_time
from io import StringIO
import uuid
from zoneinfo import ZoneInfo
from django.contrib.auth.models import User
from django.core.management import call_command
from django.templatetags.static import static
from django.test import TestCase
from freezegun import freeze_time
from .models import Event
from .models import ExternInscription
from .models import ExternLink
from .models import Inscription
from .models import Invitation
from .models import RecurrentEvent
from bde.models import Contributor
from .models import Event, Inscription, ExternInscription, ExternLink, Invitation, RecurrentEvent
class TestEvent(TestCase):
def setUp(self):
self.event = Event.objects.create(
name="test",
end_inscriptions=datetime.datetime(2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc),
end_inscriptions=datetime.datetime(
2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc
),
start_time=datetime.datetime(2014, 7, 14, 13, 0, 0, tzinfo=timezone.utc),
end_time=datetime.datetime(2014, 7, 14, 14, 0, 0, tzinfo=timezone.utc),
location="location",
......@@ -26,30 +35,29 @@ class TestEvent(TestCase):
private=False,
limited=False,
max_inscriptions=0,
allow_extern=False
allow_extern=False,
)
def do_inscriptions(self, event, nb, extern=False):
users = []
if extern:
ext = ExternLink.objects.create(
event=event,
uuid=uuid.uuid4(),
maximum=10,
name=uuid.uuid4()
event=event, uuid=uuid.uuid4(), maximum=10, name=uuid.uuid4()
)
for i in range(nb):
if extern:
ExternInscription.objects.create(
mail='{}@lol.com'.format(uuid.uuid4()),
mail="{}@lol.com".format(uuid.uuid4()),
first_name="f",
last_name="l",
event=event,
via=ext
via=ext,
)
else:
u = User.objects.create_user(str(uuid.uuid4())[:30], 'AAA{}@exemple.com'.format(i), 'AAA')
u = User.objects.create_user(
str(uuid.uuid4())[:30], "AAA{}@exemple.com".format(i), "AAA"
)
Inscription.objects.create(user=u, event=event)
return users
......@@ -63,10 +71,12 @@ class TestEvent(TestCase):
self.assertTrue(self.event.closed())
def test_photo_url(self):
self.assertEqual(self.event.photo_url(), static('images/default_event_icon.png'))
self.assertEqual(
self.event.photo_url(), static("images/default_event_icon.png")
)
self.event.photo = "coucou.png"
self.event.save()
self.assertEqual(self.event.photo_url(), '/medias/coucou.png')
self.assertEqual(self.event.photo_url(), "/medias/coucou.png")
def test_can_subscribe(self):
self.assertTrue(self.event.can_subscribe())
......@@ -88,68 +98,127 @@ class TestEvent(TestCase):
def test_external_link(self):
ext = ExternLink.objects.create(
event=self.event,
uuid=uuid.uuid4(),
maximum=10,
name=uuid.uuid4()
event=self.event, uuid=uuid.uuid4(), maximum=10, name=uuid.uuid4()
)
for i in range(5):
ExternInscription.objects.create(
mail='{}@lol.com'.format(uuid.uuid4()),
mail="{}@lol.com".format(uuid.uuid4()),
first_name="f",
last_name="l",
event=self.event,
via=ext
via=ext,
)
self.assertTrue(ext.places_left())
for i in range(5):
ExternInscription.objects.create(
mail='{}@lol.com'.format(uuid.uuid4()),
mail="{}@lol.com".format(uuid.uuid4()),
first_name="f",
last_name="l",
event=self.event,
via=ext
via=ext,
)
self.assertFalse(ext.places_left())
@freeze_time("2014-07-14 11:00:00")
def test_to_come(self):
# Event open
e1 = Event.objects.create(name="test", end_inscriptions=datetime.datetime(2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc), start_time=datetime.datetime(2014, 7, 14, 13, 0, 0, tzinfo=timezone.utc), end_time=datetime.datetime(2014, 7, 14, 14, 0, 0, tzinfo=timezone.utc), location="location", description="description", price=0, photo="", private=False, limited=False, max_inscriptions=0, allow_extern=False)
e1 = Event.objects.create(
name="test",
end_inscriptions=datetime.datetime(
2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc
),
start_time=datetime.datetime(2014, 7, 14, 13, 0, 0, tzinfo=timezone.utc),
end_time=datetime.datetime(2014, 7, 14, 14, 0, 0, tzinfo=timezone.utc),
location="location",
description="description",
price=0,
photo="",
private=False,
limited=False,
max_inscriptions=0,
allow_extern=False,
)
# Private event
e2 = Event.objects.create(name="test2", end_inscriptions=datetime.datetime(2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc), start_time=datetime.datetime(2014, 7, 14, 13, 0, 0, tzinfo=timezone.utc), end_time=datetime.datetime(2014, 7, 14, 14, 0, 0, tzinfo=timezone.utc), location="location", description="description", price=0, photo="", private=True, limited=False, max_inscriptions=0, allow_extern=False)
e2 = Event.objects.create(
name="test2",
end_inscriptions=datetime.datetime(
2014, 7, 14, 12, 0, 0, tzinfo=timezone.utc
),
start_time=datetime.datetime(2014, 7, 14, 13, 0, 0, tzinfo=timezone.utc),
end_time=datetime.datetime(2014, 7, 14, 14, 0, 0, tzinfo=timezone.utc),
location="location",
description="description",
price=0,
photo="",
private=True,
limited=False,
max_inscriptions=0,
allow_extern=False,
)
# Closed private event
Event.objects.create(name="test3", end_inscriptions=datetime.datetime(2014, 7, 13, 12, 0, 0, tzinfo=timezone.utc), start_time=datetime.datetime(2014, 7, 13, 13, 0, 0, tzinfo=timezone.utc), end_time=datetime.datetime(2014, 7, 13, 14, 0, 0, tzinfo=timezone.utc), location="location", description="description", price=0, photo="", private=True, limited=False, max_inscriptions=0, allow_extern=False)
Event.objects.create(
name="test3",
end_inscriptions=datetime.datetime(
2014, 7, 13, 12, 0, 0, tzinfo=timezone.utc
),
start_time=datetime.datetime(2014, 7, 13, 13, 0, 0, tzinfo=timezone.utc),
end_time=datetime.datetime(2014, 7, 13, 14, 0, 0, tzinfo=timezone.utc),
location="location",
description="description",
price=0,
photo="",
private=True,
limited=False,
max_inscriptions=0,
allow_extern=False,
)
# Closed event
Event.objects.create(name="test4", end_inscriptions=datetime.datetime(2014, 7, 13, 12, 0, 0, tzinfo=timezone.utc), start_time=datetime.datetime(2014, 7, 13, 13, 0, 0, tzinfo=timezone.utc), end_time=datetime.datetime(2014, 7, 13, 14, 0, 0, tzinfo=timezone.utc), location="location", description="description", price=0, photo="", private=False, limited=False, max_inscriptions=0, allow_extern=False)
Event.objects.create(
name="test4",
end_inscriptions=datetime.datetime(
2014, 7, 13, 12, 0, 0, tzinfo=timezone.utc
),
start_time=datetime.datetime(2014, 7, 13, 13, 0, 0, tzinfo=timezone.utc),
end_time=datetime.datetime(2014, 7, 13, 14, 0, 0, tzinfo=timezone.utc),
location="location",
description="description",
price=0,
photo="",
private=False,
limited=False,
max_inscriptions=0,
allow_extern=False,
)
u = User.objects.create_user(str(uuid.uuid4())[:30], 'BBB@exemple.com', 'AAA')
u = User.objects.create_user(str(uuid.uuid4())[:30], "BBB@exemple.com", "AAA")
Inscription.objects.create(user=u, event=e2)
u2 = User.objects.create_user(str(uuid.uuid4())[:30], 'CCC@exemple.com', 'AAA')
u2 = User.objects.create_user(str(uuid.uuid4())[:30], "CCC@exemple.com", "AAA")
self.assertEqual(Event.to_come(u), [(0, self.event), (0, e1), (1, e2)])
self.assertEqual(Event.to_come(u2), [(0, self.event), (0, e1)])
def test_invitations(self):
u = User.objects.create_user(str(uuid.uuid4())[:30], 'BBB@exemple.com', 'AAA')
u = User.objects.create_user(str(uuid.uuid4())[:30], "BBB@exemple.com", "AAA")
self.assertFalse(self.event.can_invite(u))
self.event.allow_invitations = True
self.event.save()
self.assertFalse(self.event.can_invite(u))
Contributor.take_full_contribution(u, 'cash')
Contributor.take_full_contribution(u, "cash")
self.assertTrue(self.event.can_invite(u))
self.event.max_invitations = 1
self.event.save()
self.assertTrue(self.event.can_invite(u))
Invitation.objects.create(mail="coucou@lol.com",
first_name="f",
last_name="l",
event=self.event,
user=u)
Invitation.objects.create(
mail="coucou@lol.com",
first_name="f",
last_name="l",
event=self.event,
user=u,
)
self.assertFalse(self.event.can_invite(u))
self.event.max_invitations = 2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment