Projet

Général

Profil

Development #23677

sms ovh: utiliser self.requests

Ajouté par Thomas Noël il y a presque 6 ans. Mis à jour il y a plus de 5 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
Version cible:
-
Début:
11 mai 2018
Echéance:
% réalisé:

0%

Temps estimé:
Patch proposed:
Oui
Planning:

Description

Parce que ça aide beaucoup pour comprendre ce qui se passe de l'autre côté.


Fichiers


Demandes liées

Lié à Publik - Bug #24285: pas de retour visible lorsqu'un SMS n'a pas réussi à être envoyéNouveau05 juin 2018

Actions

Révisions associées

Révision 8a3268bf (diff)
Ajouté par Thomas Noël il y a presque 6 ans

ovh: use BaseResource.requests instead of requests (#23677)

Historique

#1

Mis à jour par Thomas Noël il y a presque 6 ans

  • Assigné à Thomas Noël supprimé

Donc c'est :

diff --git a/passerelle/apps/ovh/models.py b/passerelle/apps/ovh/models.py
index 28caf37..01dfdd2 100644
--- a/passerelle/apps/ovh/models.py
+++ b/passerelle/apps/ovh/models.py
@@ -102,7 +102,7 @@ class OVHSMSGateway(BaseResource, SMSGatewayMixin):
         if not kwargs['stop']:
             params.update({'noStop': 1})
         try:
-            response = requests.post(self.URL, data=params)
+            response = self.requests.post(self.URL, data=params)
         except requests.RequestException as e:
             raise APIError('OVH error: POST failed, %s' % e)
         else:

Mais les tests plantent et vraiment, je n'arrive pas à comprendre du tout comment remettre ça droit.

tests/test_sms.py ....F......                                                                                                               [100%]

==================================================================== FAILURES =====================================================================
_________________________________________________________ test_connectors[OVHSMSGateway] __________________________________________________________

app = <django_webtest.DjangoTestApp object at 0x7fe762dcc090>, connector = <OVHSMSGateway: OVHSMSGateway>

    def test_connectors(app, connector):
        path = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug)
        result = app.post_json(path, params={})
        assert result.json['err'] == 1
        assert result.json['err_desc'].startswith('Payload error: ')

        payload = {
            'message': 'hello',
            'from': '+33699999999',
            'to': ['+33688888888', '+33677777777'],
        }
        for test_vector in getattr(connector, 'TEST_DEFAULTS', {}).get('test_vectors', []):
            with utils.mock_url(connector.URL, test_vector['response']):
>               result = app.post_json(path, params=payload)

tests/test_sms.py:59: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/django_webtest/__init__.py:173: in post_json
    return super(DjangoTestApp, self).post_json(url, **kwargs)
/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/webtest/utils.py:36: in wrapper
    return self._gen_request(method, url, **kw)
/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/webtest/app.py:755: in _gen_request
    expect_errors=expect_errors)
/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/django_webtest/__init__.py:87: in do_request
    expect_errors)
/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/webtest/app.py:651: in do_request
    self._check_status(status, res)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <django_webtest.DjangoTestApp object at 0x7fe762dcc090>, status = None
