Added unit tests for welcome page

pull/203/head
Piero Toffanin 2017-06-09 09:45:23 -04:00
rodzic f9fa297605
commit b7ce0f964c
3 zmienionych plików z 76 dodań i 4 usunięć

Wyświetl plik

@ -4,8 +4,8 @@
{% block registration_header %}
{% if not firstuserform.errors %}
<canvas id="canvas" style="position: absolute;"></canvas>
<script type="javascript">
<canvas id="canvas" style="position: absolute; top: 0; left: 0;"></canvas>
<script type="text/javascript">
// Confetti animation
(function () {
// globals

Wyświetl plik

@ -0,0 +1,72 @@
from django.contrib.auth.models import User, Group
from django.test import Client
from rest_framework import status
from app.models import Project, Task
from .classes import BootTestCase
from app import scheduler
from django.core.exceptions import ValidationError
class TestWelcome(BootTestCase):
def setUp(self):
Project.objects.all().delete()
# Start with no users
User.objects.all().delete()
def tearDown(self):
pass
def test_first_screen(self):
c = Client()
# User points the browser to the website
res = c.get('/', follow=True)
# User is redirected to the welcome page
self.assertRedirects(res, '/welcome/')
# The welcome page is being rendered by the correct template
self.assertTemplateUsed(res, 'app/welcome.html')
# User cannot create an admin user without password
res = c.post('/welcome/', data={
'username': 'testadminuser',
'password': ''}, follow=True)
self.assertFormError(res, 'firstuserform', 'password', 'This field is required.')
self.assertTrue(User.objects.count() == 0, 'No users were created')
# User can create admin user
res = c.post('/welcome/', data={
'username': 'testadminuser',
'password': 'testadminpass'}, follow=True)
self.assertTrue(User.objects.count() == 1, 'A user was created')
# User was created
user = User.objects.get(username='testadminuser')
self.assertTrue(user.is_superuser, 'The user is a superuser')
self.assertTrue(user.is_staff, 'The user is a staff member')
# Redirect to the dashboard happens
self.assertRedirects(res, '/dashboard/')
# User is automatically logged-in
self.assertTrue(res.context['user'].is_authenticated)
# After a super admin is created, the welcome page is no longer accessible
res = c.get('/welcome/', follow=True)
self.assertRedirects(res, '/dashboard/')
# We cannot create another superuser
res = c.post('/welcome/', data={
'username': 'testadminuser2',
'password': 'testadminpass2'}, follow=True)
self.assertRedirects(res, '/dashboard/')
self.assertTrue(User.objects.filter(username='testadminuser2').count() == 0, 'No users were created')
# If we log-out and try to access the welcome page, we should get the login page
c.logout()
res = c.get('/welcome/', follow=True)
self.assertRedirects(res, '/login/')

Wyświetl plik

@ -120,10 +120,10 @@ def welcome(request):
if User.objects.filter(is_superuser=True).count() > 0:
return redirect('index')
fuf = FirstUserForm(prefix='user')
fuf = FirstUserForm()
if request.method == 'POST':
fuf = FirstUserForm(request.POST, prefix='user')
fuf = FirstUserForm(request.POST)
if fuf.is_valid():
admin_user = fuf.save(commit=False)
admin_user.is_superuser = admin_user.is_staff = True