0001-tests-add-dummy-connector-to-test-failure-behaviours.patch
passerelle/apps/dummy/migrations/0001_initial.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('base', '0005_resourcelog'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.CreateModel( |
|
15 |
name='DummyConnector', |
|
16 |
fields=[ |
|
17 |
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
|
18 |
('title', models.CharField(max_length=50)), |
|
19 |
('slug', models.SlugField()), |
|
20 |
('description', models.TextField()), |
|
21 |
('log_level', models.CharField(default=b'INFO', max_length=10, verbose_name='Log Level', choices=[(b'NOTSET', b'NOTSET'), (b'DEBUG', b'DEBUG'), (b'INFO', b'INFO'), (b'WARNING', b'WARNING'), (b'ERROR', b'ERROR'), (b'CRITICAL', b'CRITICAL'), (b'FATAL', b'FATAL')])), |
|
22 |
('users', models.ManyToManyField(to='base.ApiUser', blank=True)), |
|
23 |
], |
|
24 |
options={ |
|
25 |
'verbose_name': 'Dummy connector', |
|
26 |
}, |
|
27 |
), |
|
28 |
] |
passerelle/apps/dummy/models.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
3 |
from django.utils.translation import ugettext_lazy as _ |
|
4 | ||
5 |
from passerelle.base.models import BaseResource |
|
6 |
from passerelle.utils.api import endpoint |
|
7 | ||
8 | ||
9 |
class DummyConnector(BaseResource): |
|
10 |
class Meta: |
|
11 |
verbose_name = _('Dummy connector') |
|
12 | ||
13 |
@endpoint(pattern='(?P<q>.+)?$') |
|
14 |
def exception_with_utf8(self, request, **kwargs): |
|
15 |
raise Exception('é') |
tests/settings.py | ||
---|---|---|
31 | 31 |
'passerelle.contrib.teamnet_axel', |
32 | 32 |
'passerelle.contrib.tlmcom', |
33 | 33 |
'passerelle.contrib.tcl', |
34 |
'passerelle.apps.dummy', |
|
34 | 35 |
) |
35 | 36 | |
36 | 37 |
PASSERELLE_APP_FAKE_FAMILY_ENABLED = True |
... | ... | |
45 | 46 | |
46 | 47 |
TCL_URL_TEMPLATE = 'http://tcl.example.net/%s' |
47 | 48 |
TCL_GEOJSON_URL_TEMPLATE = 'http://tcl.example.net/geojson/%s' |
49 | ||
50 |
LOGGING['handlers'].update({ |
|
51 |
'mail_admins': { |
|
52 |
'level': 'ERROR', |
|
53 |
'class': 'django.utils.log.AdminEmailHandler', |
|
54 |
'include_html': True, |
|
55 |
}, |
|
56 |
}) |
|
57 | ||
58 |
LOGGING['loggers']['django.request']['handlers'].append('mail_admins') |
|
59 |
LOGGING['loggers']['passerelle.jsonresponse'] = { |
|
60 |
'handlers': ['mail_admins'], |
|
61 |
'level': 'INFO', |
|
62 |
} |
|
63 |
ADMINS = [ |
|
64 |
('Admin', 'admin@example.net'), |
|
65 |
] |
tests/test_dummy.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
3 |
import pytest |
|
4 | ||
5 |
from django.contrib.contenttypes.models import ContentType |
|
6 | ||
7 |
from passerelle.base.models import ApiUser, AccessRight |
|
8 |
from passerelle.apps.dummy.models import DummyConnector |
|
9 | ||
10 | ||
11 |
@pytest.fixture() |
|
12 |
def dummy(db): |
|
13 |
api = ApiUser.objects.create(username='all', keytype='', key='') |
|
14 | ||
15 |
conn = DummyConnector.objects.create(slug='dummy') |
|
16 |
obj_type = ContentType.objects.get_for_model(conn) |
|
17 |
AccessRight.objects.create(codename='can_access', apiuser=api, |
|
18 |
resource_type=obj_type, |
|
19 |
resource_pk=conn.pk) |
|
20 |
return conn |
|
21 | ||
22 |
@pytest.mark.xfail |
|
23 |
def test_exception_with_utf8(app, dummy, mailoutbox, caplog): |
|
24 |
app.get('/dummy/dummy/exception_with_utf8/', status=500) |
|
25 |
assert u'Exception: é' in mailoutbox[0].body |
|
0 |
- |