diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61b76d3a..ea2ee918 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: matrix: os: [ubuntu-20.04] python-version: ['3.8'] - toxenv: [docs, quality, django32] + toxenv: [docs, quality, django32, django42] steps: - uses: actions/checkout@v1 @@ -37,7 +37,7 @@ jobs: run: tox - name: Run coverage - if: matrix.python-version == '3.8' && matrix.toxenv == 'django32' + if: matrix.python-version == '3.8' && matrix.toxenv == 'django42' uses: codecov/codecov-action@v3 with: flags: unittests diff --git a/edx_django_utils/cache/tests/test_middleware.py b/edx_django_utils/cache/tests/test_middleware.py index 9abb4248..57ed08ea 100644 --- a/edx_django_utils/cache/tests/test_middleware.py +++ b/edx_django_utils/cache/tests/test_middleware.py @@ -1,7 +1,7 @@ """ Tests for the RequestCacheMiddleware. """ -from unittest.mock import MagicMock +from unittest.mock import MagicMock, Mock from django.test import RequestFactory, TestCase @@ -17,7 +17,8 @@ class TestRequestCacheMiddleware(TestCase): # pylint: disable=missing-class-doc def setUp(self): super().setUp() - self.middleware = middleware.RequestCacheMiddleware() + self.mock_response = Mock() + self.middleware = middleware.RequestCacheMiddleware(self.mock_response) self.request = RequestFactory().get('/') self.request_cache = RequestCache() @@ -50,7 +51,8 @@ class TestTieredCacheMiddleware(TestCase): # pylint: disable=missing-class-docs def setUp(self): super().setUp() - self.middleware = middleware.TieredCacheMiddleware() + self.mock_response = Mock() + self.middleware = middleware.TieredCacheMiddleware(self.mock_response) self.request = RequestFactory().get('/') self.request.user = self._mock_user(is_staff=True) diff --git a/edx_django_utils/monitoring/tests/test_custom_monitoring.py b/edx_django_utils/monitoring/tests/test_custom_monitoring.py index 0ca65da6..b0bb1954 100644 --- a/edx_django_utils/monitoring/tests/test_custom_monitoring.py +++ b/edx_django_utils/monitoring/tests/test_custom_monitoring.py @@ -3,7 +3,7 @@ Note: See test_middleware.py for the rest of the middleware tests. """ -from unittest.mock import call, patch +from unittest.mock import Mock, call, patch import ddt from django.test import TestCase @@ -32,6 +32,7 @@ class TestCustomMonitoringMiddleware(TestCase): """ def setUp(self): super().setUp() + self.mock_response = Mock() RequestCache.clear_all_namespaces() @patch('newrelic.agent') @@ -62,7 +63,7 @@ def test_accumulate_and_increment( ] # fake a response to trigger attributes reporting - middleware_method = getattr(cached_monitoring_middleware_class(), middleware_method_name) + middleware_method = getattr(cached_monitoring_middleware_class(self.mock_response), middleware_method_name) middleware_method( 'fake request', 'fake response', @@ -101,8 +102,9 @@ def test_accumulate_with_illegal_value( call('error_adding_accumulated_metric', 'name=hello, new_value=10, cached_value=None'), ] + self.mock_response = Mock() # fake a response to trigger metrics reporting - cached_monitoring_middleware_class().process_response( + cached_monitoring_middleware_class(self.mock_response).process_response( 'fake request', 'fake response', ) diff --git a/edx_django_utils/monitoring/tests/test_middleware.py b/edx_django_utils/monitoring/tests/test_middleware.py index 7e58242c..df57d799 100644 --- a/edx_django_utils/monitoring/tests/test_middleware.py +++ b/edx_django_utils/monitoring/tests/test_middleware.py @@ -27,7 +27,8 @@ class TestMonitoringMemoryMiddleware(TestCase): @override_switch('edx_django_utils.monitoring.enable_memory_middleware', False) @patch('edx_django_utils.monitoring.internal.middleware.log') def test_memory_monitoring_when_disabled(self, mock_logger): - MonitoringMemoryMiddleware().process_response( + mock_response = Mock() + MonitoringMemoryMiddleware(mock_response).process_response( 'fake request', 'fake response', ) @@ -37,7 +38,8 @@ def test_memory_monitoring_when_disabled(self, mock_logger): @patch('edx_django_utils.monitoring.internal.middleware.log') def test_memory_monitoring_when_enabled(self, mock_logger): request = RequestFactory().get('/') - MonitoringMemoryMiddleware().process_response( + mock_response = Mock() + MonitoringMemoryMiddleware(mock_response).process_response( request, 'fake response', ) diff --git a/setup.py b/setup.py index 37dd9383..19c8d394 100644 --- a/setup.py +++ b/setup.py @@ -128,6 +128,7 @@ def is_requirement(line): 'Development Status :: 3 - Alpha', 'Framework :: Django', 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.2', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Natural Language :: English', diff --git a/tox.ini b/tox.ini index 398302f4..7925aee8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38-django{32} +envlist = py38-django{32, 42} [doc8] ignore = D000, D001 @@ -38,6 +38,7 @@ norecursedirs = .* docs requirements [testenv] deps = django32: Django>=3.2,<4.0 + django42: Django>=4.2,<4.3 -r{toxinidir}/requirements/test.txt commands = python -Wd -m pytest {posargs}