Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for logging #846

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/mock_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
class MockResponse:
"""Class for mock request response."""

def __init__(self, json_data, status_code, headers={}, raw_data=None):
def __init__(
self,
json_data,
status_code,
headers={},
raw_data=None,
raise_error=None,
):
"""Initialize mock get response."""
self.json_data = json_data
self.status = status_code
self.raw_data = raw_data
self.reason = "foobar"
self.headers = headers
self.read = mock.AsyncMock(return_value=self.raw_data)
self.raise_error = raise_error
self.text = mock.AsyncMock(return_vlaue="some text")

async def json(self):
"""Return json data from get_request."""
if self.raise_error:
raise self.raise_error("I'm broken", "")
return self.json_data

def get(self, name):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from unittest import mock
from unittest import IsolatedAsyncioTestCase
from aiohttp import ClientConnectionError
from aiohttp import ClientConnectionError, ContentTypeError
from blinkpy.auth import (
Auth,
TokenRefreshFailed,
Expand Down Expand Up @@ -100,6 +100,10 @@ async def test_bad_response_code(self):
with self.assertRaises(UnauthorizedError):
await self.auth.validate_response(fake_resp, True)
self.assertTrue(self.auth.is_errored)
fake_resp = mresp.MockResponse({"code": 101}, 406, raise_error=ContentTypeError)
with self.assertRaises(BlinkBadResponse):
await self.auth.validate_response(fake_resp, True)
self.assertTrue(self.auth.is_errored)

async def test_good_response_code(self):
"""Check good response code from server."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_blink_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ async def test_download_videos_file_exists(self, mock_isfile, mock_req):
]
with self.assertLogs(level="DEBUG") as dl_log:
await self.blink.download_videos("/tmp", camera="foo", stop=2, delay=0)
self.assertListEqual(dl_log.output, expected_log)
assert expected_log[0] in dl_log.output
assert expected_log[1] in dl_log.output
assert expected_log[2] in dl_log.output

@mock.patch("blinkpy.blinkpy.api.request_videos")
async def test_parse_camera_not_in_list(self, mock_req):
Expand Down
Loading