def test_contact_form_missing_subject_error(self): """ Should return 400 with missing subject """ with mock.patch.object(Contact, 'has_valid_captcha', return_value=True): class_instance = Contact() self.assertTrue( class_instance.has_valid_captcha(request={}, data={})) contact_data = { "captcha": "myRandomCaptcha", "email": "*****@*****.**", "message": "myMessageThatIsAtLeast10Chars" } response = self.client.post(self.contact_url, data=json.dumps(contact_data), content_type='application/json') self.assertTrue(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue(response.json()["subject"], "This field is required.")
def test_contact_form_successfully_submitted(self): """ Should submit valid contact info successfully """ with mock.patch.object(Contact, 'has_valid_captcha', return_value=True): class_instance = Contact() self.assertTrue( class_instance.has_valid_captcha(request={}, data={})) contact_data = { "email": "*****@*****.**", "captcha": "myRandomCaptcha", "subject": "mySubject", "message": "myMessageThatIsAtleast10Chars" } response = self.client.post(self.contact_url, data=json.dumps(contact_data), content_type='application/json') self.assertTrue(response.status_code, status.HTTP_200_OK) self.assertTrue(response.json()["message"], "Message will be delivered. Thank you.")
"""openbook_org URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path, include from openbook_org_common.views import Health from openbook_org_contact.views import Contact, WaitlistSubscribeView urlpatterns = [ path('health/', Health.as_view(), name='health'), path('contact/', Contact.as_view(), name='contact'), path('waitlist/subscribe/', WaitlistSubscribeView.as_view(), name='waitlist_subscribe') ]
"""openbook_org URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path, include from openbook_org_contact.views import Contact urlpatterns = [path('contact/', Contact.as_view())]