Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Aug 9, 2018
1 parent c727d2f commit 7dcb10c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
8 changes: 3 additions & 5 deletions tests/helpers/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,16 @@ def test_get_clientsession_cleanup_without_ssl(self):
@asyncio.coroutine
def test_async_aiohttp_proxy_stream(aioclient_mock, camera_client):
"""Test that it fetches the given url."""
aioclient_mock.get('http://example.com/mjpeg_stream', content=[
b'Frame1', b'Frame2', b'Frame3'
])
aioclient_mock.get('http://example.com/mjpeg_stream',
content=b'Frame1Frame2Frame3')

resp = yield from camera_client.get(
'/api/camera_proxy_stream/camera.config_test')

assert resp.status == 200
assert aioclient_mock.call_count == 1
body = yield from resp.text()
assert body == 'Frame3Frame2Frame1'

assert body == 'Frame1Frame2Frame3'

@asyncio.coroutine
def test_async_aiohttp_proxy_stream_timeout(aioclient_mock, camera_client):
Expand Down
17 changes: 3 additions & 14 deletions tests/test_util/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
retype = type(re.compile(''))


def create_stream(data):
def mock_stream(data):
"""Mock a stream with data."""
protocol = mock.Mock(_reading_paused=False)
stream = StreamReader(protocol)
stream.feed_data(data)
Expand Down Expand Up @@ -139,18 +140,6 @@ def __init__(self, method, url, status, response, cookies=None, exc=None,
cookie.value = data
self._cookies[name] = cookie

if isinstance(response, list):
self.content = mock.MagicMock()

@asyncio.coroutine
def read(*argc, **kwargs):
"""Read content stream mock."""
if self.response:
return self.response.pop()
return None

self.content.read = read

def match_request(self, method, url, params=None):
"""Test if response answers request."""
if method.lower() != self.method.lower():
Expand Down Expand Up @@ -189,7 +178,7 @@ def cookies(self):
@property
def content(self):
"""Return content."""
return create_stream(self.response)
return mock_stream(self.response)

@asyncio.coroutine
def read(self):
Expand Down

0 comments on commit 7dcb10c

Please sign in to comment.