Commit 241673eb8190b2b588263badc5f019cc7cdbbb63
1 parent
b084b599
Exists in
master
and in
5 other branches
Finished delete link Test [Issue:#125]
Showing
1 changed file
with
11 additions
and
4 deletions
Show diff stats
links/tests.py
1 | 1 | from django.test import TestCase,Client |
2 | 2 | from django.core.urlresolvers import reverse |
3 | 3 | from rolepermissions.shortcuts import assign_role |
4 | +from django.utils.translation import ugettext_lazy as _ | |
4 | 5 | |
5 | 6 | from users.models import User |
6 | 7 | from .models import * |
8 | +from .forms import * | |
7 | 9 | |
8 | 10 | # Create your tests here. |
9 | 11 | class LinkTestCase(TestCase): |
... | ... | @@ -28,8 +30,10 @@ class LinkTestCase(TestCase): |
28 | 30 | "link" : 'teste.com' |
29 | 31 | } |
30 | 32 | response = self.client.post(url, data) |
33 | + #self.assertEqual(response.status_code, 200) | |
34 | + self.assertFormError(response,'form',"link",_("Please enter a valid URL")) | |
31 | 35 | self.assertEqual(Link.objects.all().count(),links+1) #After creating one link, if OK, the link was created successfully. |
32 | - self.assertEqual(response.status_code, 200) | |
36 | + self.assertEqual(response.status_code, 302) #If OK, User is getting redirected correctly. | |
33 | 37 | self.assertTemplateUsed(template_name = 'links/link_modal.html') |
34 | 38 | # def test_update_link(): |
35 | 39 | # pass |
... | ... | @@ -41,8 +45,11 @@ class LinkTestCase(TestCase): |
41 | 45 | ) |
42 | 46 | self.client.login(username='user', password = 'testing') |
43 | 47 | links = Link.objects.all().count() |
48 | + deletedlink = Link.objects.get(name = self.link.name) | |
44 | 49 | url = reverse('course:delete_link',kwargs={'linkname': self.link.name}) |
45 | 50 | self.assertEqual(Link.objects.all().count(),links) |
46 | - response = self.client.get(url) | |
47 | - self.assertEqual(Link.objects.all().count(),links - 1) | |
48 | - self.assertEqual(response.status_code, 200) | |
51 | + response = self.client.post(url) | |
52 | + self.assertEqual(Link.objects.all().count(),links - 1) #Objeto removido | |
53 | + self.assertEqual(Link.objects.filter(name= deletedlink.name).exists(),False) #Objeto removido e sua não-existência verificada | |
54 | + #self.assertEqual(Link.objects.filter(name= deletedlink.name).exists(),True) #Objeto removido e sua existência verificada, se ERRO, objeto foi removido com sucesso! | |
55 | + self.assertEqual(response.status_code, 302) #If OK, User is getting redirected correctly. | ... | ... |