def test_event_create_valid_form(self): request = self.request_factory.post(reverse('events_create'), data={'title': 'event 1', 'description': 'event one', 'date_time': '2020-06-26 01:01:12'}) request.user = self.user1 response = EventCreate.as_view()(request, *[], **{}) self.assertEqual(response.status_code, HTTP_REDIRECT) self.assertRegexpMatches(response.url, '/events/[\\d]+')
from django.urls import include, path from events.views import (EventChangeWeight, EventCreate, EventDelete, EventDownloadXlsx, EventFinish, EventList, EventManageUsers, EventRemoveUser, EventSelfRegistration, EventUpdate, EventUploadXlsx) events_patterns = [ path( 'events/', include([ path('', EventList.as_view(), name='url_event_list'), path('create/', EventCreate.as_view(), name='url_event_create'), path( '<int:pk>/', include([ path('update/', EventUpdate.as_view(), name='url_event_update'), path('finish/', EventFinish.as_view(), name='url_event_finish'), path('delete/', EventDelete.as_view(), name='url_event_delete'), path('self_registration/', EventSelfRegistration.as_view(), name='url_event_self_registration'), path('users/', EventManageUsers.as_view(), name='url_event_manage_users'),
from django.urls import path, include from events.views import EventList, EventDetail, AllEventsGuests, EventGuests, EventCreate urlpatterns = [ path("events", EventList.as_view()), path("events/<int:pk>", EventDetail.as_view()), path("events/create", EventCreate.as_view()), path("events/guests", AllEventsGuests.as_view()), path("events/<int:pk>/guests", EventGuests.as_view()), # path('events/<int:pk>/', my_view) ]
def test_event_create_not_post(self): request = self.request_factory.get(reverse('events_create')) request.user = self.user1 response = EventCreate.as_view()(request, *[], **{}) self.assertEqual(response.status_code, HTTP_OK)
def test_event_create_invalid_form(self): request = self.request_factory.post(reverse('events_create')) request.user = self.user1 response = EventCreate.as_view()(request, *[], **{}) self.assertEqual(response.status_code, HTTP_OK) self.assertTrue(response.context_data['form'].errors)
def test_event_create_not_authenticated(self): request = self.request_factory.post(reverse('events_create')) request.user = AnonymousUser() response = EventCreate.as_view()(request, *[], **{}) self.assertEqual(response.status_code, HTTP_REDIRECT) self.assertIn(reverse('user_login'), response.url)
from django.conf.urls import url from django.contrib import admin from core.views import index from events.views import events_list, EventEdit, EventCreate, event_detail from events.models import EventForm urlpatterns = [ url(r'^(?P<pk>\d+)/$', event_detail, name="event_detail"), url(r'^$', events_list, name="events_list"), url(r'^edit/(?P<pk>\d+)/$', EventEdit.as_view(), name="event_edit"), url(r'^create/$', EventCreate.as_view(), name="event_create") ]