Skip to content

Commit

Permalink
Merge pull request #50 from Solution4Future/feature/fix-headers
Browse files Browse the repository at this point in the history
fix: Django 2.2 made HttpResponse headers public field
  • Loading branch information
dekoza committed Oct 31, 2021
2 parents be2652c + f97c37a commit 2b61ad2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
2 changes: 1 addition & 1 deletion djet/assertions.py
Expand Up @@ -54,7 +54,7 @@ def assert_redirect(self, response, expected_url=None):
self._get_redirect_assertion_message(response),
)
if expected_url:
location_header = response._headers.get("location", None)
location_header = response.headers.get("Location", None)
self.assertEqual(
location_header,
("Location", str(expected_url)),
Expand Down
13 changes: 4 additions & 9 deletions djet/restframework.py
@@ -1,4 +1,3 @@
import django
from rest_framework import test

from djet import testcases
Expand Down Expand Up @@ -28,13 +27,9 @@ def _get_view(self, request):
return super(APIViewTestCase, self)._get_view(request)


if django.VERSION >= (1, 4):

class APIViewLiveServerTestCase(testcases.ViewLiveServerTestCase):
factory_class = APIRequestFactory

class APIViewLiveServerTestCase(testcases.ViewLiveServerTestCase):
factory_class = APIRequestFactory

if django.VERSION >= (1, 5):

class APIViewSimpleTestCase(testcases.ViewSimpleTestCase):
factory_class = APIRequestFactory
class APIViewSimpleTestCase(testcases.ViewSimpleTestCase):
factory_class = APIRequestFactory
15 changes: 5 additions & 10 deletions djet/testcases.py
@@ -1,6 +1,5 @@
from functools import partial

import django
from django import test as django_test


Expand Down Expand Up @@ -93,7 +92,7 @@ def _load_old_middleware(self):
middleware_classes = self.middleware_classes or []
for mw_class in middleware_classes:
mw_class, mw_types = self._unpack_middleware(mw_class)
mw_instance = mw_class()
mw_instance = mw_class(self._get_response)

if self._should_add_middleware(
mw_instance, mw_types, MiddlewareType.PROCESS_REQUEST
Expand Down Expand Up @@ -209,13 +208,9 @@ class ViewTestCase(ViewTestCaseMixin, django_test.TestCase):
pass


if django.VERSION >= (1, 4):

class ViewLiveServerTestCase(ViewTestCaseMixin, django_test.LiveServerTestCase):
pass

class ViewLiveServerTestCase(ViewTestCaseMixin, django_test.LiveServerTestCase):
pass

if django.VERSION >= (1, 5):

class ViewSimpleTestCase(ViewTestCaseMixin, django_test.SimpleTestCase):
pass
class ViewSimpleTestCase(ViewTestCaseMixin, django_test.SimpleTestCase):
pass
32 changes: 14 additions & 18 deletions testproject/testapp/tests/test_testcases.py
@@ -1,4 +1,3 @@
import django
from django import test as django_test
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
Expand All @@ -9,6 +8,9 @@


class MockMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response

def process_request(self, request):
request.process_request_was_here = True

Expand Down Expand Up @@ -37,6 +39,9 @@ def __call__(self, request):


class ProcessViewMockMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response

def process_view(self, request, view_func, view_args, view_kwargs):
response = HttpResponse()
response.process_view_was_here = True
Expand Down Expand Up @@ -140,18 +145,14 @@ class ViewTransactionTestCaseTest(
pass


if django.VERSION >= (1, 4):

class ViewLiveServerTestCaseTest(
ViewTestCaseTestMixin, testcases.ViewLiveServerTestCase
):
pass

class ViewLiveServerTestCaseTest(
ViewTestCaseTestMixin, testcases.ViewLiveServerTestCase
):
pass

if django.VERSION >= (1, 5):

class ViewSimpleTestCaseTest(ViewTestCaseTestMixin, testcases.ViewSimpleTestCase):
pass
class ViewSimpleTestCaseTest(ViewTestCaseTestMixin, testcases.ViewSimpleTestCase):
pass


class ProcessExceptionMiddlewareViewTestCaseTest(testcases.ViewTestCase):
Expand Down Expand Up @@ -236,14 +237,9 @@ class NewStyleMiddlewareTest(testcases.ViewTestCase):
def test_new_middleware(self):
request = self.factory.get()

try:
response = self.view(request)
except NotImplementedError:
if django.VERSION >= (1, 10):
assert True
response = self.view(request)

if django.VERSION >= (1, 10):
self.assertTrue(response.new_middleware)
self.assertTrue(response.new_middleware)


class NoViewClassDefined(testcases.ViewTestCase):
Expand Down

0 comments on commit 2b61ad2

Please sign in to comment.