0001-esirius_swi-compute-status-on-response-60958.patch
passerelle/contrib/esirius_swi/models.py | ||
---|---|---|
19 | 19 |
import zeep |
20 | 20 |
from django.db import models |
21 | 21 |
from django.utils.translation import ugettext_lazy as _ |
22 | 22 | |
23 | 23 |
from passerelle.base.models import BaseResource |
24 | 24 |
from passerelle.utils.api import endpoint |
25 | 25 |
from passerelle.utils.jsonresponse import APIError |
26 | 26 | |
27 |
from . import utils |
|
28 | ||
27 | 29 | |
28 | 30 |
class ESiriusSwi(BaseResource): |
29 | 31 |
base_url = models.URLField(_('Base API URL'), help_text=_('with trailing slash')) |
30 | 32 |
verify_cert = models.BooleanField(default=True, verbose_name=_('Check HTTPS Certificate validity')) |
31 | 33 | |
32 | 34 |
category = _('Business Process Connectors') |
33 | 35 | |
34 | 36 |
class Meta: |
... | ... | |
74 | 76 |
'realMaxWaitingTime', |
75 | 77 |
'resourceNumber', |
76 | 78 |
'serviceWaitingIndicatorWSList', |
77 | 79 |
'siteCode', |
78 | 80 |
'waitingVisitorNumber', |
79 | 81 |
'weekHoursWS', |
80 | 82 |
]: |
81 | 83 |
item_dest[key] = item_src[key] |
84 |
utils.compute_status(item_dest) |
|
82 | 85 |
data.append(item_dest) |
83 | 86 |
return {'err': 0, 'data': data} |
passerelle/contrib/esirius_swi/utils.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Copyright (C) 2022 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 | ||
18 |
def compute_status(data): |
|
19 |
data.update( |
|
20 |
{ |
|
21 |
'closed': not data['resourceNumber'] or data['estimatedAvgWaitingTime'] == '-', |
|
22 |
'estimatedAvgWaitingTimeInMinutes': None, |
|
23 |
} |
|
24 |
) |
|
25 |
if not data['closed']: |
|
26 |
values = [int(x) for x in data['estimatedAvgWaitingTime'].split(':')] |
|
27 |
data['estimatedAvgWaitingTimeInMinutes'] = 60 * values[0] + values[1] + 1 |
tests/test_esirius_swi.py | ||
---|---|---|
16 | 16 |
import json |
17 | 17 |
import os |
18 | 18 | |
19 | 19 |
import mock |
20 | 20 |
import pytest |
21 | 21 |
import utils |
22 | 22 | |
23 | 23 |
from passerelle.contrib.esirius_swi.models import ESiriusSwi |
24 |
from passerelle.contrib.esirius_swi.utils import compute_status |
|
24 | 25 | |
25 | 26 |
pytestmark = pytest.mark.django_db |
26 | 27 | |
27 | 28 |
TEST_BASE_DIR = os.path.join(os.path.dirname(__file__), 'data', 'esirius_swi') |
28 | 29 | |
29 | 30 | |
30 | 31 |
def get_xml_file(filename): |
31 | 32 |
with open(os.path.join(TEST_BASE_DIR, filename), 'rb') as desc: |
... | ... | |
60 | 61 |
status_code=200, |
61 | 62 |
headers={'Content-Type': 'text/xml'}, |
62 | 63 |
) |
63 | 64 |
resp = app.get('/esirius-swi/test/get_all_indicators') |
64 | 65 |
assert resp.json['err'] == 1 |
65 | 66 |
assert resp.json['err_desc'] == "'NoneType' object has no attribute 'getroottree'" |
66 | 67 | |
67 | 68 | |
69 |
@pytest.mark.parametrize( |
|
70 |
'resource, time, closed, minutes', |
|
71 |
[ |
|
72 |
(0, '00:01:39', True, None), |
|
73 |
(1, '-', True, None), |
|
74 |
(2, '00:01:39', False, 2), |
|
75 |
(99, '01:59:00', False, 120), |
|
76 |
], |
|
77 |
) |
|
78 |
def test_status(resource, time, closed, minutes): |
|
79 |
data = { |
|
80 |
'resourceNumber': resource, |
|
81 |
'estimatedAvgWaitingTime': time, |
|
82 |
} |
|
83 |
compute_status(data) |
|
84 |
assert data == { |
|
85 |
'resourceNumber': resource, |
|
86 |
'estimatedAvgWaitingTime': time, |
|
87 |
'closed': closed, |
|
88 |
'estimatedAvgWaitingTimeInMinutes': minutes, |
|
89 |
} |
|
90 | ||
91 | ||
68 | 92 |
@mock.patch('passerelle.utils.Request.get') |
69 | 93 |
@mock.patch('passerelle.utils.Request.post') |
70 | 94 |
def test_get_all_indicator(mocked_post, mocked_get, v1_service_wsdl, connector, app): |
71 | 95 |
mocked_get.return_value = mock.Mock(content=v1_service_wsdl) |
72 | 96 |
mocked_post.return_value = mock.Mock( |
73 | 97 |
content=get_xml_file('get_all_indicators.xml'), |
74 | 98 |
status_code=200, |
75 | 99 |
headers={'Content-Type': 'text/xml'}, |
... | ... | |
85 | 109 |
'name': "Braine-l'Alleud", |
86 | 110 |
'realAvgWaitingTime': '00:03:51', |
87 | 111 |
'realMaxWaitingTime': '00:06:42', |
88 | 112 |
'resourceNumber': 9.000003, |
89 | 113 |
'serviceWaitingIndicatorWSList': None, |
90 | 114 |
'siteCode': 'site1', |
91 | 115 |
'waitingVisitorNumber': None, |
92 | 116 |
'weekHoursWS': None, |
117 |
'closed': False, |
|
118 |
'estimatedAvgWaitingTimeInMinutes': 4, |
|
93 | 119 |
} |
94 | 120 |
] |
95 |
- |