OpenSlides/tests/old/utils/test_main_menu.py
Oskar Hahn e7230b7391 New Test order.
* seperate unittests and integration tests
* moved old tests in seperat folder 'old'
* created a testrunner that does not create a testdatabase, if only unittests are run
* wrote some unit- and integration tests as examples
* fixed user.get_short_name() to use the sort order from config
* fixed wrong url_pattern in the user app
2015-01-24 18:00:03 +01:00

53 lines
1.9 KiB
Python

from django.contrib.auth.models import AnonymousUser
from django.test.client import RequestFactory
from openslides.utils.test import TestCase
from openslides.utils.main_menu import MainMenuEntry
class MainMenuEntryObject(TestCase):
request_factory = RequestFactory()
def tearDown(self):
"""
Remove all receivers of the MainMenuEntry-signal, so it is not called in
other tests.
"""
MainMenuEntry.signal.receivers = []
def get_entry(self, cls):
request = self.request_factory.get('/')
request.user = AnonymousUser()
for entry in MainMenuEntry.get_all(request):
if type(entry) == cls:
value = entry
break
else:
value = False
return value
def test_appearance(self):
class TestMenuEntryOne(MainMenuEntry):
pattern_name = 'core_version'
verbose_name = 'Menu entry for testing gae2thooc4che4thaoNo'
self.assertEqual(str(self.get_entry(TestMenuEntryOne)), 'Menu entry for testing gae2thooc4che4thaoNo')
def test_missing_verbose_name(self):
class TestMenuEntryBadOne(MainMenuEntry):
pattern_name = 'core_version'
entry = self.get_entry(TestMenuEntryBadOne)
text = ('The main menu entry class TestMenuEntryBadOne must provide a '
'verbose_name attribute or override the __str__ method.')
self.assertRaisesMessage(NotImplementedError, text, str, entry)
def test_missing_pattern_name(self):
class TestMenuEntryBadTwo(MainMenuEntry):
verbose_name = 'Menu entry for testing ahVeibai1iecaish2aeR'
entry = self.get_entry(TestMenuEntryBadTwo)
text = ('The main menu entry class TestMenuEntryBadTwo must provide a '
'pattern_name attribute or override the get_url method.')
self.assertRaisesMessage(NotImplementedError, text, entry.get_url)