Projet

Général

Profil

0001-sms-accept-same-destination-numbers-as-authentic-doe.patch

Nicolas Roche, 31 janvier 2021 10:05

Télécharger (2,65 ko)

Voir les différences:

Subject: [PATCH] sms: accept same destination numbers as authentic does
 (#48864)

 passerelle/sms/models.py |  2 +-
 tests/test_sms.py        | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
passerelle/sms/models.py
39 39
            'description': 'Sender number',
40 40
            'type': 'string',
41 41
        },
42 42
        'to': {
43 43
            'description': 'Destination numbers',
44 44
            "type": "array",
45 45
            "items": {
46 46
                'type': 'string',
47
                'pattern': r'^\+?\d+$'
47
                'pattern': r'^\+?[-.\s/\d]+$'
48 48
            },
49 49
        },
50 50
    }
51 51
}
52 52

  
53 53

  
54 54
class SMSResource(BaseResource):
55 55
    category = _('SMS Providers')
tests/test_sms.py
185 185
        with mock.patch.object(connector, 'send_msg') as send_function:
186 186
            send_function.return_value = {}
187 187
            result = app.post_json(base_path, params=payload)
188 188
            connector.jobs()
189 189
            assert send_function.call_args[1]['text'] == 'not a spam'
190 190
            assert send_function.call_args[1]['stop'] == ('nostop' not in path)
191 191

  
192 192

  
193
@pytest.mark.parametrize('connector', [OVHSMSGateway], indirect=True)
194
@pytest.mark.parametrize('to, destination', [
195
    ('06 12 34 56 78', '0033612345678'),
196
    ('06.12.34.56.78', '0033612345678'),
197
    ('06-12-34-56-78', '0033612345678'),
198
    ('+33/612345678', '0033612345678'),
199
])
200
def test_send_schema(app, connector, to, destination):
201
    base_path = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug)
202
    payload = {
203
        'message': 'not a spam',
204
        'from': '+33699999999',
205
        'to': [to],
206
    }
207
    with mock.patch.object(connector, 'send_msg') as send_function:
208
        app.post_json(base_path, params=payload)
209
        connector.jobs()
210
        assert send_function.call_args[1]['destinations'] == [destination]
211

  
212

  
193 213
def test_ovh_new_api(app, freezer):
194 214
    connector = OVHSMSGateway.objects.create(
195 215
        slug='ovh', account='sms-test42',
196 216
        application_key='RHrTdU2oTsrVC0pu',
197 217
        application_secret='CLjtS69tTcPgCKxedeoZlgMSoQGSiXMa',
198 218
        consumer_key='iF0zi0MJrbjNcI3hvuvwkhNk8skrigxz'
199 219
    )
200 220
    api = ApiUser.objects.create(username='apiuser')
201
-