1 |
1 |
import datetime
|
2 |
2 |
import pytest
|
|
3 |
from mock import patch
|
3 |
4 |
|
4 |
5 |
from django.utils import timezone
|
5 |
6 |
|
... | ... | |
18 |
19 |
connector = OpenGIS(slug='plop', wms_service_url='http://username@example.net:secret@www.example.net')
|
19 |
20 |
assert 'http://***:***@www.example.net' in [x[1] for x in connector.get_description_fields()]
|
20 |
21 |
|
|
22 |
|
21 |
23 |
def test_get_description_secret_fields(db):
|
22 |
24 |
connector = ClicRdv(slug='plop', apikey='secret1', username='plop', password='secret2')
|
23 |
25 |
assert not 'secret1' in [x[1] for x in connector.get_description_fields()]
|
... | ... | |
38 |
40 |
|
39 |
41 |
connector.daily()
|
40 |
42 |
assert ResourceLog.objects.all().count() == 1
|
|
43 |
|
|
44 |
@pytest.fixture
|
|
45 |
def email_handler():
|
|
46 |
import logging
|
|
47 |
from django.utils.log import AdminEmailHandler
|
|
48 |
|
|
49 |
root = logging.getLogger()
|
|
50 |
handler = AdminEmailHandler(include_html=True)
|
|
51 |
handler.level = logging.ERROR
|
|
52 |
root.handlers.append(handler)
|
|
53 |
try:
|
|
54 |
yield
|
|
55 |
finally:
|
|
56 |
root.handlers.remove(handler)
|
|
57 |
|
|
58 |
|
|
59 |
def test_trace_emails(app, settings, dummy_csv_datasource, email_handler, mailoutbox):
|
|
60 |
from .utils import generic_endpoint_url
|
|
61 |
|
|
62 |
settings.ADMINS = [('admin', 'admin@example.net')]
|
|
63 |
|
|
64 |
logging_parameters = dummy_csv_datasource.logging_parameters
|
|
65 |
logging_parameters.save()
|
|
66 |
|
|
67 |
assert not mailoutbox
|
|
68 |
|
|
69 |
with patch.object(dummy_csv_datasource.__class__,
|
|
70 |
'execute_query',
|
|
71 |
side_effect=ValueError('coin'), autospec=True):
|
|
72 |
|
|
73 |
app.get(generic_endpoint_url(connector='csvdatasource',
|
|
74 |
endpoint='query/dummy-query/',
|
|
75 |
slug=dummy_csv_datasource.slug),
|
|
76 |
status=500)
|
|
77 |
|
|
78 |
assert len(mailoutbox) == 1
|
|
79 |
assert mailoutbox[0].to == ['admin@example.net']
|
|
80 |
|
|
81 |
logging_parameters.trace_emails = 'john.doe@example.net'
|
|
82 |
logging_parameters.save()
|
|
83 |
app.get(generic_endpoint_url(connector='csvdatasource',
|
|
84 |
endpoint='query/dummy-query/',
|
|
85 |
slug=dummy_csv_datasource.slug),
|
|
86 |
status=500)
|
|
87 |
|
|
88 |
assert len(mailoutbox) == 2
|
|
89 |
assert mailoutbox[0].to == ['admin@example.net']
|
|
90 |
assert mailoutbox[1].to == ['john.doe@example.net']
|
41 |
|
-
|