Skip to content

Commit

Permalink
Support running tests with newer versions of requests
Browse files Browse the repository at this point in the history
This is to enable running the tests as part of Fedora's build pipeline
when packing WhiteNoise.

See evansd#225
  • Loading branch information
evansd authored and David Moreau Simard committed Sep 24, 2019
1 parent 94d6517 commit 76a6b4e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_django_whitenoise.py
Expand Up @@ -18,6 +18,7 @@
from django.utils.functional import empty

import brotli
import requests

from whitenoise.middleware import WhiteNoiseMiddleware

Expand Down Expand Up @@ -94,9 +95,16 @@ def test_get_gzip(self):
def test_get_brotli(self):
url = storage.staticfiles_storage.url(self.static_files.js_path)
response = self.server.get(url, headers={"Accept-Encoding": "gzip, br"})
self.assertEqual(
brotli.decompress(response.content), self.static_files.js_content
)
response_content = response.content
# Newer versions of `requests` will transparently decode the brotli
# response. We don't want to just use the newer version in testing
# because it doesn't support Python 3.4 and we still want to test on
# 3.4. However we want the tests to be able to run against newer
# versions of `requests` so they can be run as part of Fedora's build
# pipeline. See: https://github.com/evansd/whitenoise/issues/225
if tuple(map(int, requests.__version__.split(".")[:2])) < (2, 22):
response_content = brotli.decompress(response_content)
self.assertEqual(response_content, self.static_files.js_content)
self.assertEqual(response.headers["Content-Encoding"], "br")
self.assertEqual(response.headers["Vary"], "Accept-Encoding")

Expand Down

0 comments on commit 76a6b4e

Please sign in to comment.