tests.py
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from rolepermissions.shortcuts import assign_role
from users.models import User
# from django.core import mail
class LoginTestCase(TestCase):
def setUp(self):
self.client = Client()
self.user = User.objects.create_user(
username = 'test',
email = 'testing@amadeus.com',
is_staff = True,
is_active = True,
password = 'testing'
)
assign_role(self.user, 'system_admin')
self.url = reverse('core:home')
def test_ok(self):
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'index.html')
data = {'username': 'test', 'password': 'testing'}
response = self.client.post(self.url, data)
self.assertRedirects(response, reverse("app:index"))
# def test_not_ok(self):
# response = self.client.get(self.url)
# self.assertEquals(response.status_code, 200)
# self.assertTemplateUsed(response, 'index.html')
# data = {'username': 'test', 'password': 'senhaerrada'}
# response = self.client.post(self.url, data)
# self.assertTrue('message' in response.context)
# self.assertEquals(response.context['message'], "Email ou senha incorretos!")
class RegisterUserTestCase(TestCase):
def setUp(self):
self.client = Client()
self.url = reverse('core:register')
def test_register_ok(self):
response = self.client.post(self.url,
data={
'username': 'testeamadeus',
'email': 'teste@amadeus.com',
'password': 'aminhasenha1',
'password2': 'aminhasenha1',
'name': 'Teste Amadeus',
'city': 'Praia',
'state': 'PE',
'gender': 'F',
})
self.assertRedirects(response, 'http://localhost%s' % reverse('core:home'))
self.assertEqual(response.status_code, 302)
self.assertEqual(User.objects.count(), 1)