Projet

Général

Profil

0001-workflows-mark-sms-transmission-errors-47045.patch

Frédéric Péters, 23 octobre 2021 21:10

Télécharger (2,74 ko)

Voir les différences:

Subject: [PATCH] workflows: mark sms transmission errors (#47045)

 tests/workflow/test_all.py | 13 ++++++++++++-
 wcs/qommon/sms.py          | 10 ++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)
tests/workflow/test_all.py
2580 2580
    assert len(sms_mocking.sms) == 4
2581 2581

  
2582 2582

  
2583
def test_sms_with_passerelle(pub):
2583
def test_sms_with_passerelle(two_pubs):
2584
    pub = two_pubs
2584 2585
    pub.cfg['sms'] = {
2585 2586
        'mode': 'passerelle',
2586 2587
        'passerelle_url': 'http://passerelle.example.com/send?nostop=1',
......
2615 2616
            assert json_payload['to'] == ['1234']
2616 2617
            assert json_payload['from'] == 'Passerelle'
2617 2618

  
2619
    if pub.is_using_postgresql():
2620
        pub.loggederror_class.wipe()
2621
        with mock.patch('wcs.wscalls.get_secret_and_orig') as mocked_secret_and_orig:
2622
            mocked_secret_and_orig.return_value = ('secret', 'localhost')
2623
            with mock.patch('wcs.qommon.misc._http_request') as mocked_http_post:
2624
                mocked_http_post.return_value = (mock.Mock(headers={}), 400, '{"err": 1}', 'headers')
2625
                item.perform(formdata)
2626
                assert pub.loggederror_class.count() == 1
2627
                assert pub.loggederror_class.select()[0].summary == 'Could not send SMS'
2628

  
2618 2629

  
2619 2630
def test_display_form(two_pubs):
2620 2631
    formdef = FormDef()
wcs/qommon/sms.py
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from wcs.wscalls import call_webservice
17
from wcs.wscalls import call_webservice, get_app_error_code
18 18

  
19 19
from . import get_cfg, get_logger
20
from .errors import SMSError
20 21

  
21 22

  
22 23
class PasserelleSMS:
......
35 36
            'to': destinations,
36 37
        }
37 38

  
38
        data = call_webservice(self.url, method='POST', post_data=payload)[2]
39
        response, status, data = call_webservice(self.url, method='POST', post_data=payload)
40
        app_error_code = None
41
        if status == 200:
42
            app_error_code = get_app_error_code(response, data, 'json')
43
        if status != 200 or app_error_code:
44
            raise SMSError()
39 45
        get_logger().debug('sms %r sent using passerelle to %r, result: %r', text, destinations, data)
40 46

  
41 47

  
42
-