diff --git a/.circleci/config.yml b/.circleci/config.yml index 59c930b..93080aa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,85 +7,22 @@ workflows: matrix: parameters: python_image: - - "python:2.7-slim" - - "python:3.4-slim" - - "python:3.5-slim" - "python:3.6-slim" - "python:3.7-slim" - "python:3.8-slim" - - "pypy:2-slim-buster" + - "python:3.9-slim" - "pypy:3-slim-buster" django_version: - - "master" - - "3.0.x" # 3.x supports python 3.6 to 3.9 - - "2.2.x" # 2.x supports python 3.4 to 3.7 - - "2.1.x" - - "2.0.x" - - "1.11.x" # 1.11.x supports python 2.7 - - "1.10.x" - - "1.9.x" - - "1.8.x" + - "2.2.x" # 2.2 supports python 3.5 to 3.9 + - "3.2.x" # 3.0 supports python 3.6 to 3.9 + - "main" # 4.0 supports 3.8 to 3.9 exclude: - - python_image: "python:3.8-slim" - django_version: "2.2.x" - - python_image: "python:3.8-slim" - django_version: "2.1.x" - - python_image: "python:3.8-slim" - django_version: "2.0.x" - - python_image: "python:3.8-slim" - django_version: "1.11.x" - - python_image: "python:3.8-slim" - django_version: "1.10.x" - - python_image: "python:3.8-slim" - django_version: "1.9.x" - - python_image: "python:3.8-slim" - django_version: "1.8.x" - - - python_image: "python:3.7-slim" - django_version: "1.10.x" - - python_image: "python:3.7-slim" - django_version: "1.9.x" - - python_image: "python:3.7-slim" - django_version: "1.8.x" - - - python_image: "python:3.6-slim" - django_version: "1.10.x" - python_image: "python:3.6-slim" - django_version: "1.9.x" - - python_image: "python:3.6-slim" - django_version: "1.8.x" - - - python_image: "python:3.5-slim" - django_version: "master" - - python_image: "python:3.5-slim" - django_version: "3.0.x" - - - python_image: "python:3.4-slim" - django_version: "master" - - python_image: "python:3.4-slim" - django_version: "3.0.x" - - - python_image: "python:2.7-slim" - django_version: "master" - - python_image: "python:2.7-slim" - django_version: "3.0.x" - - python_image: "python:2.7-slim" - django_version: "2.2.x" - - python_image: "python:2.7-slim" - django_version: "2.1.x" - - python_image: "python:2.7-slim" - django_version: "2.0.x" - - - python_image: "pypy:2-slim-buster" - django_version: "master" - - python_image: "pypy:2-slim-buster" - django_version: "3.0.x" - - python_image: "pypy:2-slim-buster" - django_version: "2.2.x" - - python_image: "pypy:2-slim-buster" - django_version: "2.1.x" - - python_image: "pypy:2-slim-buster" - django_version: "2.0.x" + django_version: "main" + - python_image: "python:3.7-slim" + django_version: "main" + - python_image: "pypy:3-slim-buster" # on 3.7 as of 2021-07-26 + django_version: "main" jobs: test: @@ -111,7 +48,6 @@ jobs: condition: not: or: - - equal: [ "pypy:2-slim-buster", << parameters.python_image >> ] - equal: [ "pypy:3-slim-buster", << parameters.python_image >> ] steps: - run: @@ -123,7 +59,6 @@ jobs: - when: condition: or: - - equal: [ "pypy:2-slim-buster", << parameters.python_image >> ] - equal: [ "pypy:3-slim-buster", << parameters.python_image >> ] steps: - run: diff --git a/.gitignore b/.gitignore index f5b55d2..90f56c0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.db *.sw[po] .cache +.coverage .tox dist build diff --git a/csp/tests/test_context_processors.py b/csp/tests/test_context_processors.py index 6c4f062..df980a4 100644 --- a/csp/tests/test_context_processors.py +++ b/csp/tests/test_context_processors.py @@ -3,9 +3,11 @@ from csp.middleware import CSPMiddleware from csp.context_processors import nonce +from csp.tests.utils import response + rf = RequestFactory() -mw = CSPMiddleware() +mw = CSPMiddleware(response()) def test_nonce_context_processor(): diff --git a/csp/tests/test_contrib.py b/csp/tests/test_contrib.py index 33998ab..98ccded 100644 --- a/csp/tests/test_contrib.py +++ b/csp/tests/test_contrib.py @@ -3,10 +3,11 @@ from django.test.utils import override_settings from csp.contrib.rate_limiting import RateLimitedCSPMiddleware +from csp.tests.utils import response HEADER = 'Content-Security-Policy' -mw = RateLimitedCSPMiddleware() +mw = RateLimitedCSPMiddleware(response()) rf = RequestFactory() diff --git a/csp/tests/test_decorators.py b/csp/tests/test_decorators.py index 6f2716e..a4bd733 100644 --- a/csp/tests/test_decorators.py +++ b/csp/tests/test_decorators.py @@ -4,10 +4,11 @@ from csp.decorators import csp, csp_replace, csp_update, csp_exempt from csp.middleware import CSPMiddleware +from csp.tests.utils import response REQUEST = RequestFactory().get('/') -mw = CSPMiddleware() +mw = CSPMiddleware(response()) def test_csp_exempt(): diff --git a/csp/tests/test_middleware.py b/csp/tests/test_middleware.py index f9413ce..ce06b24 100644 --- a/csp/tests/test_middleware.py +++ b/csp/tests/test_middleware.py @@ -7,10 +7,11 @@ from django.test.utils import override_settings from csp.middleware import CSPMiddleware +from csp.tests.utils import response HEADER = 'Content-Security-Policy' -mw = CSPMiddleware() +mw = CSPMiddleware(response()) rf = RequestFactory() diff --git a/csp/tests/utils.py b/csp/tests/utils.py index 7d7814f..d3f9a83 100644 --- a/csp/tests/utils.py +++ b/csp/tests/utils.py @@ -1,11 +1,22 @@ +from django.http import HttpResponse from django.template import engines, Template, Context from django.test import RequestFactory from csp.middleware import CSPMiddleware +def response(*args, headers=None, **kwargs): + def get_response(req): + response = HttpResponse(*args, **kwargs) + if headers: + for k, v in headers.items(): + response.headers[k] = v + return response + return get_response + + JINJA_ENV = engines['jinja2'] -mw = CSPMiddleware() +mw = CSPMiddleware(response()) rf = RequestFactory() diff --git a/setup.cfg b/setup.cfg index 260edd9..b92ce01 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ -[wheel] -universal = 1 - [tool:pytest] addopts = -vs --tb=short --pep8 --flakes diff --git a/setup.py b/setup.py index a371bce..b945bdc 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(*parts): install_requires = [ - 'Django>=1.8', + 'Django>=2.2', ] jinja2_requires = [ @@ -32,6 +32,7 @@ def read(*parts): test_requires = [ 'pytest<4.0', + 'pytest-cov', 'pytest-django', 'pytest-flakes==1.0.1', 'pytest-pep8==1.0.6', @@ -78,11 +79,7 @@ def read(*parts): 'Intended Audience :: Developers', 'Topic :: Software Development :: Libraries :: Python Modules', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - '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', diff --git a/tox.ini b/tox.ini index 3618e29..65c4dbd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,8 @@ [tox] envlist = - {3.6,3.7,3.8,3.9,pypy3}-master, - {3.6,3.7,3.8,3.9,pypy3}-3.2.x, - {3.6,3.7,3.8,3.9,pypy3}-3.1.x, - {3.6,3.7,3.8,3.9,pypy3}-3.0.x, - {3.5,3.6,3,7,pypy3}-2.2.x, - {2.7,3.4,3.5,3.6,pypy,pypy3}-2.1.x, - {3.4,3.5,3.6,pypy3}-2.0.x, - {2.7,3.4,3.5,3.6,pypy,pypy3}-1.11.x, - {2.7,3.4,3.5,3.6,pypy}-1.10.x, - {2.7,3.4,3.5,3.6,pypy}-1.9.x, - {2.7,3.4,3.5,3.6,pypy}-1.8.x + {3.6,3.7,3.8,3.9,pypy3}-main + {3.6,3.7,3.8,3.9,pypy3}-3.0.x + {3.6,3,7,3.8,3.9,pypy3}-2.2.x [testenv] setenv = @@ -18,30 +10,16 @@ setenv = PYTHONDONTWRITEBYTECODE=1 commands = pip install --upgrade pip setuptools wheel - pip install pytest-cov - pip install -e . pip install -e .[tests] - py.test --cov={toxinidir}/csp {toxinidir}/csp + pytest --cov={toxinidir}/csp {toxinidir}/csp basepython = - 2.7: python2.7 - 3.4: python3.4 - 3.5: python3.5 3.6: python3.6 3.7: python3.7 3.8: python3.8 3.9: python3.9 - pypy: pypy pypy3: pypy3 deps= pytest - 1.8: Django>=1.8,<1.9 - 1.9: Django>=1.9,<1.10 - 1.10: Django>=1.10,<1.11 - 1.11: Django>=1.11,<1.12 - 2.0: Django>=2.0,<2.1 - 2.1: Django>=2.1,<2.2 - 2.2: Django>=2.2,<2.3 - 3.0: Django>=3.0,<3.1 - 3.1: Django>=3.1,<3.2 - 3.2: Django>=3.2,<4.0 - master: https://github.com/django/django/archive/master.tar.gz + 2.2.x: Django>=2.2,<2.3 + 3.2.x: Django>=3.2,<3.3 + main: https://github.com/django/django/archive/main.tar.gz