Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Python 3 and Django 1.9+ (plus Tox) #26

Closed
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ denisvlr - https://github.com/denisvlr
mattrobenolt - https://github.com/mattrobenolt
thoop - https://github.com/thoop
rchrd2 - https://github.com/rchrd2
chazcb - https://github.com/chazcb
chazcb - https://github.com/chazcb
Pi Delport - https://github.com/pjdelport
2 changes: 1 addition & 1 deletion django_seo_js/backends/prerender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django_seo_js import settings
from base import SEOBackendBase, RequestsBasedBackend
from .base import SEOBackendBase, RequestsBasedBackend


class PrerenderIO(SEOBackendBase, RequestsBasedBackend):
Expand Down
2 changes: 1 addition & 1 deletion django_seo_js/backends/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.http import HttpResponse

from base import SEOBackendBase
from .base import SEOBackendBase


class TestBackend(SEOBackendBase):
Expand Down
4 changes: 3 additions & 1 deletion django_seo_js/templatetags/django_seo_js.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django import template
from django.utils.safestring import mark_safe

register = template.Library()


@register.simple_tag
def seo_js_head(*args):
return """<meta name="fragment" content="!">"""
return mark_safe("""<meta name="fragment" content="!">""")
7 changes: 5 additions & 2 deletions django_seo_js/tests/backends/test_prerender_hosted.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

import random
import string

Expand All @@ -7,11 +9,12 @@
from django_seo_js.tests.utils import override_settings
from django_seo_js.backends import PrerenderHosted

MOCK_RESPONSE = "<html><body><h1>Hello, World!</h1></body></html>"
MOCK_RESPONSE = b"<html><body><h1>Hello, World!</h1></body></html>"
MOCK_RESPONSE_HEADERS = {"foo": "bar"}
MOCK_RECACHE_RESPONSE = "OK"
MOCK_RECACHE_HEADERS = {"ibbity": "ack"}
MOCK_GIANT_RESPONSE = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(200000))
_ascii = string.ascii_uppercase + string.digits
MOCK_GIANT_RESPONSE = ''.join(random.choice(_ascii) for _ in range(200000)).encode('ascii')


@all_requests
Expand Down
4 changes: 3 additions & 1 deletion django_seo_js/tests/backends/test_prerender_io.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import unicode_literals

from django.test import TestCase
from httmock import all_requests, HTTMock

from django_seo_js.tests.utils import override_settings
from django_seo_js.backends import PrerenderIO

MOCK_RESPONSE = "<html><body><h1>Hello, World!</h1></body></html>"
MOCK_RESPONSE = b"<html><body><h1>Hello, World!</h1></body></html>"
MOCK_RESPONSE_HEADERS = {"foo": "bar"}
MOCK_RECACHE_RESPONSE = "OK"
MOCK_RECACHE_HEADERS = {"ibbity": "ack"}
Expand Down
18 changes: 10 additions & 8 deletions django_seo_js/tests/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import unicode_literals

from mock import Mock
from django.test import TestCase

from django_seo_js.tests.utils import override_settings
from django_seo_js.middleware import EscapedFragmentMiddleware, UserAgentMiddleware, HashBangMiddleware

print override_settings
print(override_settings)


class BaseMiddlewareTest(TestCase):
Expand All @@ -23,7 +25,7 @@ def setUp(self):

def test_has_escaped_fragment(self):
self.request.GET = {"_escaped_fragment_": None}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

def test_does_not_have_escaped_fragment(self):
self.request.GET = {}
Expand Down Expand Up @@ -57,7 +59,7 @@ def test_overriding_skips_custom_overrides_xml_by_default(self):
self.middleware = EscapedFragmentMiddleware()
self.request.path = "/sitemap.xml"
self.request.GET = {"_escaped_fragment_": None}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

self.request.path = "/foo.html"
self.assertEqual(self.middleware.process_request(self.request), None)
Expand All @@ -80,7 +82,7 @@ def test_overriding_skips_custom_overrides_gifs_by_default(self):
self.middleware = EscapedFragmentMiddleware()
self.request.path = "/foo.gif"
self.request.GET = {"_escaped_fragment_": None}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

self.request.path = "/foo.html"
self.assertEqual(self.middleware.process_request(self.request), None)
Expand Down Expand Up @@ -115,7 +117,7 @@ def test_matches_one_of_the_default_user_agents(self):
"HTTP_USER_AGENT":
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

def test_does_not_match_one_of_the_default_user_agents(self):
self.request.META = {
Expand All @@ -132,7 +134,7 @@ def test_overriding_matches(self):
self.request.META = {
"HTTP_USER_AGENT": "The TestUserAgent v1.0"
}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

@override_settings(
USER_AGENTS=["TestUserAgent", ],
Expand Down Expand Up @@ -194,7 +196,7 @@ def test_overriding_skips_custom_overrides_xml_by_default(self):
"HTTP_USER_AGENT":
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

self.request.path = "/foo.html"
self.assertEqual(self.middleware.process_request(self.request), None)
Expand Down Expand Up @@ -223,7 +225,7 @@ def test_overriding_skips_custom_overrides_gifs_by_default(self):
"HTTP_USER_AGENT":
"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
}
self.assertEqual(self.middleware.process_request(self.request).content, "Test")
self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

self.request.path = "/foo.html"
self.assertEqual(self.middleware.process_request(self.request), None)
Expand Down
1 change: 1 addition & 0 deletions django_seo_js/tests/test_pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_pep8_conformance(self):
ignored_folders = [
".git",
"venv",
".tox",
]

pep8style = pep8.StyleGuide(
Expand Down
3 changes: 1 addition & 2 deletions requirements.tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
django
fabric
httmock
mock
nose
pep8
pep8
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests==2.2.1
Django
requests
10 changes: 6 additions & 4 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
}

SECRET_KEY = 'alksjdf93jqpijsdaklfjq;3lejqklejlakefjas'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
},
]

MIDDLEWARE_CLASSES = (
'django_seo_js.middleware.EscapedFragmentMiddleware',
Expand Down
18 changes: 18 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py{27,35}-dj1.{8,9,10}

[testenv]
deps =
-rrequirements.tests.txt

dj1.8: Django ~=1.8.0
dj1.9: Django ~=1.9.0
dj1.10: Django ~=1.10.0

commands =
{envpython} manage.py test