mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
- Take the value from the configuration and run it throught the Django translate method and make it available in Context. - Use a no-op translate method to translate the text 'FreedomBox'.
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
#
|
|
# This file is part of Plinth.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""
|
|
Test module for Plinth's custom context processors.
|
|
"""
|
|
|
|
from django.http import HttpRequest
|
|
from django.test import TestCase
|
|
|
|
from plinth import cfg
|
|
from plinth import context_processors as cp
|
|
|
|
|
|
class ContextProcessorsTestCase(TestCase):
|
|
"""Verify behavior of the context_processors module."""
|
|
|
|
def test_common(self):
|
|
"""Verify that the common() function returns the correct values."""
|
|
cfg.read() # initialize config settings
|
|
|
|
request = HttpRequest()
|
|
request.path = '/aaa/bbb/ccc/'
|
|
response = cp.common(request)
|
|
self.assertIsNotNone(response)
|
|
|
|
config = response['cfg']
|
|
self.assertIsNotNone(config)
|
|
self.assertEqual('FreedomBox', config.box_name)
|
|
|
|
self.assertEqual('FreedomBox', response['box_name'])
|
|
|
|
submenu = response['submenu']
|
|
self.assertIsNone(submenu)
|
|
|
|
urls = response['active_menu_urls']
|
|
self.assertIsNotNone(urls)
|
|
self.assertEqual(['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'], urls)
|
|
|
|
def test_common_border_conditions(self):
|
|
"""Verify that the common() function works for border conditions."""
|
|
request = HttpRequest()
|
|
request.path = ''
|
|
response = cp.common(request)
|
|
self.assertEqual([], response['active_menu_urls'])
|
|
|
|
request.path = '/'
|
|
response = cp.common(request)
|
|
self.assertEqual(['/'], response['active_menu_urls'])
|
|
|
|
request.path = '/aaa/bbb'
|
|
response = cp.common(request)
|
|
self.assertEqual(['/', '/aaa/'], response['active_menu_urls'])
|