Skip to content

Commit

Permalink
Merge pull request #13 from onna/restore-streams-after-serialize
Browse files Browse the repository at this point in the history
Restore consumed streams
  • Loading branch information
dmanchon authored Jul 11, 2018
2 parents 83bc5cc + 6624bba commit 670dabd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

1.1.7
-----

- When consuming the response content and serializing the returned response was at EOF.
Refill the buffer so it can be consumed again.

1.1.6
-----

Expand Down
12 changes: 10 additions & 2 deletions cassettedeck/deck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import aiohttp
import functools
import asyncio
import logging
from contextlib import contextmanager
from cassettedeck.store import CassetteStore
Expand Down Expand Up @@ -54,8 +55,15 @@ async def handle_request(self, method: str, url: str, params=None, data=None,
headers=headers, *args,
**kwargs)
# Store cassette
await _cassette_store.store_response(method, url, params, data,
headers, resp)
stored = await _cassette_store.store_response(method, url, params, data,
headers, resp)

# Refill the buffer
if resp.content.is_eof():
content = asyncio.StreamReader()
content.feed_data(stored['body']['data'])
content.feed_eof()
resp.content = content
logging.info(f"Recording [{method}] {url}")
else:
logging.info(f"Loading from cassette [{method}] {url}")
Expand Down
2 changes: 2 additions & 0 deletions cassettedeck/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ async def store_response(self, method, url, params0, data0, headers0,
cassette.append(request, vcr_response)
cassette._save(force=True)

return vcr_response

def build_response(self, method, url, params, data, headers):
""""""
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='cassettedeck',
version='1.1.6',
version='1.1.7',
description='A library store and replay aiohttp requests',
long_description='To simplify and speed up tests that make HTTP requests',
author='Developer team at Onna Technologies',
Expand Down

0 comments on commit 670dabd

Please sign in to comment.