Project

General

Profile

Bug #53697

Updated by Frédéric Péters about 2 months ago

Suite à #53594,

https://jenkins.entrouvert.org/job/passerelle/2126/

<pre>
connector = <ESirius: >, secret_key = 'xxx'

@pytest.mark.parametrize('secret_key', ['xxx', ''])
def test_pre_request(connector, secret_key):
@httmock.urlmatch(netloc='esirius.example.net', path='/an/uri/', method='GET')
def esirius_mock(url, request):
assert request.headers['Accept'] == 'application/json; charset=utf-8'
assert bool(request.headers.get('token_info_caller')) == bool(secret_key)
if secret_key:
assert request.headers['token_info_caller'][:42] == b'f3G6sjRZETBam6vcdrAxmvJQTX5hh6OjZ8XlUO6SMo'
return httmock.response(200)

connector.secret_key = secret_key
connector.save()
with httmock.HTTMock(esirius_mock):
> connector.request('an/uri/', method='get', params="somes")

tests/test_esirius.py:122:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
passerelle/apps/esirius/models.py:152: in request
response = self.requests.request(method=method, url=url, headers=headers, params=params, json=json)
passerelle/utils/__init__.py:300: in request
response = super(Request, self).request(method, url, **kwargs)
/tmp/tox-jenkins/passerelle/py3-django111-black-coverage/lib/python3.7/site-packages/requests/sessions.py:542: in request
resp = self.send(prep, **send_kwargs)
passerelle/utils/__init__.py:317: in send
response = super(Request, self).send(request, **kwargs)
/tmp/tox-jenkins/passerelle/py3-django111-black-coverage/lib/python3.7/site-packages/httmock.py:163: in _fake_send
response = self.intercept(request, **kwargs)
/tmp/tox-jenkins/passerelle/py3-django111-black-coverage/lib/python3.7/site-packages/httmock.py:221: in intercept
res = first_of(self.handlers, url, request)
/tmp/tox-jenkins/passerelle/py3-django111-black-coverage/lib/python3.7/site-packages/httmock.py:141: in first_of
res = handler(*args, **kwargs)
/tmp/tox-jenkins/passerelle/py3-django111-black-coverage/lib/python3.7/site-packages/httmock.py:100: in inner
return func(self_or_url, url_or_request, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

url = SplitResult(scheme='https', netloc='esirius.example.net', path='/an/uri/', query='somes', fragment='')
request = <PreparedRequest [GET]>

@httmock.urlmatch(netloc='esirius.example.net', path='/an/uri/', method='GET')
def esirius_mock(url, request):
assert request.headers['Accept'] == 'application/json; charset=utf-8'
assert bool(request.headers.get('token_info_caller')) == bool(secret_key)
if secret_key:
> assert request.headers['token_info_caller'][:42] == b'f3G6sjRZETBam6vcdrAxmvJQTX5hh6OjZ8XlUO6SMo'
E AssertionError: assert b'f3G6sjRZETB...6OjILg+vGd6TG' == b'f3G6sjRZETB...6OjZ8XlUO6SMo'
E At index 32 diff: b'I' != b'Z'
E Use -v to get the full diff
</pre>

Back