Example #1
0
class BaseLanguageTestCase(BaseUnittest):
    """
    Contains some language helper stuff.    
    """
    def tearDown(self):
        super(BaseLanguageTestCase, self).tearDown()
        if self._system_preferences is not None:
            # revert changes from self.enable_i18n_debug()
            self._system_preferences["message_level_anonymous"] = self.old_message_level
            self._system_preferences.save()
        settings.DEBUG = False
        settings.PYLUCID.I18N_DEBUG = False

    def enable_i18n_debug(self):
        """
        enable DEBUG, PYLUCID.I18N_DEBUG and set message_level_anonymous to DEBUG.
        """
        cache.clear()
        from pylucid_project.apps.pylucid.preference_forms import SystemPreferencesForm
        self._system_preferences = SystemPreferencesForm()
        self.old_message_level = self._system_preferences["message_level_anonymous"]
        self._system_preferences["message_level_anonymous"] = message_constants.DEBUG
        self._system_preferences.save()
        settings.DEBUG = True
        settings.PYLUCID.I18N_DEBUG = True

    def _pre_setup(self, *args, **kwargs):
        """ create some language related attributes """
        super(BaseLanguageTestCase, self)._pre_setup(*args, **kwargs)

        self._system_preferences = None # used in enable_i18n_debug() and tearDown()

        # default language is defined with settings.LANGUAGE_CODE
        self.default_language = Language.objects._get_default_language()
        self.failUnlessEqual(self.default_language.code, settings.LANGUAGE_CODE)

        self.other_lang_code = "de"
        assert self.other_lang_code != self.default_language.code
        self.other_language = Language.objects.get(code=self.other_lang_code)

    def assertContentLanguage(self, response, lang):
        """ Check if response is in right language """
        assert isinstance(lang, Language)
        is_lang = response["content-language"]
        if is_lang != lang.code:
            self.raise_browser_traceback(response,
                msg="Header 'Content-Language' is not %r it's: %r" % (lang.code, is_lang)
            )
        self.assertResponse(response,
            must_contain=(
                '<body lang="%s">' % lang.code,
                '<html lang="%(code)s">' % {
                    "code": lang.code
                },
            )
        )
Example #2
0
class BaseLanguageTestCase(BaseUnittest):
    """
    Contains some language helper stuff.    
    """
    def tearDown(self):
        super(BaseLanguageTestCase, self).tearDown()
        if self._system_preferences is not None:
            # revert changes from self.enable_i18n_debug()
            self._system_preferences["message_level_anonymous"] = self.old_message_level
            self._system_preferences.save()
        settings.DEBUG = False
        settings.PYLUCID.I18N_DEBUG = False

    def enable_i18n_debug(self):
        """
        enable DEBUG, PYLUCID.I18N_DEBUG and set message_level_anonymous to DEBUG.
        """
        cache.clear()
        from pylucid_project.apps.pylucid.preference_forms import SystemPreferencesForm
        self._system_preferences = SystemPreferencesForm()
        self.old_message_level = self._system_preferences["message_level_anonymous"]
        self._system_preferences["message_level_anonymous"] = message_constants.DEBUG
        self._system_preferences.save()
        settings.DEBUG = True
        settings.PYLUCID.I18N_DEBUG = True

    def _pre_setup(self, *args, **kwargs):
        """ create some language related attributes """
        super(BaseLanguageTestCase, self)._pre_setup(*args, **kwargs)

        self._system_preferences = None  # used in enable_i18n_debug() and tearDown()

        # default language is defined with settings.LANGUAGE_CODE
        self.default_language = Language.objects._get_default_language()
        self.failUnlessEqual(self.default_language.code, settings.LANGUAGE_CODE)

        self.other_lang_code = "de"
        assert self.other_lang_code != self.default_language.code
        self.other_language = Language.objects.get(code=self.other_lang_code)

    def assertContentLanguage(self, response, lang):
        """ Check if response is in right language """
        assert isinstance(lang, Language)
        is_lang = response["content-language"]
        if is_lang != lang.code:
            self.raise_browser_traceback(response,
                msg="Header 'Content-Language' is not %r it's: %r" % (lang.code, is_lang)
            )
        self.assertResponse(response,
            must_contain=(
                '<body lang="%s">' % lang.code,
                '<html lang="%(code)s">' % {
                    "code": lang.code
                },
            )
        )
