Skip to content

Commit

Permalink
Clean test init
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare committed Feb 16, 2022
1 parent 095ad20 commit bb61411
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -50,13 +49,15 @@ def __init__(self, result, status_code=200, **kwargs):

@property
def text(self):
"""Return text."""
return json.dumps(self.result)


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", "{}"))
Expand Down Expand Up @@ -169,6 +170,7 @@ def __init__(
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
Expand Down

0 comments on commit bb61411

Please sign in to comment.