Clean up tests (#374)

This commit is contained in:
Martin Hjelmare 2022-02-16 21:16:10 +01:00 committed by GitHub
parent c0e4ecfed2
commit a14a57743d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 16 deletions

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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."""

View file

@ -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):