2013-03-12 21:38:22 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.utils.test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Unit test class.
|
|
|
|
|
|
|
|
:copyright: 2011-2013 by OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2013-09-08 14:44:41 +02:00
|
|
|
from django.core.management import call_command
|
2013-03-12 21:38:22 +01:00
|
|
|
from django.test import TestCase as _TestCase
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.core.signals import post_database_setup
|
2013-03-12 21:38:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestCase(_TestCase):
|
|
|
|
"""
|
|
|
|
Overwrites Django's TestCase class to call the post_database_setup
|
2013-03-01 17:13:12 +01:00
|
|
|
signal after the preparation of every test. Also refreshs the config cache.
|
2013-03-12 21:38:22 +01:00
|
|
|
"""
|
|
|
|
def _pre_setup(self, *args, **kwargs):
|
|
|
|
return_value = super(TestCase, self)._pre_setup(*args, **kwargs)
|
|
|
|
post_database_setup.send(sender=self)
|
2013-08-19 12:41:29 +02:00
|
|
|
return return_value
|
|
|
|
|
|
|
|
def _post_teardown(self, *args, **kwargs):
|
|
|
|
return_value = super(TestCase, self)._post_teardown(*args, **kwargs)
|
|
|
|
# Resets the config object by deleting the cache
|
|
|
|
try:
|
|
|
|
del config._cache
|
|
|
|
except AttributeError:
|
|
|
|
# The cache has only to be deleted if it exists.
|
|
|
|
pass
|
2013-09-08 14:44:41 +02:00
|
|
|
# Clear the whoosh search index
|
|
|
|
call_command('clear_index', interactive=False, verbosity=0)
|
2013-03-12 21:38:22 +01:00
|
|
|
return return_value
|