Skip to content

Commit bc699b4

Browse files
committed
fix: readarr upd_book now functioning as expected
1 parent baabe59 commit bc699b4

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

pyarr/readarr.py

+11-6
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(
@@ -843,7 +848,7 @@ def upd_manual_import(self, data: JsonObject) -> JsonObject:
843848
return self._put("manualimport", self.ver_uri, data=data)
844849

845850
# GET /edition
846-
def get_edition(self, id_: int) -> JsonObject:
851+
def get_edition(self, id_: int) -> JsonArray:
847852
"""Get edition's for specific book
848853
849854
Args:

tests/test_readarr.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def test_add_delay_profile(readarr_client: ReadarrAPI):
212212
assert data["minimumCustomFormatScore"] == 10
213213

214214

215-
@pytest.mark.usefixtures
216215
def test_get_missing(readarr_client: ReadarrAPI):
217216
data = readarr_client.get_missing()
218217
assert isinstance(data, dict)
@@ -233,7 +232,6 @@ def test_get_missing(readarr_client: ReadarrAPI):
233232
assert False
234233

235234

236-
@pytest.mark.usefixtures
237235
def test_get_cutoff(readarr_client: ReadarrAPI):
238236
data = readarr_client.get_cutoff()
239237
assert isinstance(data, dict)
@@ -255,7 +253,6 @@ def test_get_cutoff(readarr_client: ReadarrAPI):
255253
assert False
256254

257255

258-
@pytest.mark.usefixtures
259256
def test_get_book(readarr_client: ReadarrAPI):
260257
data = readarr_client.get_book()
261258
assert isinstance(data, list)
@@ -264,20 +261,19 @@ def test_get_book(readarr_client: ReadarrAPI):
264261
assert isinstance(data, dict)
265262

266263

267-
@pytest.mark.usefixtures
268264
def test_upd_book(readarr_client: ReadarrAPI):
269265
book = readarr_client.get_book()
266+
editions = readarr_client.get_edition(book[0]["id"])
270267

271-
data = readarr_client.get_edition(id_=book[0]["id"])
268+
data = readarr_client.upd_book(book=book[0], editions=editions)
272269
assert isinstance(data, dict)
273270

274271

275-
@pytest.mark.usefixtures
276-
def test_upd_book(readarr_client: ReadarrAPI):
272+
def test_get_edition(readarr_client: ReadarrAPI):
277273
book = readarr_client.get_book()
278274

279-
data = readarr_client.upd_book(id_=book[0]["id"], data=book[0])
280-
assert isinstance(data, dict)
275+
data = readarr_client.get_edition(id_=book[0]["id"])
276+
assert isinstance(data, list)
281277

282278

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

292288

293-
@pytest.mark.usefixtures
294289
def test_add_author(readarr_client: ReadarrAPI):
295290
qual_profile = readarr_client.get_quality_profile()
296291
meta_profile = readarr_client.get_metadata_profile()
@@ -312,7 +307,6 @@ def test_add_author(readarr_client: ReadarrAPI):
312307
assert isinstance(data, dict)
313308

314309

315-
@pytest.mark.usefixtures
316310
def test_upd_author(readarr_client: ReadarrAPI):
317311
author = readarr_client.get_author()
318312
author[0]["monitored"] = True
@@ -322,7 +316,6 @@ def test_upd_author(readarr_client: ReadarrAPI):
322316
assert data["monitored"] == True
323317

324318

325-
@pytest.mark.usefixtures
326319
def test_get_author(readarr_client: ReadarrAPI):
327320
data = readarr_client.get_author()
328321
assert isinstance(data, list)
@@ -331,7 +324,6 @@ def test_get_author(readarr_client: ReadarrAPI):
331324
assert isinstance(data, dict)
332325

333326

334-
@pytest.mark.usefixtures
335327
def test_get_metadata_profile(readarr_client: ReadarrAPI):
336328
data = readarr_client.get_metadata_profile()
337329
assert isinstance(data, list)
@@ -340,7 +332,6 @@ def test_get_metadata_profile(readarr_client: ReadarrAPI):
340332
assert isinstance(data, dict)
341333

342334

343-
@pytest.mark.usefixtures
344335
def test_get_delay_profile(readarr_client: ReadarrAPI):
345336
data = readarr_client.get_delay_profile()
346337
assert isinstance(data, list)
@@ -349,7 +340,6 @@ def test_get_delay_profile(readarr_client: ReadarrAPI):
349340
assert isinstance(data, dict)
350341

351342

352-
@pytest.mark.usefixtures
353343
def test_get_release_profile(readarr_client: ReadarrAPI):
354344
data = readarr_client.get_release_profile()
355345
assert isinstance(data, list)

tests/test_sonarr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_get_episode(sonarr_client: SonarrAPI):
189189

190190
def test_upd_series(sonarr_client: SonarrAPI):
191191
series = sonarr_client.get_series()
192-
series["monitored"] = False
192+
series[0]["monitored"] = False
193193

194194
data = sonarr_client.upd_series(data=series[0])
195195
assert isinstance(data, dict)

0 commit comments

Comments
 (0)