Skip to content

Commit 2796541

Browse files
authored
Merge pull request #148 from marksie1988/146-multiple-test-failures-since-adding-500-exception
fix: multiple test failures since adding 500 exception
2 parents bfa1f36 + bc699b4 commit 2796541

12 files changed

+223
-116
lines changed

pyarr/base.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ def get_history(
232232
Returns:
233233
JsonObject: Dictionary with items
234234
"""
235-
params: dict[str, Union[int, PyarrHistorySortKey, PyarrSortDirection]] = {}
235+
params: dict[
236+
str,
237+
Union[
238+
int,
239+
PyarrHistorySortKey,
240+
PyarrSortDirection,
241+
],
242+
] = {}
236243

237244
if page:
238245
params["page"] = page
@@ -392,6 +399,14 @@ def upd_quality_definition(self, id_: int, data: JsonObject) -> JsonObject:
392399
"""
393400
return self._put(f"qualitydefinition/{id_}", self.ver_uri, data=data)
394401

402+
def get_quality_profile_schema(self) -> JsonArray:
403+
"""Get the schemas for quality profiles
404+
405+
Returns:
406+
JsonArray: List of dictionaries with items
407+
"""
408+
return self._get("qualityprofile/schema", self.ver_uri)
409+
395410
# INDEXER
396411

397412
# GET /indexer/schema

pyarr/lidarr.py

+31-11
Original file line numberDiff line numberDiff line change
@@ -744,23 +744,43 @@ def get_retag(
744744

745745
# POST /qualityprofile
746746
def add_quality_profile(
747-
self, name: str, upgrades_allowed: bool, cutoff: int, items: list
747+
self,
748+
name: str,
749+
upgrade_allowed: bool,
750+
cutoff: int,
751+
schema: dict[str, Any],
752+
language: dict,
753+
min_format_score: int = 0,
754+
cutoff_format_score: int = 0,
755+
format_items: list = None,
748756
) -> JsonObject:
749-
"""Add new quality profile
757+
"""Add new quality profile.
750758
751759
Args:
752760
name (str): Name of the profile
753-
upgrades_allowed (bool): Are upgrades in quality allowed?
761+
upgrade_allowed (bool): Are upgrades in quality allowed?
754762
cutoff (int): ID of quality definition to cutoff at. Must be an allowed definition ID.
755-
items (list): Add a list of items (from `get_quality_definition()`)
763+
schema (dict[str, Any]): Add the profile schema (from `get_quality_profile_schema()`)
764+
language (dict): Language profile (from `get_language()`)
765+
min_format_score (int, optional): Minimum format score. Defaults to 0.
766+
cutoff_format_score (int, optional): Cutoff format score. Defaults to 0.
767+
format_items (list, optional): Format items. Defaults to [].
768+
769+
Note:
770+
Update the result from `get_quality_profile_schema()` set the items you need
771+
from `"allowed": false` to `"allowed": true`. See tests for more details.
756772
757773
Returns:
758774
JsonObject: An object containing the profile
759775
"""
760-
data = {
761-
"name": name,
762-
"upgradeAllowed": upgrades_allowed,
763-
"cutoff": cutoff,
764-
"items": items,
765-
}
766-
return self._post("qualityprofile", self.ver_uri, data=data)
776+
if format_items is None:
777+
format_items = []
778+
schema["name"] = name
779+
schema["upgradeAllowed"] = upgrade_allowed
780+
schema["cutoff"] = cutoff
781+
schema["formatItems"] = format_items
782+
schema["language"] = language
783+
schema["minFormatScore"] = min_format_score
784+
schema["cutoffFormatScore"] = cutoff_format_score
785+
786+
return self._post("qualityprofile", self.ver_uri, data=schema)

pyarr/models/common.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@
2323
within Arr api docs.
2424
"""
2525

26-
PyarrHistorySortKey = Literal["time"]
26+
PyarrHistorySortKey = Literal[
27+
"id",
28+
"date",
29+
"eventType",
30+
"series.title",
31+
"episode.title",
32+
"movieFile.relativePath",
33+
"sourceTitle",
34+
"status",
35+
]
2736
"""History sort keys
2837
38+
series.title (Sonarr)
39+
episode.title (Sonarr)
40+
status (Lidarr only)
41+
2942
Note:
3043
There may be more, but these are not well documented
3144
within Arr api docs.

pyarr/models/lidarr.py

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@
5050
"SpotifyPlaylist",
5151
"SpotifySavedAlbums",
5252
]
53+
54+
#: Lidarr History Sort Keys
55+
LidarrHistorySortKey = Literal["sourceTitle", "status"]

pyarr/radarr.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -541,26 +541,50 @@ def get_custom_filter(self) -> JsonArray:
541541

542542
# POST /qualityprofile
543543
def add_quality_profile(
544-
self, name: str, upgrades_allowed: bool, cutoff: int, items: list
544+
self,
545+
name: str,
546+
schema: dict[str, Any],
547+
cutoff: int,
548+
upgrade_allowed: Optional[bool] = None,
549+
language: Optional[dict[str, Any]] = None,
550+
min_format_score: Optional[int] = None,
551+
cutoff_format_score: Optional[int] = None,
552+
format_items: Optional[list] = None,
545553
) -> JsonObject:
546554
"""Add new quality profile
547555
548556
Args:
549557
name (str): Name of the profile
550-
upgrades_allowed (bool): Are upgrades in quality allowed?
558+
schema (dict[str, Any]): Add the profile schema (from `get_quality_profile_schema()`)
551559
cutoff (int): ID of quality definition to cutoff at. Must be an allowed definition ID.
552-
items (list): Add a list of items (from `get_quality_definition()`)
560+
upgrade_allowed (bool, optional): Are upgrades in quality allowed?. Default provided by schema.
561+
language (dict, optional): Language profile (from `get_language()`). Default provided by schema.
562+
min_format_score (int, optional): Minimum format score. Default provided by schema.
563+
cutoff_format_score (int, optional): Cutoff format score. Default provided by schema.
564+
format_items (list, optional): Format items. Default provided by schema.
565+
566+
Note:
567+
Update the result from `get_quality_profile_schema()` set the items you need
568+
from `"allowed": false` to `"allowed": true`. See tests for more details.
553569
554570
Returns:
555571
JsonObject: An object containing the profile
556572
"""
557-
data = {
558-
"name": name,
559-
"upgradeAllowed": upgrades_allowed,
560-
"cutoff": cutoff,
561-
"items": items,
562-
}
563-
return self._post("qualityprofile", self.ver_uri, data=data)
573+
schema["name"] = name
574+
schema["cutoff"] = cutoff
575+
576+
if format_items is not None:
577+
schema["formatItems"] = format_items
578+
if language is not None:
579+
schema["language"] = language
580+
if upgrade_allowed is not None:
581+
schema["upgradeAllowed"] = upgrade_allowed
582+
if min_format_score is not None:
583+
schema["minFormatScore"] = min_format_score
584+
if cutoff_format_score is not None:
585+
schema["cutoffFormatScore"] = cutoff_format_score
586+
587+
return self._post("qualityprofile", self.ver_uri, data=schema)
564588

565589
# GET /manualimport
566590
def get_manual_import(

pyarr/readarr.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,25 @@ def add_book(
432432
return self._post("book", self.ver_uri, data=book)
433433

434434
# PUT /book/{id}
435-
def upd_book(self, id_: int, data: JsonObject) -> JsonObject:
436-
"""Update the given book, currently only monitored is changed, all other modifications are ignored.
435+
def upd_book(self, book: JsonObject, editions: JsonArray) -> JsonObject:
436+
"""Update the given book.
437437
438438
Note:
439-
To be used in conjunction with get_book()
439+
To be used in conjunction with get_book() and get_edition()
440+
441+
Currently only monitored states are updated (for the book and edition).
440442
441443
Args:
442444
id_ (int): Book database ID to update
443-
data (JsonObject): All parameters to update book
445+
book (JsonObject): All parameters to update book
446+
editions (JsonArray): List of editions to update book from `get_edition()`
444447
445448
Returns:
446449
JsonObject: Dictionary with updated record
447450
"""
448-
return self._put(f"book/{id_}", self.ver_uri, data=data)
451+
book["editions"] = editions
452+
453+
return self._put("book", self.ver_uri, data=book)
449454

450455
# PUT /book/monitor
451456
def upd_book_monitor(
@@ -841,3 +846,16 @@ def upd_manual_import(self, data: JsonObject) -> JsonObject:
841846
JsonObject: Dictionary of updated record
842847
"""
843848
return self._put("manualimport", self.ver_uri, data=data)
849+
850+
# GET /edition
851+
def get_edition(self, id_: int) -> JsonArray:
852+
"""Get edition's for specific book
853+
854+
Args:
855+
id_ (int): Database ID of book
856+
857+
Returns:
858+
JsonObject: Dictionary of editions
859+
"""
860+
861+
return self._get("edition", self.ver_uri, params={"bookId": id_})

pyarr/request_handler.py

-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ def _process_response(
252252
if res.status_code == 502:
253253
raise PyarrBadGateway("Bad Gateway. Check your server is accessible.")
254254

255-
print(res.status_code)
256255
content_type = res.headers.get("Content-Type", "")
257256
if "application/json" in content_type:
258257
return res.json()

pyarr/sonarr.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,7 @@ def add_series(
518518
"searchForMissingEpisodes": search_for_missing_episodes,
519519
}
520520

521-
response: dict[str, Any] = self._post("series", self.ver_uri, data=series)
522-
for item in response:
523-
if "errorMessage" in item:
524-
raise Exception(item)
525-
else:
526-
continue
527-
528-
return response
521+
return self._post("series", self.ver_uri, data=series)
529522

530523
# PUT /series
531524
def upd_series(self, data: JsonObject) -> JsonObject:
@@ -617,7 +610,10 @@ def get_history(
617610
Returns:
618611
JsonObject: Dictionary with items
619612
"""
620-
params: dict[str, Union[int, PyarrHistorySortKey, PyarrSortDirection]] = {}
613+
params: dict[
614+
str,
615+
Union[int, PyarrHistorySortKey, PyarrSortDirection],
616+
] = {}
621617

622618
if page:
623619
params["page"] = page

tests/test_lidarr.py

+22-45
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,17 @@ def test_get_history(lidarr_client: LidarrAPI):
781781
data = lidarr_client.get_history()
782782
assert isinstance(data, dict)
783783

784-
data = lidarr_client.get_history(
785-
page=1,
786-
page_size=10,
787-
sort_key="time",
788-
sort_dir="default",
789-
)
790-
assert isinstance(data, dict)
784+
for key in ["id", "date", "eventType", "status"]:
785+
data = lidarr_client.get_history(
786+
page=1,
787+
page_size=10,
788+
sort_key=key,
789+
sort_dir="default",
790+
)
791+
assert isinstance(data, dict)
791792

792793
with contextlib.suppress(PyarrMissingArgument):
793-
data = lidarr_client.get_history(sort_key="time")
794+
data = lidarr_client.get_history(sort_key="date")
794795
assert False
795796

796797
with contextlib.suppress(PyarrMissingArgument):
@@ -799,45 +800,16 @@ def test_get_history(lidarr_client: LidarrAPI):
799800

800801

801802
def test_add_quality_profile(lidarr_client: LidarrAPI):
803+
language = lidarr_client.get_language()[0]
804+
schema = lidarr_client.get_quality_profile_schema()
805+
schema["items"][1]["allowed"] = True
806+
802807
data = lidarr_client.add_quality_profile(
803808
name="music",
804-
upgrades_allowed=True,
805-
cutoff=1005,
806-
items=[
807-
{"quality": {"id": 0, "name": "Unknown"}, "items": [], "allowed": True},
808-
{
809-
"name": "Lossless",
810-
"items": [
811-
{
812-
"quality": {"id": 7, "name": "ALAC"},
813-
"items": [],
814-
"allowed": True,
815-
},
816-
{
817-
"quality": {"id": 6, "name": "FLAC"},
818-
"items": [],
819-
"allowed": True,
820-
},
821-
{
822-
"quality": {"id": 35, "name": "APE"},
823-
"items": [],
824-
"allowed": True,
825-
},
826-
{
827-
"quality": {"id": 36, "name": "WavPack"},
828-
"items": [],
829-
"allowed": True,
830-
},
831-
{
832-
"quality": {"id": 21, "name": "FLAC 24bit"},
833-
"items": [],
834-
"allowed": True,
835-
},
836-
],
837-
"allowed": True,
838-
"id": 1005,
839-
},
840-
],
809+
upgrade_allowed=True,
810+
cutoff=schema["items"][1]["id"],
811+
schema=schema,
812+
language=language,
841813
)
842814
assert isinstance(data, dict)
843815

@@ -874,6 +846,11 @@ def test_upd_quality_definition(lidarr_client: LidarrAPI):
874846
assert data["maxSize"] == rand_float
875847

876848

849+
def test_get_quality_profile_schema(lidarr_client: LidarrAPI):
850+
data = lidarr_client.get_quality_profile_schema()
851+
assert isinstance(data, dict)
852+
853+
877854
def test_get_indexer_schema(lidarr_client: LidarrAPI):
878855
data = lidarr_client.get_indexer_schema()
879856
assert isinstance(data, list)

0 commit comments

Comments
 (0)