diff --git a/chrono/settings.py b/chrono/settings.py index 766b06e6..ee5ea957 100644 --- a/chrono/settings.py +++ b/chrono/settings.py @@ -121,6 +121,11 @@ TEMPLATES = [ 'django.template.context_processors.tz', 'django.template.context_processors.request', 'django.contrib.messages.context_processors.messages', + 'publik_django_templatetags.wcs.context_processors.cards', + ], + 'builtins': [ + 'publik_django_templatetags.publik.templatetags.publik', + 'publik_django_templatetags.wcs.templatetags.wcs', ], }, }, diff --git a/debian/control b/debian/control index 8411019a..ed01b81e 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,8 @@ Depends: ${misc:Depends}, ${python3:Depends}, python3-django (>= 2:2.2), python3-gadjo, python3-requests, - python3-uwsgidecorators + python3-uwsgidecorators, + python3-publik-django-templatetags Recommends: python3-django-mellon Description: Agendas System (Python 3 module) diff --git a/tests/conftest.py b/tests/conftest.py index d8656126..5caa6c0c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,3 +14,12 @@ def app(request): @pytest.fixture(autouse=True) def media_root(settings, tmpdir): settings.MEDIA_ROOT = str(tmpdir.mkdir('media_root')) + + +@pytest.fixture +def nocache(settings): + settings.CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } + } diff --git a/tests/test_wcs_templatetags.py b/tests/test_wcs_templatetags.py new file mode 100644 index 00000000..5e561e4c --- /dev/null +++ b/tests/test_wcs_templatetags.py @@ -0,0 +1,35 @@ +import json +from unittest import mock + +import pytest +from django.template import Context, Template +from django.test.client import RequestFactory +from publik_django_templatetags.wcs.context_processors import Cards + + +@pytest.fixture +def context(): + return Context( + { + 'cards': Cards(), + 'request': RequestFactory().get('/'), + } + ) + + +class MockedRequestResponse(mock.Mock): + status_code = 200 + + def json(self): + return json.loads(self.content) + + +def mocked_requests_send(request, **kwargs): + data = [{'id': 1, 'fields': {'foo': 'bar'}}, {'id': 2, 'fields': {'foo': 'baz'}}] # fake result + return MockedRequestResponse(content=json.dumps({'data': data})) + + +@mock.patch('requests.Session.send', side_effect=mocked_requests_send) +def test_publik_django_templatetags_integration(mock_send, context, nocache): + t = Template('{{ cards|objects:"foo"|count }}') + assert t.render(context) == "2" diff --git a/tox.ini b/tox.ini index c8bb0f9c..0513619f 100644 --- a/tox.ini +++ b/tox.ini @@ -29,6 +29,7 @@ deps = django22: django>=2.2,<2.3 psycopg2-binary<2.9 codestyle: pre-commit + git+https://git.entrouvert.org/publik-django-templatetags.git commands = ./getlasso3.sh python3 setup.py compile_translations @@ -50,6 +51,7 @@ deps = django-mellon>=1.6.1 pytest-freezegun psycopg2-binary<2.9 + git+https://git.entrouvert.org/publik-django-templatetags.git commands = ./getlasso3.sh pylint: ./pylint.sh chrono/ tests/