def test_get_initial_anonymous(self): view = ContactUsView() view.request = RequestFactory().get('/contact/') view.request.session = {} view.request.user = AnonymousUser() initial = view.get_initial() self.assertFalse('name' in initial) self.assertFalse('email' in initial)
def test_get_initial_not_anonymous(self): view = ContactUsView() view.request = RequestFactory().get('/contact/') view.request.session = {} view.request.user = User.objects.create( first_name='Foo', last_name='Bar', email='*****@*****.**') initial = view.get_initial() self.assertEquals(initial['name'], 'Foo Bar') self.assertEquals(initial['email'], '*****@*****.**') # a subsequent call using an anonymous session returns a clean initial view.request.session = {} view.request.user = AnonymousUser() initial = view.get_initial() self.assertFalse('name' in initial) self.assertFalse('email' in initial)
def test_form_valid(self): view = ContactUsView() view.request = RequestFactory().get('/contact/') view.request.user = AnonymousUser() form = ContactUsForm() form.cleaned_data = { 'name': 'Foo Bar', 'email': '*****@*****.**', 'subject': 'other', 'description': 'There is a problem' } view.form_valid(form) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, view.subject) self.assertEquals(mail.outbox[0].from_email, 'root@localhost') self.assertEquals(mail.outbox[0].to, [settings.CONTACT_US_EMAIL])
def test_form_valid(self): view = ContactUsView() view.request = RequestFactory().get('/contact/') view.request.user = AnonymousUser() form = ContactUsForm() form.cleaned_data = { 'name': 'Foo Bar', 'email': '*****@*****.**', 'subject': 'other', 'description': 'There is a problem' } view.form_valid(form) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, view.subject) self.assertEquals(mail.outbox[0].from_email, '*****@*****.**') self.assertEquals(mail.outbox[0].to, [settings.CONTACT_US_EMAIL])
from django.urls import path from contactus.views import ContactUsView app_name = "contactus" urlpatterns = [ path("", ContactUsView.as_view(), name="contactus"), ]