pricing: publik-django-templatetags integration (#64561)

This commit is contained in:
Lauréline Guérin 2022-05-05 14:51:37 +02:00
parent 687fe2e9c3
commit eb67f72b35
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 53 additions and 1 deletions

View File

@ -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',
],
},
},

3
debian/control vendored
View File

@ -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)

View File

@ -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',
}
}

View File

@ -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"

View File

@ -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/