From a7c61f9c6c56417a4f427fd33ccf6f2618455b7d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 7 Dec 2017 14:14:01 +0100 Subject: [PATCH 1/2] tests: add dummy connector to test failure behaviours (#20498) --- tests/settings.py | 18 ++++++++++++++++++ tests/test_dummy.py | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/test_dummy.py diff --git a/tests/settings.py b/tests/settings.py index 9de1612..3ded95b 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -31,6 +31,7 @@ INSTALLED_APPS += ( 'passerelle.contrib.teamnet_axel', 'passerelle.contrib.tlmcom', 'passerelle.contrib.tcl', + 'passerelle.apps.dummy', ) PASSERELLE_APP_FAKE_FAMILY_ENABLED = True @@ -45,3 +46,20 @@ PASSERELLE_APP_GRANDLYON_STREETSECTIONS_ENABLED = True TCL_URL_TEMPLATE = 'http://tcl.example.net/%s' TCL_GEOJSON_URL_TEMPLATE = 'http://tcl.example.net/geojson/%s' + +LOGGING['handlers'].update({ + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler', + 'include_html': True, + }, +}) + +LOGGING['loggers']['django.request']['handlers'].append('mail_admins') +LOGGING['loggers']['passerelle.jsonresponse'] = { + 'handlers': ['mail_admins'], + 'level': 'INFO', +} +ADMINS = [ + ('Admin', 'admin@example.net'), +] diff --git a/tests/test_dummy.py b/tests/test_dummy.py new file mode 100644 index 0000000..8d522f0 --- /dev/null +++ b/tests/test_dummy.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +import pytest + +from django.contrib.contenttypes.models import ContentType + +from passerelle.base.models import ApiUser, AccessRight +from passerelle.apps.dummy.models import DummyConnector + + +@pytest.fixture() +def dummy(db): + api = ApiUser.objects.create(username='all', keytype='', key='') + + conn = DummyConnector.objects.create(slug='dummy') + obj_type = ContentType.objects.get_for_model(conn) + AccessRight.objects.create(codename='can_access', apiuser=api, + resource_type=obj_type, + resource_pk=conn.pk) + return conn + +@pytest.mark.xfail +def test_exception_with_utf8(app, dummy, mailoutbox, caplog): + app.get('/dummy/dummy/exception_with_utf8/', status=500) + assert u'Exception: é' in mailoutbox[0].body -- 2.1.4