From a14a57743d4cb966ee158359b5caa61d190a59ab Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Wed, 16 Feb 2022 21:16:10 +0100 Subject: [PATCH] Clean up tests (#374) --- tests/__init__.py | 8 +++++--- tests/test_account.py | 3 ++- tests/test_cmdline.py | 14 ++++++++------ tests/test_drive.py | 13 ++++++++----- tests/test_findmyiphone.py | 4 +++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 32096fe..40317b2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,10 +1,8 @@ """Library tests.""" import json -from requests import Session, Response +from requests import Response from pyicloud import base -from pyicloud.exceptions import PyiCloudFailedLoginException -from pyicloud.services.findmyiphone import FindMyiPhoneServiceManager, AppleDevice from .const import ( AUTHENTICATED_USER, @@ -42,6 +40,7 @@ class ResponseMock(Response): """Mocked Response.""" def __init__(self, result, status_code=200, **kwargs): + """Set up response mock.""" Response.__init__(self) self.result = result self.status_code = status_code @@ -50,6 +49,7 @@ class ResponseMock(Response): @property def text(self): + """Return text.""" return json.dumps(self.result) @@ -57,6 +57,7 @@ class PyiCloudSessionMock(base.PyiCloudSession): """Mocked PyiCloudSession.""" def request(self, method, url, **kwargs): + """Make the request.""" params = kwargs.get("params") headers = kwargs.get("headers") data = json.loads(kwargs.get("data", "{}")) @@ -169,6 +170,7 @@ class PyiCloudServiceMock(base.PyiCloudService): client_id=None, with_family=True, ): + """Set up pyicloud service mock.""" base.PyiCloudSession = PyiCloudSessionMock base.PyiCloudService.__init__( self, apple_id, password, cookie_directory, verify, client_id, with_family diff --git a/tests/test_account.py b/tests/test_account.py index 48b3efc..94c8c77 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -6,11 +6,12 @@ from .const import AUTHENTICATED_USER, VALID_PASSWORD class AccountServiceTest(TestCase): - """Account service tests""" + """Account service tests.""" service = None def setUp(self): + """Set up tests.""" self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD).account def test_repr(self): diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 9f0d556..2a37cac 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -1,15 +1,16 @@ """Cmdline tests.""" -from pyicloud import cmdline -from . import PyiCloudServiceMock -from .const import AUTHENTICATED_USER, REQUIRES_2FA_USER, VALID_PASSWORD, VALID_2FA_CODE -from .const_findmyiphone import FMI_FAMILY_WORKING - import os import pickle -import pytest from unittest import TestCase from unittest.mock import patch +import pytest +from pyicloud import cmdline + +from . import PyiCloudServiceMock +from .const import AUTHENTICATED_USER, REQUIRES_2FA_USER, VALID_2FA_CODE, VALID_PASSWORD +from .const_findmyiphone import FMI_FAMILY_WORKING + class TestCmdline(TestCase): """Cmdline test cases.""" @@ -17,6 +18,7 @@ class TestCmdline(TestCase): main = None def setUp(self): + """Set up tests.""" cmdline.PyiCloudService = PyiCloudServiceMock self.main = cmdline.main diff --git a/tests/test_drive.py b/tests/test_drive.py index 77e6455..9158e5d 100644 --- a/tests/test_drive.py +++ b/tests/test_drive.py @@ -1,16 +1,19 @@ """Drive service tests.""" from unittest import TestCase -from . import PyiCloudServiceMock -from .const import AUTHENTICATED_USER, VALID_PASSWORD + import pytest -# pylint: disable=pointless-statement +from . import PyiCloudServiceMock +from .const import AUTHENTICATED_USER, VALID_PASSWORD + + class DriveServiceTest(TestCase): - """Drive service tests""" + """Drive service tests.""" service = None def setUp(self): + """Set up tests.""" self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD) def test_root(self): @@ -39,7 +42,7 @@ class DriveServiceTest(TestCase): def test_folder_not_exists(self): """Test the /not_exists folder.""" with pytest.raises(KeyError, match="No child named 'not_exists' exists"): - self.service.drive["not_exists"] + self.service.drive["not_exists"] # pylint: disable=pointless-statement def test_folder(self): """Test the /pyiCloud folder.""" diff --git a/tests/test_findmyiphone.py b/tests/test_findmyiphone.py index 10826cb..517bd1e 100644 --- a/tests/test_findmyiphone.py +++ b/tests/test_findmyiphone.py @@ -1,15 +1,17 @@ """Find My iPhone service tests.""" from unittest import TestCase + from . import PyiCloudServiceMock from .const import AUTHENTICATED_USER, VALID_PASSWORD class FindMyiPhoneServiceTest(TestCase): - """Find My iPhone service tests""" + """Find My iPhone service tests.""" service = None def setUp(self): + """Set up tests.""" self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD) def test_devices(self):