From 42e65ee4bbbfa6ca4e31cab904ef01e498404ffe Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:22:47 -0500 Subject: [PATCH 01/37] Update sonarr.py --- sonarr/sonarr.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index b25aef4d..c03af7e9 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -155,6 +155,18 @@ async def calendar(self, start: int = None, end: int = None) -> List[Episode]: return [Episode.from_dict(result) for result in results] + async def command(self, id: int) -> CommandItem: + """Query the status of a previously started command.""" + result = await self._request(f"command/{id}") + + return CommandItem.from_dict(result) + + async def commands(self) -> List[CommandItem]: + """Query the status of all currently started commands.""" + results = await self._request("command") + + return [CommandItem.from_dict(result) for result in results] + async def queue(self) -> List[QueueItem]: """Get currently downloading info.""" results = await self._request("queue") From 00afca2318f99aeffc2f08d28ebd01d29c2ab8bc Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:25:43 -0500 Subject: [PATCH 02/37] Update test_interface.py --- tests/test_interface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index ba6bbde0..af468459 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -190,13 +190,14 @@ async def test_wanted(aresponses): """Test queue is handled correctly.""" aresponses.add( MATCH_HOST, - "/api/wanted/missing", + "/api/wanted/missing?sortKey=airDateUtc&page=1&pageSize=10&sortDir=desc", "GET", aresponses.Response( status=200, headers={"Content-Type": "application/json"}, text=load_fixture("wanted-missing.json"), ), + match_querystring=True, ) async with ClientSession() as session: From c99ea201dc6ce674ce39cddd3b4ed5e95b6704ad Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:30:50 -0500 Subject: [PATCH 03/37] Update test_interface.py --- tests/test_interface.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index af468459..804c7e3b 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -50,7 +50,7 @@ async def test_app(aresponses): @pytest.mark.asyncio async def test_calendar(aresponses): - """Test calendar is handled correctly.""" + """Test calendar method is handled correctly.""" aresponses.add( MATCH_HOST, "/api/calendar?start=2014-01-26&end=2014-01-27", @@ -74,9 +74,34 @@ async def test_calendar(aresponses): assert isinstance(response[0], models.Episode) +@pytest.mark.asyncio +async def test_commands(aresponses): + """Test commands method is handled correctly.""" + aresponses.add( + MATCH_HOST, + "/api/commands", + "GET", + aresponses.Response( + status=200, + headers={"Content-Type": "application/json"}, + text=load_fixture("commands.json"), + ), + ) + + async with ClientSession() as session: + client = Sonarr(HOST, API_KEY, session=session) + response = await client.commands() + + assert response + assert isinstance(response, List) + + assert response[0] + assert isinstance(response[0], models.CommandItem) + + @pytest.mark.asyncio async def test_queue(aresponses): - """Test queue is handled correctly.""" + """Test queue method is handled correctly.""" aresponses.add( MATCH_HOST, "/api/queue", @@ -103,7 +128,7 @@ async def test_queue(aresponses): @pytest.mark.asyncio async def test_series(aresponses): - """Test series is handled correctly.""" + """Test series method is handled correctly.""" aresponses.add( MATCH_HOST, "/api/series", @@ -136,7 +161,7 @@ async def test_series(aresponses): @pytest.mark.asyncio async def test_update(aresponses): - """Test update is handled correctly.""" + """Test update method is handled correctly.""" aresponses.add( MATCH_HOST, "/api/system/status", @@ -187,7 +212,7 @@ async def test_update(aresponses): @pytest.mark.asyncio async def test_wanted(aresponses): - """Test queue is handled correctly.""" + """Test queue method is handled correctly.""" aresponses.add( MATCH_HOST, "/api/wanted/missing?sortKey=airDateUtc&page=1&pageSize=10&sortDir=desc", From 3e341c51b8d81521d23c2c18707c1e119fe785f3 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:38:24 -0500 Subject: [PATCH 04/37] Update sonarr.py --- sonarr/sonarr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index c03af7e9..0bf1dd1c 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -10,7 +10,7 @@ from .__version__ import __version__ from .exceptions import SonarrAccessRestricted, SonarrConnectionError, SonarrError -from .models import Application, Episode, QueueItem, SeriesItem, WantedResults +from .models import Application, CommandItem, Episode, QueueItem, SeriesItem, WantedResults class Sonarr: From 48f5b7446543c00cfe1d23369c8a486c17b27dbb Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:52:07 -0500 Subject: [PATCH 05/37] Update models.py --- sonarr/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sonarr/models.py b/sonarr/models.py index 30d5bb4d..751b7d82 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -183,6 +183,38 @@ def from_dict(data: dict): return Info(app_name="Sonarr", version=data.get("version", "Unknown")) +@dataclass(frozen=True) +class CommandItem: + """Object holding command item information from Sonarr.""" + + command_id: int + name: int + state: str + started: datetime + changed: datetime + send_to_client: bool + + @staticmethod + def from_dict(data: dict): + """Return CommandItem object from Sonarr API response.""" + started = data.get("startedOn", None) + if started is not None: + started = datetime.strptime(stated, "%Y-%m-%dT%H:%M:%S%z") + + changed = data.get("stateChangeTime", None) + if changed is not None: + changed = datetime.strptime(changed, "%Y-%m-%dT%H:%M:%S.%f%z") + + return CommandItem( + command_id=data.get("id", 0), + name=data.get("name", ""), + state=data.get("state", "unknown"), + send_to_client=data.get("sendUpdatesToClient", False), + started=started, + changed=updated, + ) + + @dataclass(frozen=True) class QueueItem: """Object holding queue item information from Sonarr.""" From dd9ffa8b891fcb61d74478f04e6af756979a11d7 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 11:56:00 -0500 Subject: [PATCH 06/37] Create command.json --- tests/fixtures/command.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/fixtures/command.json diff --git a/tests/fixtures/command.json b/tests/fixtures/command.json new file mode 100644 index 00000000..b4525b6e --- /dev/null +++ b/tests/fixtures/command.json @@ -0,0 +1,28 @@ +[ + { + "name": "RefreshSeries", + "body": { + "isNewSeries": false, + "sendUpdatesToClient": true, + "updateScheduledTask": true, + "completionMessage": "Completed", + "requiresDiskAccess": false, + "isExclusive": false, + "name": "RefreshSeries", + "trigger": "manual", + "suppressMessages": false + }, + "priority": "normal", + "status": "started", + "queued": "2020-04-06T16:54:06.41945Z", + "started": "2020-04-06T16:54:06.421322Z", + "trigger": "manual", + "state": "started", + "manual": true, + "startedOn": "2020-04-06T16:54:06.41945Z", + "stateChangeTime": "2020-04-06T16:54:06.421322Z", + "sendUpdatesToClient": true, + "updateScheduledTask": true, + "id": 368621 + } +] From a4b8cbdb65e76478247d157409c4906a3973690b Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:00:33 -0500 Subject: [PATCH 07/37] Create command-id.json --- tests/fixtures/command-id.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/fixtures/command-id.json diff --git a/tests/fixtures/command-id.json b/tests/fixtures/command-id.json new file mode 100644 index 00000000..1071513e --- /dev/null +++ b/tests/fixtures/command-id.json @@ -0,0 +1,27 @@ +{ + "name": "RefreshSeries", + "message": "Updating The Andy Griffith Show", + "body": { + "isNewSeries": false, + "sendUpdatesToClient": true, + "updateScheduledTask": true, + "completionMessage": "Completed", + "requiresDiskAccess": false, + "isExclusive": false, + "name": "RefreshSeries", + "trigger": "manual", + "suppressMessages": false + }, + "priority": "normal", + "status": "started", + "queued": "2020-04-06T16:57:51.406504Z", + "started": "2020-04-06T16:57:51.417931Z", + "trigger": "manual", + "state": "started", + "manual": true, + "startedOn": "2020-04-06T16:57:51.406504Z", + "stateChangeTime": "2020-04-06T16:57:51.417931Z", + "sendUpdatesToClient": true, + "updateScheduledTask": true, + "id": 368630 +} From ae502fdc6b45fcb2d8354908ec9c3462df834c24 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:04:59 -0500 Subject: [PATCH 08/37] Update sonarr.py --- sonarr/sonarr.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index 0bf1dd1c..adb4165f 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -155,18 +155,18 @@ async def calendar(self, start: int = None, end: int = None) -> List[Episode]: return [Episode.from_dict(result) for result in results] - async def command(self, id: int) -> CommandItem: - """Query the status of a previously started command.""" - result = await self._request(f"command/{id}") - - return CommandItem.from_dict(result) - async def commands(self) -> List[CommandItem]: """Query the status of all currently started commands.""" results = await self._request("command") return [CommandItem.from_dict(result) for result in results] + async def command_status(self, id: int) -> CommandItem: + """Query the status of a previously started command.""" + result = await self._request(f"command/{id}") + + return CommandItem.from_dict(result) + async def queue(self) -> List[QueueItem]: """Get currently downloading info.""" results = await self._request("queue") From 83421c7b4e40638cdc7766dea9ee92d62e01b842 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:10:15 -0500 Subject: [PATCH 09/37] Update models.py --- sonarr/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sonarr/models.py b/sonarr/models.py index 751b7d82..407ede2a 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -190,6 +190,9 @@ class CommandItem: command_id: int name: int state: str + priority: Optional[str] = "unknown" + trigger: Optional[str] = "unknown" + message: Optional[str] = "" started: datetime changed: datetime send_to_client: bool @@ -209,6 +212,9 @@ def from_dict(data: dict): command_id=data.get("id", 0), name=data.get("name", ""), state=data.get("state", "unknown"), + priority=data.get("prioirty", "unknown"), + trigger=data.get("trigger", "unknown"), + message=data.get("message", ""), send_to_client=data.get("sendUpdatesToClient", False), started=started, changed=updated, From 083e23c4fea6fb6227b36b8d504b2e4868d83676 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:20:52 -0500 Subject: [PATCH 10/37] Update models.py --- sonarr/models.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sonarr/models.py b/sonarr/models.py index 407ede2a..467a78f2 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -192,30 +192,44 @@ class CommandItem: state: str priority: Optional[str] = "unknown" trigger: Optional[str] = "unknown" - message: Optional[str] = "" + message: Optional[str] = "Not Provided" + queued: datetime started: datetime changed: datetime - send_to_client: bool + send_to_client: Optional[bool] = False @staticmethod def from_dict(data: dict): """Return CommandItem object from Sonarr API response.""" - started = data.get("startedOn", None) + if "started" in data: + started = data.get("started", None) + else: + started = data.get("startedOn", None) + + if "queued" in data: + queued = data.get("queued", None) + else: + queued = started + if started is not None: started = datetime.strptime(stated, "%Y-%m-%dT%H:%M:%S%z") + if queued is not None: + queued = datetime.strptime(queued, "%Y-%m-%dT%H:%M:%S%z") + changed = data.get("stateChangeTime", None) if changed is not None: changed = datetime.strptime(changed, "%Y-%m-%dT%H:%M:%S.%f%z") return CommandItem( command_id=data.get("id", 0), - name=data.get("name", ""), + name=data.get("name", "Unknown"), state=data.get("state", "unknown"), priority=data.get("prioirty", "unknown"), trigger=data.get("trigger", "unknown"), - message=data.get("message", ""), + message=data.get("message", "Not Provided"), send_to_client=data.get("sendUpdatesToClient", False), + queued=queued, started=started, changed=updated, ) From 6a1800ff40f451f36e379ae5f972f95154631aa5 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:29:19 -0500 Subject: [PATCH 11/37] Update models.py --- sonarr/models.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sonarr/models.py b/sonarr/models.py index 467a78f2..c4ed8996 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -33,11 +33,11 @@ class Season: number: int monitored: bool - downloaded: Optional[int] = 0 - episodes: Optional[int] = 0 - total_episodes: Optional[int] = 0 - progress: Optional[int] = 0 - diskspace: Optional[int] = 0 + downloaded: int = 0 + episodes: int = 0 + total_episodes: int = 0 + progress: int = 0 + diskspace: int = 0 @staticmethod def from_dict(data: dict): @@ -190,13 +190,13 @@ class CommandItem: command_id: int name: int state: str - priority: Optional[str] = "unknown" - trigger: Optional[str] = "unknown" - message: Optional[str] = "Not Provided" + priority: str = "unknown" + trigger: str = "unknown" + message: str = "Not Provided" queued: datetime started: datetime changed: datetime - send_to_client: Optional[bool] = False + send_to_client: bool = False @staticmethod def from_dict(data: dict): From 798c4ed8db994292e85881c8f869c0ba2a51d1d2 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:31:21 -0500 Subject: [PATCH 12/37] Update models.py --- sonarr/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonarr/models.py b/sonarr/models.py index c4ed8996..f5af7011 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -2,7 +2,7 @@ from dataclasses import dataclass from datetime import datetime -from typing import List, Optional +from typing import List from .exceptions import SonarrError From 00305d2c2060d28a745bbd7a9015bcb7f08ba596 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:37:44 -0500 Subject: [PATCH 13/37] Update models.py --- sonarr/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sonarr/models.py b/sonarr/models.py index f5af7011..5037ac0e 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -190,12 +190,12 @@ class CommandItem: command_id: int name: int state: str - priority: str = "unknown" - trigger: str = "unknown" - message: str = "Not Provided" queued: datetime started: datetime changed: datetime + priority: str = "unknown" + trigger: str = "unknown" + message: str = "Not Provided" send_to_client: bool = False @staticmethod @@ -212,7 +212,7 @@ def from_dict(data: dict): queued = started if started is not None: - started = datetime.strptime(stated, "%Y-%m-%dT%H:%M:%S%z") + started = datetime.strptime(started, "%Y-%m-%dT%H:%M:%S%z") if queued is not None: queued = datetime.strptime(queued, "%Y-%m-%dT%H:%M:%S%z") @@ -231,7 +231,7 @@ def from_dict(data: dict): send_to_client=data.get("sendUpdatesToClient", False), queued=queued, started=started, - changed=updated, + changed=changed, ) From 05a14aff4c0a2f67c8df79c6fe82844d946236f8 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:42:23 -0500 Subject: [PATCH 14/37] Update sonarr.py --- sonarr/sonarr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index adb4165f..e41f43f1 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -161,9 +161,9 @@ async def commands(self) -> List[CommandItem]: return [CommandItem.from_dict(result) for result in results] - async def command_status(self, id: int) -> CommandItem: + async def command_status(self, command_id: int) -> CommandItem: """Query the status of a previously started command.""" - result = await self._request(f"command/{id}") + result = await self._request(f"command/{command_id}") return CommandItem.from_dict(result) From 84b5ecadcf9a076d6e08a2dcfaaee23baaad0800 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:44:44 -0500 Subject: [PATCH 15/37] Update test_interface.py --- tests/test_interface.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index 804c7e3b..75c8c8fb 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -79,12 +79,12 @@ async def test_commands(aresponses): """Test commands method is handled correctly.""" aresponses.add( MATCH_HOST, - "/api/commands", + "/api/command", "GET", aresponses.Response( status=200, headers={"Content-Type": "application/json"}, - text=load_fixture("commands.json"), + text=load_fixture("command.json"), ), ) @@ -99,6 +99,28 @@ async def test_commands(aresponses): assert isinstance(response[0], models.CommandItem) +@pytest.mark.asyncio +async def test_command_status(aresponses): + """Test command_status method is handled correctly.""" + aresponses.add( + MATCH_HOST, + "/api/command/368690", + "GET", + aresponses.Response( + status=200, + headers={"Content-Type": "application/json"}, + text=load_fixture("command-id.json"), + ), + ) + + async with ClientSession() as session: + client = Sonarr(HOST, API_KEY, session=session) + response = await client.command_status(368630) + + assert response + assert isinstance(response, models.CommandItem) + + @pytest.mark.asyncio async def test_queue(aresponses): """Test queue method is handled correctly.""" From 12a094a9a153d1bb4728f66ce02be8436110e596 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:49:09 -0500 Subject: [PATCH 16/37] Update test_models.py --- tests/test_models.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 7f507992..61e8534e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -11,6 +11,7 @@ INFO = json.loads(load_fixture("system-status.json")) CALENDAR = json.loads(load_fixture("calendar.json")) +COMMAND=json.loads(load_fixture("command.json")) DISKSPACE = json.loads(load_fixture("diskspace.json")) QUEUE = json.loads(load_fixture("queue.json")) SERIES = json.loads(load_fixture("series.json")) @@ -38,7 +39,6 @@ def test_application_no_data() -> None: with pytest.raises(SonarrError): models.Application({}) - def test_info() -> None: """Test the Info model.""" info = models.Info.from_dict(INFO) @@ -48,6 +48,21 @@ def test_info() -> None: assert info.version == "2.0.0.1121" +def test_command_item() -> None: + """Test the Info model.""" + iten = models.CommandItem.from_dict(COMMAND[0]) + + assert item + assert item.name == "" + assert item.message == "" + assert item.state == "" + assert item.priority == "" + assert item.trigger == "" + assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.queued == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + + def test_episode() -> None: """Test the Episode model.""" episode = models.Episode.from_dict(CALENDAR[0]) From 3c19733218f0d7f5f3922b770e974b296cc76a2d Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:51:49 -0500 Subject: [PATCH 17/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 61e8534e..ce97e4a3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -50,7 +50,7 @@ def test_info() -> None: def test_command_item() -> None: """Test the Info model.""" - iten = models.CommandItem.from_dict(COMMAND[0]) + item = models.CommandItem.from_dict(COMMAND[0]) assert item assert item.name == "" From 9a36add5a7d1a08fd2bf5adad464e9aaf512e107 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:52:30 -0500 Subject: [PATCH 18/37] Update models.py --- sonarr/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonarr/models.py b/sonarr/models.py index 5037ac0e..d5021ba5 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -210,7 +210,7 @@ def from_dict(data: dict): queued = data.get("queued", None) else: queued = started - + if started is not None: started = datetime.strptime(started, "%Y-%m-%dT%H:%M:%S%z") From 4272a230f2424037bfcc9c405f500703a8c4fa7f Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:53:27 -0500 Subject: [PATCH 19/37] Update sonarr.py --- sonarr/sonarr.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index e41f43f1..4215ee82 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -10,8 +10,14 @@ from .__version__ import __version__ from .exceptions import SonarrAccessRestricted, SonarrConnectionError, SonarrError -from .models import Application, CommandItem, Episode, QueueItem, SeriesItem, WantedResults - +from .models import ( + Application, + CommandItem, + Episode, + QueueItem, + SeriesItem, + WantedResults, +) class Sonarr: """Main class for handling connections with Sonarr API.""" From 556d3caecbadc163a38090d88c93b6e91c4a2fcf Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:53:58 -0500 Subject: [PATCH 20/37] Update test_models.py --- tests/test_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_models.py b/tests/test_models.py index ce97e4a3..d68e8375 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -39,6 +39,7 @@ def test_application_no_data() -> None: with pytest.raises(SonarrError): models.Application({}) + def test_info() -> None: """Test the Info model.""" info = models.Info.from_dict(INFO) From 610503f41e536a8cf4ccacc6e734ef18ee750573 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:57:24 -0500 Subject: [PATCH 21/37] Update sonarr.py --- sonarr/sonarr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sonarr/sonarr.py b/sonarr/sonarr.py index 4215ee82..b42b0026 100644 --- a/sonarr/sonarr.py +++ b/sonarr/sonarr.py @@ -19,6 +19,7 @@ WantedResults, ) + class Sonarr: """Main class for handling connections with Sonarr API.""" From 291261c253281d1673e704428a096ee7dac57a4e Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 12:57:49 -0500 Subject: [PATCH 22/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index d68e8375..bdf114a1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -11,7 +11,7 @@ INFO = json.loads(load_fixture("system-status.json")) CALENDAR = json.loads(load_fixture("calendar.json")) -COMMAND=json.loads(load_fixture("command.json")) +COMMAND = json.loads(load_fixture("command.json")) DISKSPACE = json.loads(load_fixture("diskspace.json")) QUEUE = json.loads(load_fixture("queue.json")) SERIES = json.loads(load_fixture("series.json")) From 1e6e3d79bea78284cb4e9fecc00f4b3f249b1aff Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 13:23:12 -0500 Subject: [PATCH 23/37] Update test_interface.py --- tests/test_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index 75c8c8fb..2d45280b 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -104,7 +104,7 @@ async def test_command_status(aresponses): """Test command_status method is handled correctly.""" aresponses.add( MATCH_HOST, - "/api/command/368690", + "/api/command/368630", "GET", aresponses.Response( status=200, From 12d8165ea598e2a272c36975c8cbb9dc4f68b7d6 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 13:33:19 -0500 Subject: [PATCH 24/37] Update models.py --- sonarr/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonarr/models.py b/sonarr/models.py index d5021ba5..e4c6042a 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -212,10 +212,10 @@ def from_dict(data: dict): queued = started if started is not None: - started = datetime.strptime(started, "%Y-%m-%dT%H:%M:%S%z") + started = datetime.strptime(started, "%Y-%m-%dT%H:%M:%S.%f%z") if queued is not None: - queued = datetime.strptime(queued, "%Y-%m-%dT%H:%M:%S%z") + queued = datetime.strptime(queued, "%Y-%m-%dT%H:%M:%S.%f%z") changed = data.get("stateChangeTime", None) if changed is not None: From b71422e02ac5df0228adc9481e63b1688a6815e5 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 13:36:58 -0500 Subject: [PATCH 25/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index bdf114a1..440182bf 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -54,7 +54,7 @@ def test_command_item() -> None: item = models.CommandItem.from_dict(COMMAND[0]) assert item - assert item.name == "" + assert item.name == "RefreshSeries" assert item.message == "" assert item.state == "" assert item.priority == "" From 473cb1ba308153acc693e66c604c8aeee500eb3d Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 13:40:13 -0500 Subject: [PATCH 26/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 440182bf..a9eb931e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -55,7 +55,7 @@ def test_command_item() -> None: assert item assert item.name == "RefreshSeries" - assert item.message == "" + assert item.message == "Not Provided" assert item.state == "" assert item.priority == "" assert item.trigger == "" From 5c11d704373abf2bb7e556fa312d4afaaeb70240 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 13:43:41 -0500 Subject: [PATCH 27/37] Update test_models.py --- tests/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index a9eb931e..56bd53ad 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -50,13 +50,13 @@ def test_info() -> None: def test_command_item() -> None: - """Test the Info model.""" + """Test the CommandItem model.""" item = models.CommandItem.from_dict(COMMAND[0]) assert item assert item.name == "RefreshSeries" assert item.message == "Not Provided" - assert item.state == "" + assert item.state == "started" assert item.priority == "" assert item.trigger == "" assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) From f8b882e18d75d09c97433ec3a4f97e0b8b376b36 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 14:42:18 -0500 Subject: [PATCH 28/37] Update test_models.py --- tests/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 56bd53ad..adb058a8 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -57,8 +57,8 @@ def test_command_item() -> None: assert item.name == "RefreshSeries" assert item.message == "Not Provided" assert item.state == "started" - assert item.priority == "" - assert item.trigger == "" + assert item.priority == "unknown" + assert item.trigger == "unknown" assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) assert item.queued == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) From 52ad8798e6af76a41427751fefc8e31f88522c2a Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:02:55 -0500 Subject: [PATCH 29/37] Update test_models.py --- tests/test_models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index adb058a8..4409e4f6 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -53,6 +53,18 @@ def test_command_item() -> None: """Test the CommandItem model.""" item = models.CommandItem.from_dict(COMMAND[0]) + assert item + assert item.name == "RefreshSeries" + assert item.message == "Not Provided" + assert item.state == "started" + assert item.priority == "normal" + assert item.trigger == "manual" + assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.queued == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + + item = models.CommandItem.from_dict(COMMAND[1]) + assert item assert item.name == "RefreshSeries" assert item.message == "Not Provided" From 243d1581f974da1a6a98d5eedee84c4b1b6784ee Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:06:26 -0500 Subject: [PATCH 30/37] Update command.json --- tests/fixtures/command.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/fixtures/command.json b/tests/fixtures/command.json index b4525b6e..6ccc3cbd 100644 --- a/tests/fixtures/command.json +++ b/tests/fixtures/command.json @@ -24,5 +24,13 @@ "sendUpdatesToClient": true, "updateScheduledTask": true, "id": 368621 + }, + { + "name": "RefreshSeries", + "state": "started", + "startedOn": "2020-04-06T16:57:51.406504Z", + "stateChangeTime": "2020-04-06T16:57:51.417931Z", + "sendUpdatesToClient": true, + "id": 368630 } ] From 1c374cb7bdf61c36e604cad61ff45373499684b5 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:06:46 -0500 Subject: [PATCH 31/37] Update command.json --- tests/fixtures/command.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/command.json b/tests/fixtures/command.json index 6ccc3cbd..97acc2f9 100644 --- a/tests/fixtures/command.json +++ b/tests/fixtures/command.json @@ -31,6 +31,6 @@ "startedOn": "2020-04-06T16:57:51.406504Z", "stateChangeTime": "2020-04-06T16:57:51.417931Z", "sendUpdatesToClient": true, - "id": 368630 + "id": 368629 } ] From 14da1df00fc6c4c50eca77b10e45dd55335c57c0 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:11:28 -0500 Subject: [PATCH 32/37] Update models.py --- sonarr/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonarr/models.py b/sonarr/models.py index e4c6042a..5a7a3a47 100644 --- a/sonarr/models.py +++ b/sonarr/models.py @@ -225,7 +225,7 @@ def from_dict(data: dict): command_id=data.get("id", 0), name=data.get("name", "Unknown"), state=data.get("state", "unknown"), - priority=data.get("prioirty", "unknown"), + priority=data.get("priority", "unknown"), trigger=data.get("trigger", "unknown"), message=data.get("message", "Not Provided"), send_to_client=data.get("sendUpdatesToClient", False), From 36f586fa6d28c025ef7fcc6b812034a200e92163 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:31:37 -0500 Subject: [PATCH 33/37] Update test_models.py --- tests/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 4409e4f6..83bd7951 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -59,8 +59,8 @@ def test_command_item() -> None: assert item.state == "started" assert item.priority == "normal" assert item.trigger == "manual" - assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) - assert item.queued == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.started == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) + assert item.queued == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) item = models.CommandItem.from_dict(COMMAND[1]) From bf5f32274dd9410605dd639eb49bfb12cd79052e Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:34:21 -0500 Subject: [PATCH 34/37] Update test_models.py --- tests/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 83bd7951..97132d79 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -60,8 +60,8 @@ def test_command_item() -> None: assert item.priority == "normal" assert item.trigger == "manual" assert item.started == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) - assert item.queued == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) - assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.queued == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) + assert item.changed == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) item = models.CommandItem.from_dict(COMMAND[1]) From aea9f21cea8a995eabb791b0f6681a91a8dc6c3c Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:40:13 -0500 Subject: [PATCH 35/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 97132d79..30af05aa 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -60,7 +60,7 @@ def test_command_item() -> None: assert item.priority == "normal" assert item.trigger == "manual" assert item.started == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) - assert item.queued == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) + assert item.queued == datetime(2020, 4, 6, 16, 54, 6, 419450, tzinfo=timezone.utc) assert item.changed == datetime(2020, 4, 6, 16, 54, 6, 421322, tzinfo=timezone.utc) item = models.CommandItem.from_dict(COMMAND[1]) From 1a2e91232dbc22571ac35d73a59b2bd4eba9de40 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 15:46:32 -0500 Subject: [PATCH 36/37] Update test_models.py --- tests/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 30af05aa..ac91392b 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -71,8 +71,8 @@ def test_command_item() -> None: assert item.state == "started" assert item.priority == "unknown" assert item.trigger == "unknown" - assert item.started == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) - assert item.queued == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.started == datetime(2020, 4, 6, 16, 57, 51, 406504, tzinfo=timezone.utc) + assert item.queued == datetime(2020, 4, 6, 16, 57, 51, 406504, tzinfo=timezone.utc) assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) From 3362aecd3de4023920f59f07b4408786bfbe00f1 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 6 Apr 2020 16:17:57 -0500 Subject: [PATCH 37/37] Update test_models.py --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index ac91392b..4682ca2c 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -73,7 +73,7 @@ def test_command_item() -> None: assert item.trigger == "unknown" assert item.started == datetime(2020, 4, 6, 16, 57, 51, 406504, tzinfo=timezone.utc) assert item.queued == datetime(2020, 4, 6, 16, 57, 51, 406504, tzinfo=timezone.utc) - assert item.changed == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc) + assert item.changed == datetime(2020, 4, 6, 16, 57, 51, 417931, tzinfo=timezone.utc) def test_episode() -> None: