From aa343e46247b6a55bd0d26dad1d0b9dabaf04851 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 13 Oct 2020 10:19:20 +0100 Subject: first VERY BASIC view test working --- .../templates/single_datetime_event_create.html | 4 +++ ctrack/register/tests/test_views.py | 35 +++++++++++++++++----- ctrack/register/urls.py | 26 +++++++++++----- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 ctrack/register/templates/single_datetime_event_create.html (limited to 'ctrack/register') diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/single_datetime_event_create.html new file mode 100644 index 0000000..94a5162 --- /dev/null +++ b/ctrack/register/templates/single_datetime_event_create.html @@ -0,0 +1,4 @@ +{% extends "base.html" %} +{% block content %} + {{ form }} +{% endblock %} diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py index 51fceac..089cb9e 100644 --- a/ctrack/register/tests/test_views.py +++ b/ctrack/register/tests/test_views.py @@ -1,18 +1,39 @@ import pytest +from django.test import Client +from django.urls import reverse from ctrack.register.views import SingleDateTimeEventCreate +from ctrack.users.models import User pytestmark = pytest.mark.django_db -class TestSingleDateFormView: - def test_single_datetime_event_form(self, user, request_factory): +class TestMeetingEventFormView: + def test_add_meeting_form(self, user): + client = Client() + client.force_login(user) + url = reverse("register:event_create_singledatetime") + response = client.get(url) + assert response.status_code == 200 + + form = response.context_data["form"] + assert not form.is_bound + expected_fields = [ + "type_descriptor", + "short_description", + "datetime", + "comments", + "location", + ] + for field in expected_fields: + assert field in form.fields + # We're keeping the use field out of the form + assert "user" not in form.fields + + def test_user_passed_as_kwarg(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 + view.setup(request) + assert "user" in view.get_form_kwargs() diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py index d5c21cb..fb05a02 100644 --- a/ctrack/register/urls.py +++ b/ctrack/register/urls.py @@ -1,21 +1,33 @@ from django.urls import path -from ctrack.register.views import EngagementEventCreate, EngagementEventDelete, EngagementEventCreateFromCaf, \ - SingleDateTimeEventCreate +from ctrack.register.views import ( + EngagementEventCreate, + EngagementEventDelete, + EngagementEventCreateFromCaf, + SingleDateTimeEventCreate, +) app_name = "register" urlpatterns = [ path( - "engagement-event/create/from-org/", view=EngagementEventCreate.as_view(), name="create", + "engagement-event/create/from-org/", + view=EngagementEventCreate.as_view(), + name="create", ), path( - "engagement-event/delete//for-org/", view=EngagementEventDelete.as_view(), name="ee_delete" + "engagement-event/delete//for-org/", + view=EngagementEventDelete.as_view(), + name="ee_delete", ), path( - "engagement-event/create/from-caf/", view=EngagementEventCreateFromCaf.as_view(), name="create_from_caf" + "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" - ) + "event/create-single-datetime", + view=SingleDateTimeEventCreate.as_view(), + name="event_create_singledatetime", + ), ] -- cgit v1.2.3