Add tests for gnuviechadmin.context_processors
This commit adds new tests for the gnuviechadmin.context_processors module. The module gnuviechadmin.tests has been moved into a separate directory for a more clear structure.
This commit is contained in:
parent
de0f3b8ca1
commit
7bcb0d3100
4 changed files with 144 additions and 7 deletions
2
gnuviechadmin/gnuviechadmin/tests/__init__.py
Normal file
2
gnuviechadmin/gnuviechadmin/tests/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# -*- python -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
129
gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py
Normal file
129
gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
# -*- python -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
This module contains tests for :py:mod:`gnuviechadmin.context_processors`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from mock import MagicMock
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from gnuviechadmin import __version__ as gvaversion
|
||||||
|
from gnuviechadmin.context_processors import navigation
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class NavigationContextProcessorTest(TestCase):
|
||||||
|
|
||||||
|
EXPECTED_ITEMS = (
|
||||||
|
'webmail_url', 'phpmyadmin_url', 'phppgadmin_url',
|
||||||
|
'active_item'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_ajax_request(self):
|
||||||
|
response = self.client.get(
|
||||||
|
'/', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertNotIn(item, response.context)
|
||||||
|
|
||||||
|
def _check_static_urls(self, context):
|
||||||
|
self.assertEqual(
|
||||||
|
context['webmail_url'], settings.GVA_LINK_WEBMAIL)
|
||||||
|
self.assertEqual(
|
||||||
|
context['phpmyadmin_url'], settings.GVA_LINK_PHPMYADMIN)
|
||||||
|
self.assertEqual(
|
||||||
|
context['phppgadmin_url'], settings.GVA_LINK_PHPPGADMIN)
|
||||||
|
|
||||||
|
def test_index_page_context(self):
|
||||||
|
response = self.client.get('/')
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertIn(item, response.context)
|
||||||
|
self._check_static_urls(response.context)
|
||||||
|
self.assertEqual(response.context['active_item'], 'dashboard')
|
||||||
|
|
||||||
|
def test_contact_page_context(self):
|
||||||
|
response = self.client.get(reverse('contact_form'))
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertIn(item, response.context)
|
||||||
|
self._check_static_urls(response.context)
|
||||||
|
self.assertEqual(response.context['active_item'], 'contact')
|
||||||
|
|
||||||
|
def test_hostingpackage_page_context(self):
|
||||||
|
user = User.objects.create_user('test', password='test')
|
||||||
|
self.client.login(username='test', password='test')
|
||||||
|
response = self.client.get(
|
||||||
|
reverse('hosting_packages', kwargs={'user': 'test'}))
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertIn(item, response.context)
|
||||||
|
self._check_static_urls(response.context)
|
||||||
|
self.assertEqual(response.context['active_item'], 'hostingpackage')
|
||||||
|
|
||||||
|
def _test_page_context_by_viewmodule(self, viewmodule, expecteditem):
|
||||||
|
request = HttpRequest()
|
||||||
|
request.resolver_match = MagicMock()
|
||||||
|
request.resolver_match.func.__module__ = viewmodule
|
||||||
|
context = navigation(request)
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertIn(item, context)
|
||||||
|
self._check_static_urls(context)
|
||||||
|
self.assertEqual(context['active_item'], expecteditem)
|
||||||
|
|
||||||
|
def test_osusers_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'osusers.views', 'hostingpackage')
|
||||||
|
|
||||||
|
def test_userdbs_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'userdbs.views', 'hostingpackage')
|
||||||
|
|
||||||
|
def test_managemails_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'managemails.views', 'hostingpackage')
|
||||||
|
|
||||||
|
def test_websites_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'websites.views', 'hostingpackage')
|
||||||
|
|
||||||
|
def test_domains_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'domains.views', 'hostingpackage')
|
||||||
|
|
||||||
|
def test_allauth_account_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'allauth.account.views', 'account')
|
||||||
|
|
||||||
|
def test_allauth_socialaccount_page_context(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'allauth.socialaccount.views', 'account')
|
||||||
|
|
||||||
|
def test_imprint_page_context(self):
|
||||||
|
response = self.client.get(reverse('imprint'))
|
||||||
|
for item in self.EXPECTED_ITEMS:
|
||||||
|
self.assertIn(item, response.context)
|
||||||
|
self._check_static_urls(response.context)
|
||||||
|
self.assertEqual(response.context['active_item'], 'imprint')
|
||||||
|
|
||||||
|
def test_no_resolver_match(self):
|
||||||
|
request = HttpRequest()
|
||||||
|
context = navigation(request)
|
||||||
|
self._check_static_urls(context)
|
||||||
|
self.assertEqual(context['active_item'], 'dashboard')
|
||||||
|
|
||||||
|
def test_admin_module(self):
|
||||||
|
self._test_page_context_by_viewmodule(
|
||||||
|
'django.contrib.admin.foo', 'dashboard')
|
||||||
|
|
||||||
|
|
||||||
|
class VersionInfoContextProcessorTest(TestCase):
|
||||||
|
|
||||||
|
def test_version_info_in_context(self):
|
||||||
|
response = self.client.get('/')
|
||||||
|
self.assertIn('gnuviechadmin_version', response.context)
|
||||||
|
self.assertEqual(response.context['gnuviechadmin_version'], gvaversion)
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- python -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
@ -19,10 +21,3 @@ class GetEnvVariableTest(TestCase):
|
||||||
get_env_variable('missingvariable')
|
get_env_variable('missingvariable')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(e.exception), 'Set the missingvariable environment variable')
|
str(e.exception), 'Set the missingvariable environment variable')
|
||||||
|
|
||||||
|
|
||||||
class WSGITest(TestCase):
|
|
||||||
|
|
||||||
def test_wsgi_application(self):
|
|
||||||
from gnuviechadmin import wsgi
|
|
||||||
self.assertIsNotNone(wsgi.application)
|
|
11
gnuviechadmin/gnuviechadmin/tests/test_wsgi.py
Normal file
11
gnuviechadmin/gnuviechadmin/tests/test_wsgi.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# -*- python -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class WSGITest(TestCase):
|
||||||
|
|
||||||
|
def test_wsgi_application(self):
|
||||||
|
from gnuviechadmin import wsgi
|
||||||
|
self.assertIsNotNone(wsgi.application)
|
||||||
|
|
Loading…
Reference in a new issue