Skip to content

Commit

Permalink
Merge pull request #7 from tomsender/support-cookie-in-formation-reqesut
Browse files Browse the repository at this point in the history
Support cookie in Formation request
  • Loading branch information
jondot committed Feb 24, 2020
2 parents 3a3d289 + 3bf896d commit 9fadf93
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions formation/for_requests.py
Expand Up @@ -64,6 +64,7 @@ class FormationHttpRequest(object):
# these two are very stabby. a single default instance is shared among all attrs
# objects. to assign new keys, update immutably -- use merge and re-assign
headers = attrib(default={})
cookies = attrib(default={})
params = attrib(default={})

auth = attrib(default=None)
Expand Down Expand Up @@ -187,6 +188,7 @@ def requests_adapter(ctx):
res = meth(
req.url,
headers=req.headers,
cookies=req.cookies,
params=req.params,
auth=req.auth,
data=req.data,
Expand Down
62 changes: 62 additions & 0 deletions tests/cassettes/test_cookies.yaml
@@ -0,0 +1,62 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Cookie:
- clientSession=session
User-Agent:
- python-requests/2.22.0
x-custom:
- hello
method: GET
uri: http://example.com/?v=1.0
response:
body:
string: !!binary |
H4sIAMIVqF0AA31UTXPbIBC9+1ds1UsyIyQnaRqPLWn6mWkPaQ9pDz0SsbKYCFAByfZ08t+7Qo4j
N5makYFdeLvvsZC9Eqb0uxah9qopZtljh1wUM6Bf5qVvsPi85aptED4ZxaXO0tE6G5co9BzKmluH
Po86X7FFBGkxcdbetwx/d7LPo49Ge9SeDWEjKMdZHnnc+nQIvzpAvYSkucI86iVuWmP9ZP9GCl/n
AntZIguTGKSWXvKGuZI3mJ89QTm/IzJDBvvApXPR6LszYgd/wjBMeXm/tqbTgpWmMXYJr6s5tfPV
YYnidi31EuZPppYLIfX6yFZRpqziSja7JTDekpzM7ZxHFcPYs07G8KGR+v6Gl7fBdE2bYohucW0Q
fn6NaPy9RQ23XLth8gWbHr0sOXzDDslyMMTw3hJ3wqalzKGV1VMuYfAQ/oXsJ3SDcEt4O5+32+cM
L1EB77x5geg5qtV/RRPUJhncGSvQMsuF7BzplFweAZgtczUXZkPI7RYu6Luibxjb9R0/mcehJfPz
09WEDF8O6sXU99JJj2JC7TGTi8WbxWKSyXD+TGBpLPfSEEttNE5B3ykUksOJ4lu21+dq0Od0An6s
4lFV/KPYROVjx8MkZJaGCi3CWWXpeB1n2VCbdDsp2L6O67NnN5NMo68tftTSgQh2oFFlLHQOYZg1
Tef8QLhHwBHBDQ56DjpF98kl8Mt0RGIXtnhCGqtlj6ahIXkJoLNIdHxtOg+tlRSiNHS0Ugcxgebc
3VOFhOgtWiWdI0eSpe0hz4weCItVHg3PhFum6WazSSTXPDF2nY4hXbpPMypujB1IEKAKQZKE0HgR
ELM0iJOle6nS8UH7CyjrfG/oBAAA
headers:
Age:
- '585141'
Cache-Control:
- max-age=604800
Content-Encoding:
- gzip
Content-Length:
- '648'
Content-Type:
- text/html; charset=UTF-8
Date:
- Mon, 24 Feb 2020 11:36:33 GMT
Etag:
- '"3147526947+ident+gzip"'
Expires:
- Mon, 02 Mar 2020 11:36:33 GMT
Last-Modified:
- Thu, 17 Oct 2019 07:18:26 GMT
Server:
- ECS (nyb/1D04)
Vary:
- Accept-Encoding
X-Cache:
- HIT
status:
code: 200
message: OK
version: 1
7 changes: 7 additions & 0 deletions tests/test_for_requests.py
Expand Up @@ -45,3 +45,10 @@ def test_accept():
"get", "http://example.com", headers={"x-custom": "hello"}, params={"v": "1.0"}
)


@pytest.mark.vcr()
def test_cookies():
sender = build_sender(middleware=[])
sender(
"get", "http://example.com", headers={"x-custom": "hello"}, params={"v": "1.0"}, cookies={"clientSession": "session"}
)

0 comments on commit 9fadf93

Please sign in to comment.