Skip to content

Commit

Permalink
Fixed udlejning and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersSeverinsen committed Sep 15, 2024
1 parent bae1c83 commit f2fb181
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 27 deletions.
35 changes: 35 additions & 0 deletions bartenders/migrations/0003_auto_20240915_2045.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.4 on 2024-09-15 18:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bartenders", "0002_ballotlink_poll"),
]

operations = [
migrations.AlterField(
model_name="bartender",
name="email",
field=models.CharField(
blank=True,
help_text="En post.au mail fungerer ikke",
max_length=255,
unique=True,
verbose_name="E-mail",
),
),
migrations.AlterField(
model_name="bartenderapplication",
name="email",
field=models.CharField(
blank=True,
help_text="En post.au mail fungerer ikke",
max_length=255,
unique=True,
verbose_name="E-mail",
),
),
]
9 changes: 8 additions & 1 deletion bartenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ class Meta:
username = models.CharField(
max_length=140, unique=True, verbose_name=_("Brugernavn")
)
email = models.CharField(max_length=255, unique=True, blank=True)
email = models.CharField(
max_length=255,
unique=True,
blank=True,
verbose_name=_("E-mail"),
help_text=_("En post.au mail fungerer ikke"),
)
studentNumber = models.IntegerField(
blank=True, null=True, verbose_name=_("Studienummer")
)
Expand Down Expand Up @@ -282,6 +288,7 @@ def _send_accept_email(self):
)

def accept(self):
self.email = self.email if self.email is None else self.email.lower()
common_fields = super()._meta.get_fields()
value_dict = {f.name: getattr(self, f.name) for f in common_fields}
b = Bartender.objects.create(**value_dict)
Expand Down
Binary file modified locale/da/LC_MESSAGES/django.mo
Binary file not shown.
26 changes: 17 additions & 9 deletions locale/da/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 02:00+0200\n"
"PO-Revision-Date: 2024-09-03 02:02+0050\n"
"POT-Creation-Date: 2024-09-15 20:46+0200\n"
"PO-Revision-Date: 2024-09-15 20:47+0050\n"
"Last-Translator: <abs@post.au.dk>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
Expand Down Expand Up @@ -105,34 +105,42 @@ msgid "Brugernavn"
msgstr ""

#: bartenders/models.py:57
msgid "E-mail"
msgstr ""

#: bartenders/models.py:58
msgid "En post.au mail fungerer ikke"
msgstr ""

#: bartenders/models.py:61
msgid "Studienummer"
msgstr ""

#: bartenders/models.py:60
#: bartenders/models.py:64
msgid "Telefonnummer"
msgstr ""

#: bartenders/models.py:67
#: bartenders/models.py:71
msgid "T-shirt størrelse"
msgstr ""

#: bartenders/models.py:75
#: bartenders/models.py:79
msgid "Jeg foretrækker ikke at have nogle sene barvagter"
msgstr ""

#: bartenders/models.py:231
#: bartenders/models.py:235
msgid "til"
msgstr ""

#: bartenders/models.py:236
#: bartenders/models.py:240
msgid "Studie"
msgstr ""

#: bartenders/models.py:237
#: bartenders/models.py:241
msgid "Årgang"
msgstr ""

#: bartenders/models.py:239
#: bartenders/models.py:243
msgid "Eventuelle ekstra info til bestyrelsen skrives her"
msgstr ""

Expand Down
Binary file modified locale/en/LC_MESSAGES/django.mo
Binary file not shown.
34 changes: 18 additions & 16 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 02:00+0200\n"
"PO-Revision-Date: 2024-09-03 02:02+0050\n"
"POT-Creation-Date: 2024-09-15 20:46+0200\n"
"PO-Revision-Date: 2024-09-15 20:47+0050\n"
"Last-Translator: <abs@post.au.dk>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
Expand Down Expand Up @@ -105,34 +105,43 @@ msgid "Brugernavn"
msgstr "Username"

#: bartenders/models.py:57
#| msgid "Email"
msgid "E-mail"
msgstr "E-mail"

#: bartenders/models.py:58
msgid "En post.au mail fungerer ikke"
msgstr "A post.au email does not work"

#: bartenders/models.py:61
msgid "Studienummer"
msgstr "Study number"

#: bartenders/models.py:60
#: bartenders/models.py:64
msgid "Telefonnummer"
msgstr "Phone number"

#: bartenders/models.py:67
#: bartenders/models.py:71
msgid "T-shirt størrelse"
msgstr "T-shirt size"

