From: Radek Czajka Date: Fri, 15 Feb 2019 09:50:21 +0000 (+0100) Subject: Drop i18n_patterns prefix parameter. X-Git-Tag: 0.3 X-Git-Url: https://git.mdrn.pl/fnpdjango.git/commitdiff_plain/28b1d7e9f4a7008712736adce363ca2770d48aea Drop i18n_patterns prefix parameter. Test for Django up to 1.11. Drop Python 2.6, 3.2, 3.3. --- diff --git a/fnpdjango/storage.py b/fnpdjango/storage.py index 72719b2..31674e8 100644 --- a/fnpdjango/storage.py +++ b/fnpdjango/storage.py @@ -19,7 +19,7 @@ class BofhStorageMixin(FileSystemStorage): and for sane caching settings. """ - def get_available_name(self, name): + def get_available_name(self, name, max_length=None): if self.exists(name): self.delete(name) return name diff --git a/fnpdjango/utils/urls.py b/fnpdjango/utils/urls.py index bf9747d..a493c97 100644 --- a/fnpdjango/utils/urls.py +++ b/fnpdjango/utils/urls.py @@ -4,9 +4,8 @@ Utilities for urlconfs. import re from django.conf import settings -from django.conf.urls import patterns from django.core.urlresolvers import LocaleRegexURLResolver -from django.utils.translation import get_language, string_concat +from django.utils.translation import get_language class MyLocaleRegexURLResolver(LocaleRegexURLResolver): @@ -27,14 +26,14 @@ class MyLocaleRegexURLResolver(LocaleRegexURLResolver): return self._regex_dict[language_code] -def i18n_patterns(prefix, *args): +def i18n_patterns(*args): """ Adds the language code prefix to every URL pattern within this function. This may only be used in the root URLconf, not in an included URLconf. """ - pattern_list = patterns(prefix, *args) + pattern_list = list(args) if not settings.USE_I18N: return pattern_list return pattern_list + [MyLocaleRegexURLResolver(pattern_list)] diff --git a/runtests.py b/runtests.py index fd4e24a..3f8dd95 100644 --- a/runtests.py +++ b/runtests.py @@ -41,7 +41,20 @@ if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'): ], LANGUAGE_CODE='pl', MEDIA_ROOT=media_root, + MIDDLEWARE_CLASSES=[ + 'django.middleware.common.CommonMiddleware', + 'fnpdjango.middleware.URLLocaleMiddleware', + 'fnpdjango.middleware.SetRemoteAddrFromXRealIP', + ], + FNPDJANGO_REALIP = True, + ROOT_URLCONF='tests.urls', + TEMPLATES=[ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + }, + ], TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."), + USE_I18N=True, ) else: media_root = None diff --git a/setup.py b/setup.py index a2c5ef0..adb30aa 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def whole_trees(package_dir, paths): setup( name='fnpdjango', - version='0.2.8', + version='0.3', author='Radek Czajka', author_email='radekczajka@nowoczesnapolska.org.pl', url='', @@ -33,7 +33,7 @@ setup( 'fnpdjango.management.commands': ['babel.cfg'], }, install_requires=[ - 'Django>=1.4,<1.11', + 'Django>=1.4,<2.0', 'textile==2.3.16', ], license='LICENSE', diff --git a/tests/tests/__init__.py b/tests/tests/__init__.py index ec449c4..468aae5 100644 --- a/tests/tests/__init__.py +++ b/tests/tests/__init__.py @@ -8,6 +8,9 @@ in Django<1.6. The newer django.test.runner.DiscoverRunner finds test_* modules by itself. """ +from .test_middleware import * from .test_storage import * from .test_templatetags_fnp_markup import * +from .test_templatetags_macros import * from .test_utils_settings import * +from .test_utils_urls import * diff --git a/tests/tests/test_middleware.py b/tests/tests/test_middleware.py new file mode 100644 index 0000000..0ba5966 --- /dev/null +++ b/tests/tests/test_middleware.py @@ -0,0 +1,16 @@ +from django.test import TestCase + + +class MiddlewareTests(TestCase): + def test_realip(self): + self.assertEqual( + self.client.get('/ip/').content.decode('latin1'), + '127.0.0.1' + ) + self.assertEqual( + self.client.get( + '/ip/', + HTTP_X_REAL_IP='1.2.3.4' + ).content.decode('latin1'), + '1.2.3.4' + ) diff --git a/tests/tests/test_templatetags_fnp_markup.py b/tests/tests/test_templatetags_fnp_markup.py index 5c8e07c..82fba0c 100644 --- a/tests/tests/test_templatetags_fnp_markup.py +++ b/tests/tests/test_templatetags_fnp_markup.py @@ -4,18 +4,9 @@ # from __future__ import unicode_literals -import sys from django.test import TestCase -try: - from unittest import skipIf -except ImportError: - # Don't need skipping for Python2.6. - skipIf = lambda expr, comment: lambda test: test - -@skipIf(sys.version_info[:2] == (3, 2), - "No usable python-textile for Python 3.2.") class TemplatetagsFNPMarkupTestCase(TestCase): def test_textile_en(self): diff --git a/tests/tests/test_templatetags_macros.py b/tests/tests/test_templatetags_macros.py new file mode 100644 index 0000000..8fd7823 --- /dev/null +++ b/tests/tests/test_templatetags_macros.py @@ -0,0 +1,19 @@ +from __future__ import unicode_literals + +from django.test import TestCase +from django.template import Template, Context + + +class MacrosTests(TestCase): + def test_macro(self): + tmpl = Template(""" + {% load macros %} + {% macro my_macro arg1 %} + Parameter: {{ arg1 }}
+ {% endmacro %} + {% usemacro my_macro "String parameter" %} + """) + self.assertEqual( + tmpl.render(Context()).strip(), + "Parameter: String parameter
" + ) diff --git a/tests/tests/test_utils_urls.py b/tests/tests/test_utils_urls.py new file mode 100644 index 0000000..397e54d --- /dev/null +++ b/tests/tests/test_utils_urls.py @@ -0,0 +1,7 @@ +from django.test import TestCase + + +class UrlsTestCase(TestCase): + def test_i18n_patterns(self): + self.assertEqual(self.client.get('/').content.decode('latin1'), 'pl') + self.assertEqual(self.client.get('/en/').content.decode('latin1'), 'en') diff --git a/tests/urls.py b/tests/urls.py new file mode 100644 index 0000000..15a9417 --- /dev/null +++ b/tests/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from fnpdjango.utils.urls import i18n_patterns +from . import views + + +urlpatterns = [ + url(r'^ip/$', views.ip), +] + i18n_patterns( + url(r'^$', views.get_lang), +) diff --git a/tests/views.py b/tests/views.py new file mode 100644 index 0000000..0c8ee47 --- /dev/null +++ b/tests/views.py @@ -0,0 +1,10 @@ +from django.http import HttpResponse +from django.utils.translation import get_language + + +def get_lang(request): + return HttpResponse(get_language()) + + +def ip(request): + return HttpResponse(request.META['REMOTE_ADDR']) diff --git a/tox.ini b/tox.ini index cf4976a..2175e7c 100644 --- a/tox.ini +++ b/tox.ini @@ -3,15 +3,15 @@ # [tox] envlist=clear, - d14-py{26,27}, - d1{5,6}-py{26,27,32,33}, - d17-py{27,32,33,34}, - d18-py{27,32,33,34,35}, - d{19,d}-py{27,34,35}, + d1{4,5,6}-py27, + d17-py{27,34}, + d{18,19,110}-py{27,34,35}, + d111-py{27,34,35,36,37}, + #d20-py{34,35,36,37}, + #d21-py{35,36,37}, stats [testenv] -indexserver=https://py.mdrn.pl:8443 commands=coverage run --source=fnpdjango --append --branch runtests.py deps= d14: Django>=1.4,<1.5 @@ -20,10 +20,11 @@ deps= d17: Django>=1.7,<1.8 d18: Django>=1.8,<1.9 d19: Django>=1.9,<1.10 - dd: https://github.com/django/django/zipball/master + d110: Django>=1.10,<1.11 + d111: Django>=1.11,<2.0 + d20: Django>=2.0,<2.1 + d21: Django>=2.1,<2.2 coverage -install_command = - pip install --process-dependency-links {opts} {packages} [testenv:clear] basepython=python3.4