OpenDroneMap-WebODM/app/tests.py

50 wiersze
1.4 KiB
Python
Czysty Zwykły widok Historia

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
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):
fixtures = ['test_users', ]
2016-09-09 23:47:07 +00:00
def setUp(self):
self.credentials = {
'username': 'testuser',
'password': 'test1234',
2016-09-09 23:47:07 +00:00
'email': 'test@mail.com'}
# Create a test Group
2016-09-09 23:47:07 +00:00
my_group, created = Group.objects.get_or_create(name='test_group')
# 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
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/')
# The login page is being rendered by the correct template
2016-09-09 23:47:07 +00:00
self.assertTemplateUsed(res, 'registration/login.html')
# 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')