#: bartenders/models.py:75
#: bartenders/models.py:79
msgid "Jeg foretrækker ikke at have nogle sene barvagter"
msgstr "I prefer to not have any late shifts"

#: bartenders/models.py:231
#: bartenders/models.py:235
msgid "til"
msgstr "to"

#: bartenders/models.py:236
#: bartenders/models.py:240
msgid "Studie"
msgstr "Study"

#: bartenders/models.py:237
#: bartenders/models.py:241
msgid "Årgang"
msgstr "Year"

#: bartenders/models.py:239
#: bartenders/models.py:243
msgid "Eventuelle ekstra info til bestyrelsen skrives her"
msgstr "Any additional information for the board can be written here"

Expand Down Expand Up @@ -546,13 +555,6 @@ msgstr ""
"fully reflect reality."

#: items/templates/items.html:9
#| msgid ""
#| "\n"
#| "\tHer kan du se Fredagscaféens faste sortiment, og mange af de ting vi er kendte for at sælge. \n"
#| "\tMen derudover finder du altid et stort sortiment af spændende og nye specialøl, for enhver smag, i baren. \n"
#| "\tVi har i Fredagscaféen et stort fokus på at have noget for alle, så derfor finder du også flere \n"
#| "\tglutenfrie og alkoholfrie øl.\n"
#| "\t"
msgid ""
"\n"
"\tHer kan du se Fredagscaféens faste sortiment, og mange af de ting vi er kendte for at sælge.\n"
Expand Down
2 changes: 1 addition & 1 deletion udlejning/templates/udlejning.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h3>
{% translate "Ansøgninsformular" %}
</span>
</h3>
<form method="post" action="/udlejning/#rentingform">
<form method="post" action="/{{ LANGUAGE_CODE }}/udlejning/#rentingform">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
Expand Down
74 changes: 74 additions & 0 deletions udlejning/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
import datetime
import os

import pytz
from django.core import mail
from django.test import TestCase

from udlejning.models import Udlejning, UdlejningApplication


# Create your tests here.
class UdlejningApplicationTests(TestCase):
def setUp(self):
os.environ["RECAPTCHA_TESTING"] = "True"

def tearDown(self):
os.environ["RECAPTCHA_TESTING"] = "False"

def test_accepting_application(self):
d = dict(
dateFrom=datetime.datetime(2024, 9, 16, 16, 0, tzinfo=pytz.UTC),
dateTo=None,
whoReserved="Abekat",
contactEmail="kat@mail.dk",
contactPhone=42345123,
whoPays="AU",
paymentType="EAN",
EANnumber=1234567890123,
where="Nygaard-02",
expectedConsummation="Alt for meget",
comments="Igen kommentar",
)
ap = UdlejningApplication.objects.create(**d)
ap.accept()

# Test that an application has been created with the correct data
self.assertTrue(Udlejning.objects.exists())

def test_sending_application(self):
data = dict(
dateFrom=datetime.datetime(2024, 9, 16, 16, 0, tzinfo=pytz.UTC),
dateTo=datetime.datetime(2024, 9, 16, 22, 0, tzinfo=pytz.UTC),
whoReserved="Abekat",
contactEmail="kat@mail.dk",
contactPhone=42345123,
whoPays="AU",
paymentType="card",
where="Nygaard-02",
expectedConsummation="Alt for meget",
comments="Igen kommentar",
)

data["g-recaptcha-response"] = "PASSED"
response = self.client.post("/da/udlejning/#rentingform", data=data)
# self.assertRedirects(response, "/da/udlejning/")

# Test that application was made
self.assertTrue(UdlejningApplication.objects.exists())
# And mail was sent
self.assertEqual(len(mail.outbox), 1)

def test_invalid_application(self):
# Missing payment info
data = dict(
dateFrom=datetime.datetime(2024, 9, 16, 16, 0, tzinfo=pytz.UTC),
dateTo=datetime.datetime(2024, 9, 16, 22, 0, tzinfo=pytz.UTC),
whoReserved="Abekat",
contactEmail="kat@mail.dk",
contactPhone=42345123,
where="Nygaard-02",
expectedConsummation="Alt for meget",
comments="Igen kommentar",
)

self.client.post("/da/udlejning/", data=data)
self.assertFalse(UdlejningApplication.objects.exists())
self.assertEqual(len(mail.outbox), 0)

0 comments on commit f2fb181

Please sign in to comment.