diff --git a/.travis.yml b/.travis.yml index 7ecffca..e6dd4d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,9 @@ matrix: include: - { python: "2.7", env: DJANGO=1.11 } - { python: "3.4", env: DJANGO=2.0 } - - { python: "nightly", env: DJANGO=2.2 } + - { python: "3.5", env: DJANGO=2.2 } + - { python: "3.6", env: DJANGO=3.0 } + - { python: "nightly", env: DJANGO=3.1 } install: - pip install -r requirements.txt diff --git a/README.md b/README.md index f8e91b4..edbe6d3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Django Batch Requests ========================= -![](https://img.shields.io/badge/python-2.7%20|%203.4%20|%20nightly-blue.svg) -![](https://img.shields.io/badge/django%20versions-1.11%20|%202.0%20|%202.2-blue.svg) +![](https://img.shields.io/badge/python-2.7%20--%203.10-blue.svg) +![](https://img.shields.io/badge/django%20versions-1.11%20|%202.0%20|%202.2%20|%203.0%20|%203.1-blue.svg) [![build-status-image]][travis] [![coverage]][coverage-repo] diff --git a/batch_requests/__init__.py b/batch_requests/__init__.py index fc4cb02..36c9fcd 100644 --- a/batch_requests/__init__.py +++ b/batch_requests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- __title__ = 'django-batch-requests' -__version__ = '1.0' +__version__ = '2.0' __author__ = 'Rahul Tanwani, Tomasz Nowak' __license__ = 'MIT' diff --git a/batch_requests/utils.py b/batch_requests/utils.py index af00fa5..2171068 100644 --- a/batch_requests/utils.py +++ b/batch_requests/utils.py @@ -65,7 +65,7 @@ def pre_process_method_headers(method, headers): header = header.replace("-", "_") header = "http_{header}".format( header=header) if header.lower() not in _wsgi_headers else header - _transformed_headers.update({header.upper(): value}) + _transformed_headers[header.upper()] = value return method, _transformed_headers @@ -87,7 +87,7 @@ def get_wsgi_request_object(curr_request, method, url, headers, body): # Add default content type. if "CONTENT_TYPE" not in t_headers: - t_headers.update({"CONTENT_TYPE": _settings.DEFAULT_CONTENT_TYPE}) + t_headers["CONTENT_TYPE"] = _settings.DEFAULT_CONTENT_TYPE # Override existing batch requests headers with the new headers passed for this request. x_headers.update(t_headers) diff --git a/batch_requests/views.py b/batch_requests/views.py index 3a1e967..abf9aeb 100644 --- a/batch_requests/views.py +++ b/batch_requests/views.py @@ -36,7 +36,7 @@ def get_response(wsgi_request): except Exception as exc: resp = HttpResponseServerError(content=exc.args[0]) - headers = dict(resp._headers.values()) + headers = dict(resp.items()) # Convert HTTP response into simple dict type. d_resp = {"status_code": resp.status_code, "reason_phrase": resp.reason_phrase, "headers": headers} @@ -48,7 +48,7 @@ def get_response(wsgi_request): # Check if we need to send across the duration header. if _settings.ADD_DURATION_HEADER: - d_resp['headers'].update({_settings.DURATION_HEADER_NAME: (datetime.now() - service_start_time).seconds}) + d_resp['headers'][_settings.DURATION_HEADER_NAME] = (datetime.now() - service_start_time).seconds return d_resp diff --git a/setup.py b/setup.py index dde45c8..80db3f8 100644 --- a/setup.py +++ b/setup.py @@ -106,6 +106,12 @@ def get_package_data(package): 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Topic :: Internet :: WWW/HTTP' ] ) diff --git a/tests/test_base.py b/tests/test_base.py index 8aa0865..6170fae 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -34,7 +34,7 @@ def headers_dict(self, headers): ''' Converts the headers from the response in to a dict. ''' - return dict(headers.values()) + return dict(headers) def prepare_response(self, status_code, body, headers): ''' diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index b061b44..7aa6107 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -22,7 +22,7 @@ def test_compatibility_of_get_request(self): ''' # Get the response for an individual request. inv_req = self.client.get("/views/") - inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for a batch request. batch_request = self.make_a_batch_request("GET", "/views/", "") @@ -41,7 +41,7 @@ def test_compatibility_of_post_request(self): # Get the response for an individual request. inv_req = self.client.post("/views/", data, content_type="text/plain") - inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for a batch request. 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): # Get the response for an individual request. inv_req = self.client.patch("/views/", data, content_type="text/plain") - inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for a batch request. 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): # Get the response for an individual request. inv_req = self.client.post("/views/", data, content_type="text/plain") - inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for a batch request. 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): ''' # Get the response for an individual request. inv_req = self.client.delete("/views/") - inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_resp = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for a batch request. batch_request = self.make_a_batch_request("delete", "/views/", "") @@ -117,15 +117,15 @@ def test_compatibility_of_multiple_requests(self): # Get the response for an individual GET request. inv_req = self.client.get("/views/") - inv_get = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_get = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for an individual POST request. inv_req = self.client.post("/views/", data, content_type="text/plain") - inv_post = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_post = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Get the response for an individual PUT request. inv_req = self.client.patch("/views/", data, content_type="text/plain") - inv_put = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req._headers) + inv_put = self.prepare_response(inv_req.status_code, inv_req.content.decode('utf-8'), inv_req.items()) # Consolidate all the responses. indv_responses = [inv_get, inv_post, inv_put] diff --git a/tests/test_concurrency_base.py b/tests/test_concurrency_base.py index e2729b2..bd6d4f9 100644 --- a/tests/test_concurrency_base.py +++ b/tests/test_concurrency_base.py @@ -62,11 +62,11 @@ def compare_seq_concurrent_duration(self): # Get the response for a batch request. batch_requests = self.make_multiple_batch_request([sleep_2_seconds, sleep_1_second, sleep_2_seconds]) - seq_duration = int(batch_requests._headers.get(br_settings.DURATION_HEADER_NAME)[1]) + seq_duration = int(batch_requests[br_settings.DURATION_HEADER_NAME]) # Update the executor settings. br_settings.executor = self.get_executor() concurrent_batch_requests = self.make_multiple_batch_request([sleep_2_seconds, sleep_1_second, sleep_2_seconds]) - concurrency_duration = int(concurrent_batch_requests._headers.get(br_settings.DURATION_HEADER_NAME)[1]) + concurrency_duration = int(concurrent_batch_requests[br_settings.DURATION_HEADER_NAME]) self.assertLess(concurrency_duration, seq_duration, "Concurrent requests are slower than running them in sequence.") diff --git a/tests/test_settings.py b/tests/test_settings.py index e92d58f..d06b40c 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -90,7 +90,7 @@ def test_duration_header(self): batch_requests = self._make_multiple_batch_request([get_req]) # Make sure we have the header present in enclosing batch response and all individual responses. - self.assertIn(br_settings.DURATION_HEADER_NAME, batch_requests._headers, + self.assertIn(br_settings.DURATION_HEADER_NAME, batch_requests, "Enclosing batch request does not contain duration header.") self.assertIn(br_settings.DURATION_HEADER_NAME, json.loads(batch_requests.content.decode('utf-8'))[0]['headers'],