2016-08-10 20:23:17 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2016-09-09 23:47:07 +00:00
|
|
|
from django.contrib.auth.models import User, Group
|
|
|
|
from django.test import Client
|
|
|
|
|
2016-09-12 10:19:00 +00:00
|
|
|
from .models import Project,Task
|
2016-09-09 23:47:07 +00:00
|
|
|
|
2016-08-10 20:23:17 +00:00
|
|
|
# Create your tests here.
|
2016-09-09 23:47:07 +00:00
|
|
|
|
|
|
|
class TestUser(TestCase):
|
2016-09-12 10:19:00 +00:00
|
|
|
|
|
|
|
fixtures = ['test_users', ]
|
|
|
|
|
2016-09-09 23:47:07 +00:00
|
|
|
def setUp(self):
|
|
|
|
self.credentials = {
|
|
|
|
'username': 'testuser',
|
2016-09-12 10:19:00 +00:00
|
|
|
'password': 'test1234',
|
2016-09-09 23:47:07 +00:00
|
|
|
'email': 'test@mail.com'}
|
|
|
|
|
2016-09-12 10:19:00 +00:00
|
|
|
# Create a test Group
|
2016-09-09 23:47:07 +00:00
|
|
|
my_group, created = Group.objects.get_or_create(name='test_group')
|
2016-09-12 10:19:00 +00:00
|
|
|
|
|
|
|
# Add user to test Group
|
|
|
|
User.objects.get(pk=1).groups.add(my_group)
|
2016-09-09 23:47:07 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_User_Login_Test(self):
|
|
|
|
c = Client()
|
|
|
|
# User points the browser to the landing page
|
2016-09-10 12:08:31 +00:00
|
|
|
res = c.post('/', follow=True)
|
2016-09-09 23:47:07 +00:00
|
|
|
|
2016-09-10 00:17:11 +00:00
|
|
|
# the user is not logged in
|
2016-09-09 23:47:07 +00:00
|
|
|
self.assertFalse(res.context['user'].is_authenticated)
|
2016-09-10 00:17:11 +00:00
|
|
|
# and is redirected to the login page
|
2016-09-09 23:47:07 +00:00
|
|
|
self.assertRedirects(res, '/login/')
|
|
|
|
|
2016-09-10 12:08:31 +00:00
|
|
|
# The login page is being rendered by the correct template
|
2016-09-09 23:47:07 +00:00
|
|
|
self.assertTemplateUsed(res, 'registration/login.html')
|
|
|
|
|
2016-09-10 12:08:31 +00:00
|
|
|
# asks the user to login using a set of valid credentials
|
|
|
|
res = c.post('/login/', data=self.credentials, follow=True)
|
2016-09-09 23:57:08 +00:00
|
|
|
|
|
|
|
# The system acknowledges him
|
2016-09-09 23:47:07 +00:00
|
|
|
self.assertTrue(res.context['user'].is_authenticated)
|
|
|
|
|
2016-09-09 23:57:08 +00:00
|
|
|
# and moves him at the dashboard
|
2016-09-09 23:47:07 +00:00
|
|
|
self.assertTemplateUsed(res, 'app/dashboard.html')
|