diff options
-rw-r--r-- | ctrack/register/tests/test_views.py | 61 | ||||
-rw-r--r-- | ctrack/register/urls.py | 5 |
2 files changed, 53 insertions, 13 deletions
diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py index 21496b4..ed5d900 100644 --- a/ctrack/register/tests/test_views.py +++ b/ctrack/register/tests/test_views.py @@ -1,16 +1,16 @@ import pytest -from django.urls import reverse from django.test import TestCase - -test_case = TestCase("run") +from django.urls import reverse from ctrack.register.views import SingleDateTimeEventCreate +# Doing this allows us to use TestCase assertions (assertIn, etc) +test_case = TestCase("run") + pytestmark = pytest.mark.django_db class TestSingleDateTimeEvent: - def test_add_single_datetime_event_form(self, client): url = reverse("register:event_create_simple_event") response = client.get(url) @@ -30,20 +30,54 @@ class TestSingleDateTimeEvent: # We're keeping the use field out of the form assert "user" not in form.fields - def test_add_incorrect_form_data_single_datetime(self, client): + @pytest.mark.parametrize("bad_date,expected_error", [ + ("NOT A DATE", "Enter a valid date/time."), + ("202002-10-12", "Enter a valid date/time."), + ("32 May 2020", "Enter a valid date/time."), + ("May 2020", "Enter a valid date/time.") + ]) + def test_bad_date(self, bad_date, expected_error, client): url = reverse("register:event_create_simple_event") data = { - "type_descriptor": "Meeting X", + "type_descriptor": "MEETING", "short_description": "Test Short Description", - "datetime": "2010-10-10", + "datetime": bad_date, "comments": "Blah...", - "location": "The Moon" + "location": "The Moon", } response = client.post(url, data) assert response.status_code == 200 html = response.content.decode("utf-8") - test_case.assertIn("Select a valid choice. Meeting X is not one of the available choices.", html) + test_case.assertIn(expected_error, html) + @pytest.mark.parametrize( + "bad_type,expected_error", + [ + ( + "Meeting X", + "Select a valid choice. Meeting X is not one of the available choices.", + ), + ( + "Meeting Bunting Radgehead", + "Select a valid choice. Meeting Bunting Radgehead is not one of the available choices.", + ), + ], + ) + def test_add_incorrect_form_data_single_datetime( + self, bad_type, expected_error, client + ): + url = reverse("register:event_create_simple_event") + data = { + "type_descriptor": bad_type, + "short_description": "Test Short Description", + "datetime": "2010-10-10", + "comments": "Blah...", + "location": "The Moon", + } + response = client.post(url, data) + assert response.status_code == 200 + html = response.content.decode("utf-8") + test_case.assertIn(expected_error, html) def test_user_passed_as_kwarg(self, user, request_factory): view = SingleDateTimeEventCreate() @@ -53,8 +87,9 @@ class TestSingleDateTimeEvent: view.setup(request) assert "user" in view.get_form_kwargs() -class TestSingleDateCAFEventViews: - - def test_initial_caf_recevied(self, client): - pass +class TestSingleDateCAFEventViews: + def test_initial_caf_received(self, client): + url = reverse("register:event_create_caf_single_date_event") + response = client.get(url) + assert response.status_code == 200 diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py index b6ee408..1cdd92f 100644 --- a/ctrack/register/urls.py +++ b/ctrack/register/urls.py @@ -30,4 +30,9 @@ urlpatterns = [ view=SingleDateTimeEventCreate.as_view(), name="event_create_simple_event", ), + # path( + # "event/create-caf-single-date-event", + # view=CAFSingleDateEventView.as_view(), + # name="create_caf_single_date_event" + # ) ] |