OpenDroneMap-WebODM/app/tests.py

51 wiersze
1.5 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
2016-08-10 20:23:17 +00:00
# Create your tests here.
2016-09-09 23:47:07 +00:00
class TestUser(TestCase):
def setUp(self):
self.credentials = {
'username': 'testuser',
'password': 'secret',
'email': 'test@mail.com'}
self.u = User.objects.create_user(
username=self.credentials['username'],
email=self.credentials['email'],
password=self.credentials['password'],
is_superuser=True
)
my_group, created = Group.objects.get_or_create(name='test_group')
self.u.groups.add(my_group)
def tearDown(self):
pass
def test_User_Login_Test(self):
c = Client()
# User points the browser to the landing page
res = c.get('/')
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-09 23:57:08 +00:00
# The login page
2016-09-09 23:47:07 +00:00
res = c.get('/login/')
2016-09-10 00:17:11 +00:00
# is being rendered by the correct template
2016-09-09 23:47:07 +00:00
self.assertTemplateUsed(res, 'registration/login.html')
2016-09-10 00:17:11 +00:00
# askes the user to login using a set of valid credentials
2016-09-09 23:47:07 +00:00
res = c.post('/login/', 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')