Drop i18n_patterns prefix parameter. 0.3
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 15 Feb 2019 09:50:21 +0000 (10:50 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 15 Feb 2019 09:52:01 +0000 (10:52 +0100)
Test for Django up to 1.11.
Drop Python 2.6, 3.2, 3.3.

12 files changed:
fnpdjango/storage.py
fnpdjango/utils/urls.py
runtests.py
setup.py
tests/tests/__init__.py
tests/tests/test_middleware.py [new file with mode: 0644]
tests/tests/test_templatetags_fnp_markup.py
tests/tests/test_templatetags_macros.py [new file with mode: 0644]
tests/tests/test_utils_urls.py [new file with mode: 0644]
tests/urls.py [new file with mode: 0644]
tests/views.py [new file with mode: 0644]
tox.ini

index 72719b2..31674e8 100644 (file)
@@ -19,7 +19,7 @@ class BofhStorageMixin(FileSystemStorage):
     and for sane caching settings.
 
     """
     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
         if self.exists(name):
             self.delete(name)
         return name
index bf9747d..a493c97 100644 (file)
@@ -4,9 +4,8 @@ Utilities for urlconfs.
 
 import re
 from django.conf import settings
 
 import re
 from django.conf import settings
-from django.conf.urls import patterns
 from django.core.urlresolvers import LocaleRegexURLResolver
 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):
 
 
 class MyLocaleRegexURLResolver(LocaleRegexURLResolver):
@@ -27,14 +26,14 @@ class MyLocaleRegexURLResolver(LocaleRegexURLResolver):
         return self._regex_dict[language_code]
 
 
         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.
 
     """
     """
     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)]
     if not settings.USE_I18N:
         return pattern_list
     return pattern_list + [MyLocaleRegexURLResolver(pattern_list)]
index fd4e24a..3f8dd95 100644 (file)
@@ -41,7 +41,20 @@ if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
         ],
         LANGUAGE_CODE='pl',
         MEDIA_ROOT=media_root,
         ],
         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."),
         TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
+        USE_I18N=True,
     )
 else:
     media_root = None
     )
 else:
     media_root = None
index a2c5ef0..adb30aa 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='fnpdjango',
 
 setup(
     name='fnpdjango',
-    version='0.2.8',
+    version='0.3',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url='',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url='',
@@ -33,7 +33,7 @@ setup(
         'fnpdjango.management.commands': ['babel.cfg'],
     },
     install_requires=[
         'fnpdjango.management.commands': ['babel.cfg'],
     },
     install_requires=[
-        'Django>=1.4,<1.11',
+        'Django>=1.4,<2.0',
         'textile==2.3.16',
     ],
     license='LICENSE',
         'textile==2.3.16',
     ],
     license='LICENSE',
index ec449c4..468aae5 100644 (file)
@@ -8,6 +8,9 @@ in Django<1.6.  The newer django.test.runner.DiscoverRunner finds
 test_* modules by itself.
 
 """
 test_* modules by itself.
 
 """
+from .test_middleware import *
 from .test_storage import *
 from .test_templatetags_fnp_markup import *
 from .test_storage import *
 from .test_templatetags_fnp_markup import *
+from .test_templatetags_macros import *
 from .test_utils_settings 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 (file)
index 0000000..0ba5966
--- /dev/null
@@ -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'
+        )
index 5c8e07c..82fba0c 100644 (file)
@@ -4,18 +4,9 @@
 #
 from __future__ import unicode_literals
 
 #
 from __future__ import unicode_literals
 
-import sys
 from django.test import TestCase
 
 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):
 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 (file)
index 0000000..8fd7823
--- /dev/null
@@ -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 }} <br/>
+            {% endmacro %}
+            {% usemacro my_macro "String parameter" %}
+        """)
+        self.assertEqual(
+            tmpl.render(Context()).strip(),
+            "Parameter: String parameter <br/>"
+        )
diff --git a/tests/tests/test_utils_urls.py b/tests/tests/test_utils_urls.py
new file mode 100644 (file)
index 0000000..397e54d
--- /dev/null
@@ -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 (file)
index 0000000..15a9417
--- /dev/null
@@ -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 (file)
index 0000000..0c8ee47
--- /dev/null
@@ -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 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -3,15 +3,15 @@
 #
 [tox]
 envlist=clear,
 #
 [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]
     stats
 
 [testenv]
-indexserver=https://py.mdrn.pl:8443
 commands=coverage run --source=fnpdjango --append --branch runtests.py
 deps=
     d14: Django>=1.4,<1.5
 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
     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
     coverage
-install_command =
-    pip install --process-dependency-links {opts} {packages}
 
 [testenv:clear]
 basepython=python3.4
 
 [testenv:clear]
 basepython=python3.4