Pylint happiness!
This commit is contained in:
@@ -1,22 +1,37 @@
|
||||
# -*- coding: utf-8
|
||||
"""
|
||||
Account management module for the Duck Booking Tool backend
|
||||
"""
|
||||
|
||||
from django.test import TestCase, Client
|
||||
from django_webtest import WebTest
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
|
||||
class FrontTest(TestCase):
|
||||
"""
|
||||
Test front-end capabilities of the accounts module
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
self.admin = User.objects.create_user(
|
||||
username = 'admin',
|
||||
password = 'password')
|
||||
self.admin.save()
|
||||
self.admin = User.objects.create_user(username='admin',
|
||||
password='password')
|
||||
|
||||
def test_login_page(self):
|
||||
"""
|
||||
Test for the existence of the login page
|
||||
"""
|
||||
|
||||
response = self.client.get('/accounts/login')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_login(self):
|
||||
"""
|
||||
Test login functionality
|
||||
"""
|
||||
|
||||
response = self.client.post('/accounts/login', {
|
||||
'next': '/',
|
||||
'username': 'admin',
|
||||
@@ -25,17 +40,33 @@ class FrontTest(TestCase):
|
||||
self.assertRedirects(response, '/')
|
||||
|
||||
def test_logout(self):
|
||||
self.client.login(username = 'admin', password = 'aeou')
|
||||
"""
|
||||
Test the logout page
|
||||
"""
|
||||
|
||||
self.client.login(username='admin', password='aeou')
|
||||
|
||||
response = self.client.get('/accounts/logout')
|
||||
self.assertRedirects(response, '/')
|
||||
|
||||
def test_registration_page(self):
|
||||
"""
|
||||
Test for existence of the registration page
|
||||
"""
|
||||
|
||||
response = self.client.get('/accounts/register')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
class RegFormTest(WebTest):
|
||||
"""
|
||||
Test case for the registration form
|
||||
"""
|
||||
|
||||
def test_valid_data(self):
|
||||
"""
|
||||
Test valid registration without actual HTTP requests
|
||||
"""
|
||||
|
||||
form_data = {
|
||||
'username': 'test',
|
||||
'password1': 'password',
|
||||
@@ -51,6 +82,10 @@ class RegFormTest(WebTest):
|
||||
self.assertNotEqual(user.password, 'password')
|
||||
|
||||
def test_empty(self):
|
||||
"""
|
||||
Test empty registration form
|
||||
"""
|
||||
|
||||
form_data = {}
|
||||
form = UserCreationForm(form_data)
|
||||
self.assertFalse(form.is_valid())
|
||||
@@ -61,11 +96,19 @@ class RegFormTest(WebTest):
|
||||
})
|
||||
|
||||
def test_form_error(self):
|
||||
"""
|
||||
Test incomplete registration
|
||||
"""
|
||||
|
||||
page = self.app.get('/accounts/register')
|
||||
page = page.form.submit()
|
||||
self.assertContains(page, "This field is required.")
|
||||
|
||||
def test_form_success(self):
|
||||
"""
|
||||
Test for successful registrations
|
||||
"""
|
||||
|
||||
page = self.app.get('/accounts/register')
|
||||
page.form['username'] = 'test'
|
||||
page.form['password1'] = 'password'
|
||||
|
@@ -1,24 +1,28 @@
|
||||
from django.conf.urls import patterns, url
|
||||
# -*- coding: utf-8
|
||||
"""
|
||||
URL patterns for the accounts module
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import RegistrationFormView
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
urlpatterns = [
|
||||
url(
|
||||
r'^register$',
|
||||
RegistrationFormView.as_view(),
|
||||
name = 'register'
|
||||
name='register'
|
||||
),
|
||||
url(
|
||||
r'^login$',
|
||||
'django.contrib.auth.views.login',
|
||||
{'template_name': 'accounts/login.html'},
|
||||
name = 'login'
|
||||
name='login'
|
||||
),
|
||||
url(
|
||||
r'^logout$',
|
||||
'django.contrib.auth.views.logout',
|
||||
{'next_page': 'booking:list'},
|
||||
name = 'logout'
|
||||
name='logout'
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@@ -1,3 +1,8 @@
|
||||
# -*- coding: utf-8
|
||||
"""
|
||||
Views for the accounts module
|
||||
"""
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.views import generic
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -5,14 +10,26 @@ from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
|
||||
class RegistrationFormView(generic.View):
|
||||
"""
|
||||
Class to display the registration form
|
||||
"""
|
||||
|
||||
form_class = UserCreationForm
|
||||
template_name = 'accounts/registration.html'
|
||||
|
||||
def get(self, request):
|
||||
"""
|
||||
Implementation of the GET method
|
||||
"""
|
||||
|
||||
form = self.form_class()
|
||||
return render(request, self.template_name, { 'form': form })
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
||||
def post(self, request):
|
||||
"""
|
||||
Implementation of the POST method
|
||||
"""
|
||||
|
||||
form = self.form_class(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
|
Reference in New Issue
Block a user