From 29028b60b46693c2ad9e786a61bd5e94bf6c7fa6 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 12 Oct 2020 20:33:04 +0100 Subject: first view test for events --- ctrack/register/tests/test_views.py | 18 ++++++++++++++++++ ctrack/register/urls.py | 6 +++++- ctrack/register/views.py | 13 ++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 ctrack/register/tests/test_views.py (limited to 'ctrack') diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py new file mode 100644 index 0000000..51fceac --- /dev/null +++ b/ctrack/register/tests/test_views.py @@ -0,0 +1,18 @@ +import pytest + +from ctrack.register.views import SingleDateTimeEventCreate + +pytestmark = pytest.mark.django_db + + +class TestSingleDateFormView: + def test_single_datetime_event_form(self, user, request_factory): + view = SingleDateTimeEventCreate() + request = request_factory.get("/register/event/create-single-datetime/") + request.user = user + view.request = request + response = SingleDateTimeEventCreate.as_view()(request) + assert response.status_code == 200 + assert not response.context_data["form"].is_bound + for k in ["type_descriptor", "short_description", "datetime", "comments", "location"]: + assert k in response.context_data["form"].fields diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py index c5afb73..d5c21cb 100644 --- a/ctrack/register/urls.py +++ b/ctrack/register/urls.py @@ -1,6 +1,7 @@ from django.urls import path -from ctrack.register.views import EngagementEventCreate, EngagementEventDelete, EngagementEventCreateFromCaf +from ctrack.register.views import EngagementEventCreate, EngagementEventDelete, EngagementEventCreateFromCaf, \ + SingleDateTimeEventCreate app_name = "register" @@ -13,5 +14,8 @@ urlpatterns = [ ), path( "engagement-event/create/from-caf/", view=EngagementEventCreateFromCaf.as_view(), name="create_from_caf" + ), + path( + "event/create-single-datetime", view=SingleDateTimeEventCreate.as_view(), name="event_create_singledatetime" ) ] diff --git a/ctrack/register/views.py b/ctrack/register/views.py index eb2d748..b60d2be 100644 --- a/ctrack/register/views.py +++ b/ctrack/register/views.py @@ -6,7 +6,7 @@ from django.views.generic import FormView, DeleteView from ctrack.caf.models import CAF from ctrack.organisations.models import Organisation -from ctrack.register.forms import EngagementEventCreateForm +from ctrack.register.forms import EngagementEventCreateForm, AddMeetingForm from ctrack.register.models import EngagementEvent @@ -70,3 +70,14 @@ class EngagementEventCreateFromCaf(LoginRequiredMixin, FormView): def get_success_url(self): org_slug = CAF.objects.get(pk=self.kwargs["caf_id"]).organisation.slug return reverse_lazy("organisations:detail", args=[org_slug]) + + +class SingleDateTimeEventCreate(LoginRequiredMixin, FormView): + template_name = "single_datetime_event_create.html" + form_class = AddMeetingForm + success_url = "/" + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs["user"] = self.request.user + return kwargs -- cgit v1.2.3