Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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])
Ejemplo n.º 6
0
    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"),
]