Clean up tests (#374)
This commit is contained in:
parent
c0e4ecfed2
commit
a14a57743d
5 changed files with 26 additions and 16 deletions
|
@ -1,10 +1,8 @@
|
||||||
"""Library tests."""
|
"""Library tests."""
|
||||||
import json
|
import json
|
||||||
from requests import Session, Response
|
from requests import Response
|
||||||
|
|
||||||
from pyicloud import base
|
from pyicloud import base
|
||||||
from pyicloud.exceptions import PyiCloudFailedLoginException
|
|
||||||
from pyicloud.services.findmyiphone import FindMyiPhoneServiceManager, AppleDevice
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
AUTHENTICATED_USER,
|
AUTHENTICATED_USER,
|
||||||
|
@ -42,6 +40,7 @@ class ResponseMock(Response):
|
||||||
"""Mocked Response."""
|
"""Mocked Response."""
|
||||||
|
|
||||||
def __init__(self, result, status_code=200, **kwargs):
|
def __init__(self, result, status_code=200, **kwargs):
|
||||||
|
"""Set up response mock."""
|
||||||
Response.__init__(self)
|
Response.__init__(self)
|
||||||
self.result = result
|
self.result = result
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
|
@ -50,6 +49,7 @@ class ResponseMock(Response):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
|
"""Return text."""
|
||||||
return json.dumps(self.result)
|
return json.dumps(self.result)
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ class PyiCloudSessionMock(base.PyiCloudSession):
|
||||||
"""Mocked PyiCloudSession."""
|
"""Mocked PyiCloudSession."""
|
||||||
|
|
||||||
def request(self, method, url, **kwargs):
|
def request(self, method, url, **kwargs):
|
||||||
|
"""Make the request."""
|
||||||
params = kwargs.get("params")
|
params = kwargs.get("params")
|
||||||
headers = kwargs.get("headers")
|
headers = kwargs.get("headers")
|
||||||
data = json.loads(kwargs.get("data", "{}"))
|
data = json.loads(kwargs.get("data", "{}"))
|
||||||
|
@ -169,6 +170,7 @@ class PyiCloudServiceMock(base.PyiCloudService):
|
||||||
client_id=None,
|
client_id=None,
|
||||||
with_family=True,
|
with_family=True,
|
||||||
):
|
):
|
||||||
|
"""Set up pyicloud service mock."""
|
||||||
base.PyiCloudSession = PyiCloudSessionMock
|
base.PyiCloudSession = PyiCloudSessionMock
|
||||||
base.PyiCloudService.__init__(
|
base.PyiCloudService.__init__(
|
||||||
self, apple_id, password, cookie_directory, verify, client_id, with_family
|
self, apple_id, password, cookie_directory, verify, client_id, with_family
|
||||||
|
|
|
@ -6,11 +6,12 @@ from .const import AUTHENTICATED_USER, VALID_PASSWORD
|
||||||
|
|
||||||
|
|
||||||
class AccountServiceTest(TestCase):
|
class AccountServiceTest(TestCase):
|
||||||
"""Account service tests"""
|
"""Account service tests."""
|
||||||
|
|
||||||
service = None
|
service = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
"""Set up tests."""
|
||||||
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD).account
|
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD).account
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
"""Cmdline tests."""
|
"""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 os
|
||||||
import pickle
|
import pickle
|
||||||
import pytest
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import patch
|
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):
|
class TestCmdline(TestCase):
|
||||||
"""Cmdline test cases."""
|
"""Cmdline test cases."""
|
||||||
|
@ -17,6 +18,7 @@ class TestCmdline(TestCase):
|
||||||
main = None
|
main = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
"""Set up tests."""
|
||||||
cmdline.PyiCloudService = PyiCloudServiceMock
|
cmdline.PyiCloudService = PyiCloudServiceMock
|
||||||
self.main = cmdline.main
|
self.main = cmdline.main
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
"""Drive service tests."""
|
"""Drive service tests."""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from . import PyiCloudServiceMock
|
|
||||||
from .const import AUTHENTICATED_USER, VALID_PASSWORD
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# pylint: disable=pointless-statement
|
from . import PyiCloudServiceMock
|
||||||
|
from .const import AUTHENTICATED_USER, VALID_PASSWORD
|
||||||
|
|
||||||
|
|
||||||
class DriveServiceTest(TestCase):
|
class DriveServiceTest(TestCase):
|
||||||
"""Drive service tests"""
|
"""Drive service tests."""
|
||||||
|
|
||||||
service = None
|
service = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
"""Set up tests."""
|
||||||
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD)
|
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD)
|
||||||
|
|
||||||
def test_root(self):
|
def test_root(self):
|
||||||
|
@ -39,7 +42,7 @@ class DriveServiceTest(TestCase):
|
||||||
def test_folder_not_exists(self):
|
def test_folder_not_exists(self):
|
||||||
"""Test the /not_exists folder."""
|
"""Test the /not_exists folder."""
|
||||||
with pytest.raises(KeyError, match="No child named 'not_exists' exists"):
|
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):
|
def test_folder(self):
|
||||||
"""Test the /pyiCloud folder."""
|
"""Test the /pyiCloud folder."""
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
"""Find My iPhone service tests."""
|
"""Find My iPhone service tests."""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from . import PyiCloudServiceMock
|
from . import PyiCloudServiceMock
|
||||||
from .const import AUTHENTICATED_USER, VALID_PASSWORD
|
from .const import AUTHENTICATED_USER, VALID_PASSWORD
|
||||||
|
|
||||||
|
|
||||||
class FindMyiPhoneServiceTest(TestCase):
|
class FindMyiPhoneServiceTest(TestCase):
|
||||||
"""Find My iPhone service tests"""
|
"""Find My iPhone service tests."""
|
||||||
|
|
||||||
service = None
|
service = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
"""Set up tests."""
|
||||||
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD)
|
self.service = PyiCloudServiceMock(AUTHENTICATED_USER, VALID_PASSWORD)
|
||||||
|
|
||||||
def test_devices(self):
|
def test_devices(self):
|
||||||
|
|
Loading…
Reference in a new issue