Skip to content

Commit f782bf7

Browse files
committed
Compatibility fixes for Django 3.0
1 parent f818155 commit f782bf7

File tree

10 files changed

+28
-20
lines changed

10 files changed

+28
-20
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ matrix:
55
include:
66
- { python: "2.7", env: DJANGO=1.11 }
77
- { python: "3.4", env: DJANGO=2.0 }
8-
- { python: "nightly", env: DJANGO=2.2 }
8+
- { python: "3.5", env: DJANGO=2.2 }
9+
- { python: "3.6", env: DJANGO=3.0 }
10+
- { python: "nightly", env: DJANGO=3.1 }
911

1012
install:
1113
- pip install -r requirements.txt

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Django Batch Requests
22
=========================
33

4-
![](https://img.shields.io/badge/python-2.7%20|%203.4%20|%20nightly-blue.svg)
5-
![](https://img.shields.io/badge/django%20versions-1.11%20|%202.0%20|%202.2-blue.svg)
4+
![](https://img.shields.io/badge/python-2.7%20--%203.10-blue.svg)
5+
![](https://img.shields.io/badge/django%20versions-1.11%20|%202.0%20|%202.2%20|%203.0%20|%203.1-blue.svg)
66
[![build-status-image]][travis]
77
[![coverage]][coverage-repo]
88

batch_requests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
__title__ = 'django-batch-requests'
4-
__version__ = '1.0'
4+
__version__ = '2.0'
55
__author__ = 'Rahul Tanwani, Tomasz Nowak'
66
__license__ = 'MIT'
77

batch_requests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def pre_process_method_headers(method, headers):
6565
header = header.replace("-", "_")
6666
header = "http_{header}".format(
6767
header=header) if header.lower() not in _wsgi_headers else header
68-
_transformed_headers.update({header.upper(): value})
68+
_transformed_headers[header.upper()] = value
6969

7070
return method, _transformed_headers
7171

@@ -87,7 +87,7 @@ def get_wsgi_request_object(curr_request, method, url, headers, body):
8787

8888
# Add default content type.
8989
if "CONTENT_TYPE" not in t_headers:
90-
t_headers.update({"CONTENT_TYPE": _settings.DEFAULT_CONTENT_TYPE})
90+
t_headers["CONTENT_TYPE"] = _settings.DEFAULT_CONTENT_TYPE
9191

9292
# Override existing batch requests headers with the new headers passed for this request.
9393
x_headers.update(t_headers)

batch_requests/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_response(wsgi_request):
3636
except Exception as exc:
3737
resp = HttpResponseServerError(content=exc.args[0])
3838

39-
headers = dict(resp._headers.values())
39+
headers = dict(resp.items())
4040
# Convert HTTP response into simple dict type.
4141
d_resp = {"status_code": resp.status_code, "reason_phrase": resp.reason_phrase,
4242
"headers": headers}
@@ -48,7 +48,7 @@ def get_response(wsgi_request):
4848

4949
# Check if we need to send across the duration header.
5050
if _settings.ADD_DURATION_HEADER:
51-
d_resp['headers'].update({_settings.DURATION_HEADER_NAME: (datetime.now() - service_start_time).seconds})
51+
d_resp['headers'][_settings.DURATION_HEADER_NAME] = (datetime.now() - service_start_time).seconds
5252

5353
return d_resp
5454

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ def get_package_data(package):
106106
'Programming Language :: Python :: 2.7',
107107
'Programming Language :: Python :: 3',
108108
'Programming Language :: Python :: 3.4',
109+
'Programming Language :: Python :: 3.5',
110+
'Programming Language :: Python :: 3.6',
111+
'Programming Language :: Python :: 3.7',
112+
'Programming Language :: Python :: 3.8',
113+
'Programming Language :: Python :: 3.9',
114+
'Programming Language :: Python :: 3.10',
109115
'Topic :: Internet :: WWW/HTTP'
110116
]
111117
)

tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def headers_dict(self, headers):
3434
'''
3535
Converts the headers from the response in to a dict.
3636
'''
37-
return dict(headers.values())
37+
return dict(headers)
3838

3939
def prepare_response(self, status_code, body, headers):
4040
'''

tests/test_compatibility.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_compatibility_of_get_request(self):
2222
'''
2323
# Get the response for an individual request.
2424
inv_req = self.client.get("/views/")
25-
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
25+
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
2626

2727
# Get the response for a batch request.
2828
batch_request = self.make_a_batch_request("GET", "/views/", "")
@@ -41,7 +41,7 @@ def test_compatibility_of_post_request(self):
4141

4242
# Get the response for an individual request.
4343
inv_req = self.client.post("/views/", data, content_type="text/plain")
44-
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
44+
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
4545

4646
# Get the response for a batch request.
4747
batch_request = self.make_a_batch_request("POST", "/views/", data, {"content_type": "text/plain"})
@@ -60,7 +60,7 @@ def test_compatibility_of_put_request(self):
6060

6161
# Get the response for an individual request.
6262
inv_req = self.client.patch("/views/", data, content_type="text/plain")
63-
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
63+
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
6464

6565
# Get the response for a batch request.
6666
batch_request = self.make_a_batch_request("patch", "/views/", data, {"content_type": "text/plain"})
@@ -79,7 +79,7 @@ def test_compatibility_of_patch_request(self):
7979

8080
# Get the response for an individual request.
8181
inv_req = self.client.post("/views/", data, content_type="text/plain")
82-
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
82+
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
8383

8484
# Get the response for a batch request.
8585
batch_request = self.make_a_batch_request("POST", "/views/", data, {"CONTENT_TYPE": "text/plain"})
@@ -96,7 +96,7 @@ def test_compatibility_of_delete_request(self):
9696
'''
9797
# Get the response for an individual request.
9898
inv_req = self.client.delete("/views/")
99-
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
99+
inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
100100

101101
# Get the response for a batch request.
102102
batch_request = self.make_a_batch_request("delete", "/views/", "")
@@ -117,15 +117,15 @@ def test_compatibility_of_multiple_requests(self):
117117

118118
# Get the response for an individual GET request.
119119
inv_req = self.client.get("/views/")
120-
inv_get = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
120+
inv_get = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
121121

122122
# Get the response for an individual POST request.
123123
inv_req = self.client.post("/views/", data, content_type="text/plain")
124-
inv_post = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
124+
inv_post = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
125125

126126
# Get the response for an individual PUT request.
127127
inv_req = self.client.patch("/views/", data, content_type="text/plain")
128-
inv_put = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers)
128+
inv_put = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items())
129129

130130
# Consolidate all the responses.
131131
indv_responses = [inv_get, inv_post, inv_put]

tests/test_concurrency_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def compare_seq_concurrent_duration(self):
6262

6363
# Get the response for a batch request.
6464
batch_requests = self.make_multiple_batch_request([sleep_2_seconds, sleep_1_second, sleep_2_seconds])
65-
seq_duration = int(batch_requests._headers.get(br_settings.DURATION_HEADER_NAME)[1])
65+
seq_duration = int(batch_requests[br_settings.DURATION_HEADER_NAME])
6666

6767
# Update the executor settings.
6868
br_settings.executor = self.get_executor()
6969
concurrent_batch_requests = self.make_multiple_batch_request([sleep_2_seconds, sleep_1_second, sleep_2_seconds])
70-
concurrency_duration = int(concurrent_batch_requests._headers.get(br_settings.DURATION_HEADER_NAME)[1])
70+
concurrency_duration = int(concurrent_batch_requests[br_settings.DURATION_HEADER_NAME])
7171

7272
self.assertLess(concurrency_duration, seq_duration, "Concurrent requests are slower than running them in sequence.")

tests/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_duration_header(self):
9090
batch_requests = self._make_multiple_batch_request([get_req])
9191

9292
# Make sure we have the header present in enclosing batch response and all individual responses.
93-
self.assertIn(br_settings.DURATION_HEADER_NAME, batch_requests._headers,
93+
self.assertIn(br_settings.DURATION_HEADER_NAME, batch_requests,
9494
"Enclosing batch request does not contain duration header.")
9595

9696
self.assertIn(br_settings.DURATION_HEADER_NAME, json.loads(batch_requests.content.decode('utf-8'))[0]['headers'],

0 commit comments

Comments
 (0)