From 062126e50c9eac105bf9f52d55e95ef208e96e16 Mon Sep 17 00:00:00 2001 From: Paulo Romeira Date: Wed, 3 Jun 2020 21:42:11 -0300 Subject: [PATCH] tests/aiohttp: Add cookies test --- tests/integration/test_aiohttp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index dd9c4d8..5a646ef 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -1,5 +1,6 @@ import contextlib import logging +import urllib.parse import pytest @@ -319,3 +320,23 @@ def test_double_requests(tmpdir): # Now that we made both requests, we should have played both. assert cassette.play_count == 2 + + +def test_cookies(scheme, tmpdir): + url = scheme + ( + '://httpbin.org/response-headers?' + 'set-cookie=' + urllib.parse.quote('cookie_1=val_1; Path=/') + '&' + 'Set-Cookie=' + urllib.parse.quote('Cookie_2=Val_2; Path=/') + ) + with vcr.use_cassette(str(tmpdir.join("cookies.yaml"))) as cassette: + response, _ = get(url, output='json') + + assert response.cookies.get('cookie_1').value == 'val_1' + assert response.cookies.get('Cookie_2').value == 'Val_2' + + with vcr.use_cassette(str(tmpdir.join("cookies.yaml"))) as cassette: + response, _ = get(url, output='json') + assert cassette.play_count == 1 + + assert response.cookies.get('cookie_1').value == 'val_1' + assert response.cookies.get('Cookie_2').value == 'Val_2'