Skip to content

Commit

Permalink
fix: readarr upd_book now functioning as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
marksie1988 committed Apr 18, 2023
1 parent baabe59 commit bc699b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
17 changes: 11 additions & 6 deletions pyarr/readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,25 @@ def add_book(
return self._post("book", self.ver_uri, data=book)

# PUT /book/{id}
def upd_book(self, id_: int, data: JsonObject) -> JsonObject:
"""Update the given book, currently only monitored is changed, all other modifications are ignored.
def upd_book(self, book: JsonObject, editions: JsonArray) -> JsonObject:
"""Update the given book.
Note:
To be used in conjunction with get_book()
To be used in conjunction with get_book() and get_edition()
Currently only monitored states are updated (for the book and edition).
Args:
id_ (int): Book database ID to update
data (JsonObject): All parameters to update book
book (JsonObject): All parameters to update book
editions (JsonArray): List of editions to update book from `get_edition()`
Returns:
JsonObject: Dictionary with updated record
"""
return self._put(f"book/{id_}", self.ver_uri, data=data)
book["editions"] = editions

return self._put("book", self.ver_uri, data=book)

# PUT /book/monitor
def upd_book_monitor(
Expand Down Expand Up @@ -843,7 +848,7 @@ def upd_manual_import(self, data: JsonObject) -> JsonObject:
return self._put("manualimport", self.ver_uri, data=data)

# GET /edition
def get_edition(self, id_: int) -> JsonObject:
def get_edition(self, id_: int) -> JsonArray:
"""Get edition's for specific book
Args:
Expand Down
20 changes: 5 additions & 15 deletions tests/test_readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def test_add_delay_profile(readarr_client: ReadarrAPI):
assert data["minimumCustomFormatScore"] == 10


@pytest.mark.usefixtures
def test_get_missing(readarr_client: ReadarrAPI):
data = readarr_client.get_missing()
assert isinstance(data, dict)
Expand All @@ -233,7 +232,6 @@ def test_get_missing(readarr_client: ReadarrAPI):
assert False


@pytest.mark.usefixtures
def test_get_cutoff(readarr_client: ReadarrAPI):
data = readarr_client.get_cutoff()
assert isinstance(data, dict)
Expand All @@ -255,7 +253,6 @@ def test_get_cutoff(readarr_client: ReadarrAPI):
assert False


@pytest.mark.usefixtures
def test_get_book(readarr_client: ReadarrAPI):
data = readarr_client.get_book()
assert isinstance(data, list)
Expand All @@ -264,20 +261,19 @@ def test_get_book(readarr_client: ReadarrAPI):
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_upd_book(readarr_client: ReadarrAPI):
book = readarr_client.get_book()
editions = readarr_client.get_edition(book[0]["id"])

data = readarr_client.get_edition(id_=book[0]["id"])
data = readarr_client.upd_book(book=book[0], editions=editions)
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_upd_book(readarr_client: ReadarrAPI):
def test_get_edition(readarr_client: ReadarrAPI):
book = readarr_client.get_book()

data = readarr_client.upd_book(id_=book[0]["id"], data=book[0])
assert isinstance(data, dict)
data = readarr_client.get_edition(id_=book[0]["id"])
assert isinstance(data, list)


def test_upd_book_monitor(readarr_client: ReadarrAPI):
Expand All @@ -290,7 +286,6 @@ def test_upd_book_monitor(readarr_client: ReadarrAPI):
assert data[0]["monitored"] == False


@pytest.mark.usefixtures
def test_add_author(readarr_client: ReadarrAPI):
qual_profile = readarr_client.get_quality_profile()
meta_profile = readarr_client.get_metadata_profile()
Expand All @@ -312,7 +307,6 @@ def test_add_author(readarr_client: ReadarrAPI):
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_upd_author(readarr_client: ReadarrAPI):
author = readarr_client.get_author()
author[0]["monitored"] = True
Expand All @@ -322,7 +316,6 @@ def test_upd_author(readarr_client: ReadarrAPI):
assert data["monitored"] == True


@pytest.mark.usefixtures
def test_get_author(readarr_client: ReadarrAPI):
data = readarr_client.get_author()
assert isinstance(data, list)
Expand All @@ -331,7 +324,6 @@ def test_get_author(readarr_client: ReadarrAPI):
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_get_metadata_profile(readarr_client: ReadarrAPI):
data = readarr_client.get_metadata_profile()
assert isinstance(data, list)
Expand All @@ -340,7 +332,6 @@ def test_get_metadata_profile(readarr_client: ReadarrAPI):
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_get_delay_profile(readarr_client: ReadarrAPI):
data = readarr_client.get_delay_profile()
assert isinstance(data, list)
Expand All @@ -349,7 +340,6 @@ def test_get_delay_profile(readarr_client: ReadarrAPI):
assert isinstance(data, dict)


@pytest.mark.usefixtures
def test_get_release_profile(readarr_client: ReadarrAPI):
data = readarr_client.get_release_profile()
assert isinstance(data, list)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_get_episode(sonarr_client: SonarrAPI):

def test_upd_series(sonarr_client: SonarrAPI):
series = sonarr_client.get_series()
series["monitored"] = False
series[0]["monitored"] = False

data = sonarr_client.upd_series(data=series[0])
assert isinstance(data, dict)
Expand Down

0 comments on commit bc699b4

Please sign in to comment.