Add tests for gvawebcore

This commit adds tests for gvawebcore.forms and gvawebcore.views.
This commit is contained in:
Jan Dittberner 2015-11-22 14:43:02 +00:00
parent b11055807f
commit 28fc535f9e
3 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,29 @@
"""
This module contains tests for :py:mod:`gvawebcore.forms`.
"""
from unittest import TestCase
from gvawebcore.forms import PasswordModelFormMixin, PASSWORD_MISMATCH_ERROR
class PasswordModelFormMixinTest(TestCase):
def test_form_properties(self):
form = PasswordModelFormMixin()
self.assertIn('password1', form.fields)
self.assertIn('password2', form.fields)
def test_clean_password_same(self):
form = PasswordModelFormMixin(data={
'password1': 'secret', 'password2': 'secret'})
self.assertTrue(form.is_valid())
self.assertEqual('secret', form.clean_password2())
def test_clean_password_different(self):
form = PasswordModelFormMixin(data={
'password1': 'onesecret', 'password2': 'other'})
self.assertFalse(form.is_valid())
self.assertIn('password2', form.errors)
self.assertIn(PASSWORD_MISMATCH_ERROR, form.errors['password2'])

View file

@ -0,0 +1,34 @@
"""
This model contains tests for :py:mod:`gvawebcore.views`.
"""
from unittest import TestCase
from mock import patch, Mock
from gvawebcore.views import HostingPackageAndCustomerMixin
class HostingPackageAndCustomerMixinTest(TestCase):
class TestView(HostingPackageAndCustomerMixin):
kwargs = {'package': '1'}
@patch('gvawebcore.views.get_object_or_404')
def test_get_hosting_package(self, get_object_or_404):
get_object_or_404.return_value = 'A package'
view = self.TestView()
self.assertEqual('A package', view.get_hosting_package())
def test_get_hosting_package_cached(self):
view = self.TestView()
view.hostingpackage = 'Cached package'
self.assertEqual('Cached package', view.get_hosting_package())
@patch('gvawebcore.views.get_object_or_404')
def test_get_customer_object(self, get_object_or_404):
get_object_or_404.return_value = Mock(customer='A customer')
view = self.TestView()
self.assertEqual('A customer', view.get_customer_object())