tests: do not rely on httpbin (#73655) #214

Merged
ecazenave merged 1 commits from wip/24828-httpbin into main 2023-04-17 21:13:10 +02:00
1 changed files with 12 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import warnings
from unittest import mock
import pytest
import responses
from django.urls import reverse
import tests.utils
@ -683,13 +684,19 @@ def test_endpoint_cache(app, db, monkeypatch):
assert resp1.json_body != resp6.json_body
def test_endpoint_cookies(app, db, monkeypatch, httpbin):
def test_endpoint_cookies(app, db, monkeypatch):
@endpoint(methods=['get'])
def httpcall(obj, request):
response = obj.requests.get(httpbin.url + '/cookies/set?foo=bar', allow_redirects=False)
cookie1 = response.request.headers.get('Cookie')
response = obj.requests.get(httpbin.url + '/get')
cookie2 = response.request.headers.get('Cookie')
with responses.RequestsMock() as rsps:
rsps.get('https://foo.invalid/set-cookie', json={}, headers={"set-cookie": "foo=bar;"})
rsps.get(
'https://foo.invalid/get',
json={},
)
response = obj.requests.get('https://foo.invalid/set-cookie', allow_redirects=False)
cookie1 = response.request.headers.get('Cookie')
response = obj.requests.get('https://foo.invalid/get')
cookie2 = response.request.headers.get('Cookie')
return {'cookie1': cookie1, 'cookie2': cookie2}
monkeypatch.setattr(StubInvoicesConnector, 'httpcall', httpcall, raising=False)