def test_contactus_form_is_valid(self):
     form = ContactUsForm(data={
         "contact_id": "1",
         "name": "John Doe",
         "email": "*****@*****.**",
         "subject": "Test subject",
         "message": "Hi this is a test message",
     }, )
     self.assertTrue(form.is_valid())
示例#2
0
    def test_form_clean(self):
        form = ContactUsForm()
        form._errors = {}
        form.cleaned_data = {
            'decoy': '',
            'subject': 'other'
        }

        form.clean()
        self.assertEquals(len(form._errors.keys()), 0)
示例#3
0
    def test_form_clean_errors(self):
        form = ContactUsForm()
        form._errors = {}
        form.cleaned_data = {
            'decoy': 'foo',
            'subject': '-----'
        }

        form.clean()
        self.assertEquals(len(form._errors.keys()), 2)
        self.assertTrue('decoy' in form._errors)
        self.assertTrue('subject' in form._errors)
示例#4
0
def homepage_view(request):
    form = ContactUsForm(request.POST or None)
    successMsg = ""
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        #message success
        messages.success(request, "Your request has been submitted!")
        return HttpResponseRedirect('/contactus')
    title = "Homepage"
    nbar = "homepage"
    context = {
        "form": form,
        "title": title,
        "nbar": nbar,
    }
    return render(request, 'home_page.html', context)
示例#5
0
def homepage_view(request):
    form = ContactUsForm(request.POST or None)
    successMsg = ""
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        #message success
        messages.success(request, "Your request has been submitted!")
        return HttpResponseRedirect('/contactus')
    title = "Homepage"
    nbar = "homepage"
    context = {
        "form": form,
        "title": title,
        "nbar": nbar,
    }
    return render(request, 'home_page.html', context)
示例#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, 'root@localhost')
        self.assertEquals(mail.outbox[0].to, [settings.CONTACT_US_EMAIL])
示例#7
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])
示例#8
0
    def test_form_clean(self):
        form = ContactUsForm()
        form._errors = {}
        form.cleaned_data = {
            'decoy': '',
            'subject': 'other'
        }

        form.clean()
        self.assertEquals(len(form._errors.keys()), 0)
示例#9
0
    def test_form_clean_errors(self):
        form = ContactUsForm()
        form._errors = {}
        form.cleaned_data = {
            'decoy': 'foo',
            'subject': '-----'
        }

        form.clean()
        self.assertEquals(len(form._errors.keys()), 2)
        self.assertTrue('decoy' in form._errors)
        self.assertTrue('subject' in form._errors)
 def test_contactus_form_is_invalid(self):
     form = ContactUsForm(data={}, )
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 4)