Example #3
0
class BlogPluginAnonymousTestCase(BlogPluginTestCase):
    def setUp(self):
        cache.clear()

        from pylucid_project.apps.pylucid.preference_forms import SystemPreferencesForm
        self.system_pref_form = SystemPreferencesForm()
        self.system_preferences = self.system_pref_form.get_preferences()
        self.system_preferences["message_level_anonymous"] = message_constants.DEBUG
        self.system_pref_form.save()

        DEBUG_LANG_FILTER = True
        settings.PYLUCID.I18N_DEBUG = True

        self.pref_form = BlogPrefForm()

    def _set_language_filter(self, language_filter):
        self.pref_form["language_filter"] = language_filter
        self.pref_form.save()
Example #4
0
class BlogPluginAnonymousTestCase(BlogPluginTestCase):
    def setUp(self):
        cache.clear()

        from pylucid_project.apps.pylucid.preference_forms import SystemPreferencesForm
        self.system_pref_form = SystemPreferencesForm()
        self.system_preferences = self.system_pref_form.get_preferences()
        self.system_preferences["message_level_anonymous"] = message_constants.DEBUG
        self.system_pref_form.save()

        DEBUG_LANG_FILTER = True
        settings.PYLUCID.I18N_DEBUG = True

        self.pref_form = BlogPrefForm()

    def _set_language_filter(self, language_filter):
        self.pref_form["language_filter"] = language_filter
        self.pref_form.save()
Example #5
0
    def test_non_caching_pages_with_messages(self):
        system_preferences = SystemPreferencesForm()
        system_preferences["message_level_anonymous"] = message_constants.DEBUG
        system_preferences.save()

        url = self.url + "test_messages/"
        client = Client()

        # Put page into cache?
        client.cookies["test_messages"] = "one"
        response = client.get(url)
        self.assertResponse(response,
            must_contain=(
                "Response from unittest_plugin.test_messages() [one]",
                "A &#39;debug&#39; message",
                "A &#39;info&#39; message",
                "A &#39;success&#39; message",
                "A &#39;warning&#39; message",
                "A &#39;error&#39; message",
            ),
            must_not_contain=("Traceback",)
        )
        self.assertFalse(response._from_cache)

        # Request from cache?
        client.cookies["test_messages"] = "two"
        response = client.get(url)
        self.assertResponse(response,
            must_contain=(
                "Response from unittest_plugin.test_messages() [two]",
                "A &#39;debug&#39; message",
                "A &#39;info&#39; message",
                "A &#39;success&#39; message",
                "A &#39;warning&#39; message",
                "A &#39;error&#39; message",

            ),
            must_not_contain=("Traceback",)
        )
        self.assertFalse(response._from_cache)
Example #6
0
    def test_non_caching_pages_with_messages(self):
        system_preferences = SystemPreferencesForm()
        system_preferences["message_level_anonymous"] = message_constants.DEBUG
        system_preferences.save()

        url = self.url + "test_messages/"
        client = Client()

        # Put page into cache?
        client.cookies["test_messages"] = "one"
        response = client.get(url)
        self.assertResponse(response,
            must_contain=(
                "Response from unittest_plugin.test_messages() [one]",
                "A &#39;debug&#39; message",
                "A &#39;info&#39; message",
                "A &#39;success&#39; message",
                "A &#39;warning&#39; message",
                "A &#39;error&#39; message",
            ),
            must_not_contain=("Traceback",)
        )
        self.assertFalse(response._from_cache)

        # Request from cache?
        client.cookies["test_messages"] = "two"
        response = client.get(url)
        self.assertResponse(response,
            must_contain=(
                "Response from unittest_plugin.test_messages() [two]",
                "A &#39;debug&#39; message",
                "A &#39;info&#39; message",
                "A &#39;success&#39; message",
                "A &#39;warning&#39; message",
                "A &#39;error&#39; message",

            ),
            must_not_contain=("Traceback",)
        )
        self.assertFalse(response._from_cache)