|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from plexapi.exceptions import BadRequest, NotFound |
| 8 | +from plexapi.compat import quote_plus |
8 | 9 |
|
9 | 10 | from . import conftest as utils |
10 | 11 |
|
@@ -349,6 +350,105 @@ def test_video_Movie_history(movie): |
349 | 350 | movie.markUnwatched() |
350 | 351 |
|
351 | 352 |
|
| 353 | +def test_video_Movie_match(movies): |
| 354 | + sectionAgent = movies.agent |
| 355 | + sectionAgents = [agent.identifier for agent in movies.agents() if agent.shortIdentifier != 'none'] |
| 356 | + sectionAgents.remove(sectionAgent) |
| 357 | + altAgent = sectionAgents[0] |
| 358 | + |
| 359 | + movie = movies.all()[0] |
| 360 | + title = movie.title |
| 361 | + year = str(movie.year) |
| 362 | + titleUrlEncode = quote_plus(title) |
| 363 | + |
| 364 | + def parse_params(key): |
| 365 | + params = key.split('?', 1)[1] |
| 366 | + params = params.split("&") |
| 367 | + return {x.split("=")[0]: x.split("=")[1] for x in params} |
| 368 | + |
| 369 | + results = movie.matches(title="", year="") |
| 370 | + if results: |
| 371 | + initpath = results[0]._initpath |
| 372 | + assert initpath.startswith(movie.key) |
| 373 | + params = initpath.split(movie.key)[1] |
| 374 | + parsedParams = parse_params(params) |
| 375 | + assert parsedParams.get('manual') == '1' |
| 376 | + assert parsedParams.get('title') == "" |
| 377 | + assert parsedParams.get('year') == "" |
| 378 | + assert parsedParams.get('agent') == sectionAgent |
| 379 | + else: |
| 380 | + assert len(results) == 0 |
| 381 | + |
| 382 | + results = movie.matches(title=title, year="", agent=sectionAgent) |
| 383 | + if results: |
| 384 | + initpath = results[0]._initpath |
| 385 | + assert initpath.startswith(movie.key) |
| 386 | + params = initpath.split(movie.key)[1] |
| 387 | + parsedParams = parse_params(params) |
| 388 | + assert parsedParams.get('manual') == '1' |
| 389 | + assert parsedParams.get('title') == titleUrlEncode |
| 390 | + assert parsedParams.get('year') == "" |
| 391 | + assert parsedParams.get('agent') == sectionAgent |
| 392 | + else: |
| 393 | + assert len(results) == 0 |
| 394 | + |
| 395 | + results = movie.matches(title=title, agent=sectionAgent) |
| 396 | + if results: |
| 397 | + initpath = results[0]._initpath |
| 398 | + assert initpath.startswith(movie.key) |
| 399 | + params = initpath.split(movie.key)[1] |
| 400 | + parsedParams = parse_params(params) |
| 401 | + assert parsedParams.get('manual') == '1' |
| 402 | + assert parsedParams.get('title') == titleUrlEncode |
| 403 | + assert parsedParams.get('year') == year |
| 404 | + assert parsedParams.get('agent') == sectionAgent |
| 405 | + else: |
| 406 | + assert len(results) == 0 |
| 407 | + |
| 408 | + results = movie.matches(title="", year="") |
| 409 | + if results: |
| 410 | + initpath = results[0]._initpath |
| 411 | + assert initpath.startswith(movie.key) |
| 412 | + params = initpath.split(movie.key)[1] |
| 413 | + parsedParams = parse_params(params) |
| 414 | + assert parsedParams.get('manual') == '1' |
| 415 | + assert parsedParams.get('agent') == sectionAgent |
| 416 | + else: |
| 417 | + assert len(results) == 0 |
| 418 | + |
| 419 | + results = movie.matches(title="", year="", agent=altAgent) |
| 420 | + if results: |
| 421 | + initpath = results[0]._initpath |
| 422 | + assert initpath.startswith(movie.key) |
| 423 | + params = initpath.split(movie.key)[1] |
| 424 | + parsedParams = parse_params(params) |
| 425 | + assert parsedParams.get('manual') == '1' |
| 426 | + assert parsedParams.get('agent') == altAgent |
| 427 | + else: |
| 428 | + assert len(results) == 0 |
| 429 | + |
| 430 | + results = movie.matches(agent=altAgent) |
| 431 | + if results: |
| 432 | + initpath = results[0]._initpath |
| 433 | + assert initpath.startswith(movie.key) |
| 434 | + params = initpath.split(movie.key)[1] |
| 435 | + parsedParams = parse_params(params) |
| 436 | + assert parsedParams.get('manual') == '1' |
| 437 | + assert parsedParams.get('agent') == altAgent |
| 438 | + else: |
| 439 | + assert len(results) == 0 |
| 440 | + |
| 441 | + results = movie.matches() |
| 442 | + if results: |
| 443 | + initpath = results[0]._initpath |
| 444 | + assert initpath.startswith(movie.key) |
| 445 | + params = initpath.split(movie.key)[1] |
| 446 | + parsedParams = parse_params(params) |
| 447 | + assert parsedParams.get('manual') == '1' |
| 448 | + else: |
| 449 | + assert len(results) == 0 |
| 450 | + |
| 451 | + |
352 | 452 | def test_video_Show(show): |
353 | 453 | assert show.title == "Game of Thrones" |
354 | 454 |
|
|
0 commit comments