From 06e9a44fc3e4605d4b8e32ddbc87bf11deb71f57 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 4 Jan 2017 19:16:28 -0800 Subject: [PATCH 1/6] django-1.8 support. Initial changes to configs and mixin. Not quite ready yet. Signed-off-by: Steven Githens --- requirements.txt | 2 +- restlib2/mixins.py | 3 ++- test_suite.py | 20 ++++++++++++-------- tests/settings.py | 32 +++++++++++++++++++++++++++----- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index c53f5ec..30a8a85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django>=1.4,<1.7 +Django>=1.8.16 six>=1.4.0 diff --git a/restlib2/mixins.py b/restlib2/mixins.py index beae076..efdd40e 100644 --- a/restlib2/mixins.py +++ b/restlib2/mixins.py @@ -1,3 +1,4 @@ +from django.template import Engine from django.template import loader from django.template import RequestContext from django.http import HttpResponse @@ -17,7 +18,7 @@ def render(self, request, context, status=codes.ok, content_type=None, elif self.template_name: template = loader.get_template(self.template_name) else: - template = loader.Template(self.template_string) + template = Engine().from_string(self.template_string) context = RequestContext(request, context) content = template.render(context) diff --git a/test_suite.py b/test_suite.py index 29b44ef..7c81164 100644 --- a/test_suite.py +++ b/test_suite.py @@ -1,15 +1,19 @@ import os import sys -os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' +if __name__ == "__main__": + apps = sys.argv[1:] -from django.core import management + if not apps: + apps = [ + 'tests', + ] -apps = sys.argv[1:] + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") -if not apps: - apps = [ - 'tests', - ] + from django.core.management import execute_from_command_line + from django.core.management import call_command -management.call_command('test', *apps) + # execute_from_command_line(sys.argv) + execute_from_command_line(['manage.py', 'test', 'tests']) + # call_command('test', *apps) diff --git a/tests/settings.py b/tests/settings.py index 6a23919..f15d0bf 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,5 +1,6 @@ import os from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS +# from django.conf.global_settings import TEMPLATES SECRET_KEY = '123abc' @@ -13,16 +14,37 @@ ROOT_URLCONF = 'tests.tests' INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'restlib2', - 'tests', + # 'django.contrib.auth', + # 'django.contrib.contenttypes', + # 'restlib2', + # 'tests', ) TEMPLATE_CONTEXT_PROCESSORS += ( - 'django.core.context_processors.request', + 'django.template.context_processors.request', ) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + "tests/templates/" + ], + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.template.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + ] + } + }, +] + LOGGING = { 'version': 1, 'disable_existing_loggers': True, From d24519f5c9249b3992b2f4f20e90b21d922493bf Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 8 Feb 2017 17:27:42 -0800 Subject: [PATCH 2/6] django-1.8 Cleaning up test suite Signed-off-by: Steven Githens --- test_suite.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test_suite.py b/test_suite.py index 7c81164..ea603c1 100644 --- a/test_suite.py +++ b/test_suite.py @@ -12,8 +12,4 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") from django.core.management import execute_from_command_line - from django.core.management import call_command - - # execute_from_command_line(sys.argv) execute_from_command_line(['manage.py', 'test', 'tests']) - # call_command('test', *apps) From a77ab0714d5a9eb29847f6e880d7431d618974e8 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 8 Feb 2017 17:43:05 -0800 Subject: [PATCH 3/6] django-1.8 Cleaning up test settings Removed unused imports and template settings. Also adding comment on potentially unresolved issue with the INSTALLED_APPS. Signed-off-by: Steven Githens --- tests/settings.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/settings.py b/tests/settings.py index f15d0bf..32e1d75 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,6 +1,5 @@ import os from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS -# from django.conf.global_settings import TEMPLATES SECRET_KEY = '123abc' @@ -14,16 +13,15 @@ ROOT_URLCONF = 'tests.tests' INSTALLED_APPS = ( + # TODO sgithens - There seems to an issue when these are included, + # that the tests can't find the db tables to load the test fixtures. + # However, the unit tests still pass if these are not included... # 'django.contrib.auth', # 'django.contrib.contenttypes', # 'restlib2', # 'tests', ) -TEMPLATE_CONTEXT_PROCESSORS += ( - 'django.template.context_processors.request', -) - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', From 6689106d179b26d4c0437ad9a82218bc205805eb Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 20 Feb 2017 21:00:20 -0800 Subject: [PATCH 4/6] django-1.8 Bumping versions in requirements and travis Signed-off-by: Steven Githens --- .travis.yml | 1 + requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2da2446..0cecfb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - DJANGO=1.4.10 - DJANGO=1.5.5 - DJANGO=1.6.1 + - DJANGO=1.8.17 matrix: exclude: diff --git a/requirements.txt b/requirements.txt index 30a8a85..1d60717 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django>=1.8.16 +Django>=1.8 six>=1.4.0 From f5b6429235fb18e9536b23c74483d64845baf681 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 30 Jan 2018 22:13:35 -0800 Subject: [PATCH 5/6] Django 1.11 - Moving Status code import from deprecated django module to standard location in python 2.7 --- restlib2/http/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restlib2/http/__init__.py b/restlib2/http/__init__.py index 0fd0b8d..6065f46 100644 --- a/restlib2/http/__init__.py +++ b/restlib2/http/__init__.py @@ -1,4 +1,4 @@ -from django.core.handlers.wsgi import STATUS_CODE_TEXT +from httplib import responses as STATUS_CODE_TEXT from restlib2.structures import AttrDict STATUS_CODE_TEXT.setdefault(422, 'UNPROCESSABLE ENTITY') From 31bc2ee0b339fcfeda6ada29eee8c11eac443373 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 8 Feb 2018 14:13:50 -0800 Subject: [PATCH 6/6] Django 1.11 Work - Removed url patterns import - Removed old template context import - Bumped django version in setup.py Signed-off-by: Steven Githens --- setup.py | 2 +- tests/settings.py | 1 - tests/tests.py | 5 ++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 21beff0..29be536 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ 'url': 'https://github.com/bruth/restlib2', 'install_requires': [ - 'django>=1.4', + 'django>=1.8', 'six>=1.4.0', ], diff --git a/tests/settings.py b/tests/settings.py index 32e1d75..8f3bc3f 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,5 +1,4 @@ import os -from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS SECRET_KEY = '123abc' diff --git a/tests/tests.py b/tests/tests.py index c552363..d1b71f1 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,7 +1,7 @@ from calendar import timegm from django.test.client import RequestFactory from django.test import TestCase -from django.conf.urls import patterns, url +from django.conf.urls import url from restlib2 import params from restlib2.resources import Resource from restlib2.mixins import TemplateResponseMixin @@ -469,8 +469,7 @@ def get(self, request): pass -urlpatterns = patterns('', - url(r'^$', TestResource(template_name='index.html'))) +urlpatterns =(url(r'^$', TestResource(template_name='index.html')),) class TemplateResourceTestCase(TestCase):