res = <500 INTERNAL SERVER ERROR application/json body='{"err": 1...or"}'/115>

    def _check_status(self, status, res):
        if status == '*':
            return
        res_status = res.status
        if (isinstance(status, string_types) and '*' in status):
            if re.match(fnmatch.translate(status), res_status, re.I):
                return
        if isinstance(status, string_types):
            if status == res_status:
                return
        if isinstance(status, (list, tuple)):
            if res.status_int not in status:
                raise AppError(
                    "Bad response: %s (not one of %s for %s)\n%s",
                    res_status, ', '.join(map(str, status)),
                    res.request.url, res)
            return
        if status is None:
            if res.status_int >= 200 and res.status_int < 400:
                return
            raise AppError(
                "Bad response: %s (not 200 OK or 3xx redirect for %s)\n%s",
                res_status, res.request.url,
>               res)
E           AppError: Bad response: 500 INTERNAL SERVER ERROR (not 200 OK or 3xx redirect for http://testserver/ovh/ovhsmsgateway/send/)
E           {"err": 1, "data": null, "err_desc": "'NoneType' object has no attribute 'headers'", "err_class": "AttributeError"}

/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/webtest/app.py:683: AppError
-------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------
endpoint POST /ovh/ovhsmsgateway/send/ ('{}') 
endpoint POST /ovh/ovhsmsgateway/send/ ('{"from": "+33699999999", "message": "hello", "to": ["+33688888888", "+33677777777"]}') 
POST https://www.ovh.com/cgi-bin/sms/http2sms.cgi 
---------------------------------------------------------------- Captured log call ----------------------------------------------------------------
models.py                  523 INFO     endpoint POST /ovh/ovhsmsgateway/send/ ('{}') 
jsonresponse.py            138 WARNING  Error occurred while processing request
models.py                  523 INFO     endpoint POST /ovh/ovhsmsgateway/send/ ('{"from": "+33699999999", "message": "hello", "to": ["+33688888888", "+33677777777"]}') 
models.py                  523 INFO     POST https://www.ovh.com/cgi-bin/sms/http2sms.cgi 
jsonresponse.py            129 ERROR    Error occurred while processing request
Traceback (most recent call last):
  File "/home/thomas/dev/publik/src/passerelle/passerelle/utils/jsonresponse.py", line 117, in api
    resp = f(*args, **kwargs)
  File "/home/thomas/dev/publik/src/passerelle/passerelle/views.py", line 320, in perform
    return self.endpoint(request, **self.get_params(request, *args, **kwargs))
  File "/home/thomas/dev/publik/src/passerelle/passerelle/sms/__init__.py", line 56, in send
    return {'data': self.send_msg(data['message'], data['from'], data['to'], stop=True)}
  File "/home/thomas/dev/publik/src/passerelle/passerelle/apps/ovh/models.py", line 105, in send_msg
    response = self.requests.post(self.URL, data=params)
  File "/tmp/tox-thomas/passerelle/coverage-django18-pylint/local/lib/python2.7/site-packages/requests/sessions.py", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/thomas/dev/publik/src/passerelle/passerelle/utils/__init__.py", line 227, in request
    '%s: %s | ' % (k,v) for k,v in response.request.headers.items()
AttributeError: 'NoneType' object has no attribute 'headers'
#2

Mis à jour par Emmanuel Cazenave il y a presque 6 ans

  • Assigné à mis à Emmanuel Cazenave
#3

Mis à jour par Frédéric Péters il y a presque 6 ans

Désolé Emmanuel, pas vu.

--- a/tests/utils.py
+++ b/tests/utils.py
@@ -37,7 +37,7 @@ def mock_url(url, response):

     @httmock.urlmatch(netloc=parsed.netloc, path=parsed.path)
     def mocked(url, request):
-        return response
+        return httmock.response(200, response, request=request)
     return httmock.HTTMock(mocked)
#4

Mis à jour par Thomas Noël il y a presque 6 ans

Merci Frédéric (même si en vérité j'ai juste vu que ça marche et renoncé à comprendre).

#5

Mis à jour par Emmanuel Cazenave il y a presque 6 ans

ack

#6

Mis à jour par Thomas Noël il y a presque 6 ans

  • Statut changé de En cours à Résolu (à déployer)
commit 8a3268bf9eb837c62e431012c5d72a6743e281d8
Author: Thomas NOEL <tnoel@entrouvert.com>
Date:   Fri May 11 10:40:07 2018 +0200

    ovh: use BaseResource.requests instead of requests (#23677)

#7

Mis à jour par Thomas Noël il y a presque 6 ans

  • Lié à Bug #24285: pas de retour visible lorsqu'un SMS n'a pas réussi à être envoyé ajouté
#8

Mis à jour par Benjamin Dauvergne il y a plus de 5 ans

  • Statut changé de Résolu (à déployer) à Fermé

Formats disponibles : Atom PDF