Skip to content

Commit feb1456

Browse files
committed
Tests sobre o envio de e-mail criado
1 parent dda82d6 commit feb1456

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed
1 Byte
Binary file not shown.

core/templates/contact.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% block container %}
1010
<div class="page-header">
1111
<h1>Fale conosco</h1>
12-
{% if sucess %}
12+
{% if success %}
1313
<div class="alert alert-success">
1414
Mensagem enviada com sucesso!
1515
</div>
1.26 KB
Binary file not shown.

core/tests/test_views.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.test import TestCase, Client
44
from django.core.urlresolvers import reverse
5+
from django.core import mail
56

67
class IndexViewTestCase(TestCase):
78

@@ -19,4 +20,29 @@ def test_status_code(self):
1920
def test_template_used(self):
2021
response = self.client.get(self.url)
2122
self.assertTemplateUsed(response, 'index.html')
22-
23+
24+
25+
class ContactViewTestCase(TestCase):
26+
27+
def setUp(self):
28+
self.client = Client()
29+
self.url = reverse('contact')
30+
31+
def test_view_ok(self):
32+
response = self.client.get(self.url)
33+
self.assertEquals(response.status_code, 200)
34+
self.assertTemplateUsed(response, 'contact.html')
35+
36+
def test_form(self):
37+
data = {'name': '', 'message': '', 'email': ''}
38+
response = self.client.post(self.url, data)
39+
self.assertFormError(response, 'form','name', 'Este campo é obrigatório.')
40+
self.assertFormError(response, 'form','email', 'Este campo é obrigatório.')
41+
self.assertFormError(response, 'form','message', 'Este campo é obrigatório.')
42+
43+
def test_form_ok(self):
44+
data = {'name': 'test', 'message': 'test', 'email': 'teste@test.com'}
45+
response = self.client.post(self.url, data)
46+
self.assertTrue(response.context['success'])
47+
self.assertEquals(len(mail.outbox), 1)
48+
self.assertEquals(mail.outbox[0].subject, 'Contato do Django E-commerce')

core/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def index(request):
1313

1414

1515
def contact(request):
16-
sucess = False
16+
success = False
1717
form = ContactForm(request.POST or None)
1818
if form.is_valid():
1919
form.send_mail()
20-
sucess = True
20+
success = True
2121
context = {
2222
'form': form,
23-
'sucess': sucess
23+
'success': success
2424
}
2525
return render(request, 'contact.html', context)

0 commit comments

Comments
 (0)