|
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 |
|
@@ -318,6 +319,105 @@ def test_video_Movie_history(movie): |
318 | 319 | movie.markUnwatched() |
319 | 320 |
|
320 | 321 |
|
| 322 | +def test_video_Movie_match(movies): |
| 323 | + sectionAgent = movies.agent |
| 324 | + sectionAgents = [agent.identifier for agent in movies.agents() if agent.shortIdentifier != 'none'] |
| 325 | + sectionAgents.remove(sectionAgent) |
| 326 | + altAgent = sectionAgents[0] |
| 327 | + |
| 328 | + movie = movies.all()[0] |
| 329 | + title = movie.title |
| 330 | + year = str(movie.year) |
| 331 | + titleUrlEncode = quote_plus(title) |
| 332 | + |
| 333 | + def parse_params(key): |
| 334 | + params = key.split('?', 1)[1] |
| 335 | + params = params.split("&") |
| 336 | + return {x.split("=")[0]: x.split("=")[1] for x in params} |
| 337 | + |
| 338 | + results = movie.matches(title="", year="") |
| 339 | + if results: |
| 340 | + initpath = results[0]._initpath |
| 341 | + assert initpath.startswith(movie.key) |
| 342 | + params = initpath.split(movie.key)[1] |
| 343 | + parsedParams = parse_params(params) |
| 344 | + assert parsedParams.get('manual') == '1' |
| 345 | + assert parsedParams.get('title') == "" |
| 346 | + assert parsedParams.get('year') == "" |
| 347 | + assert parsedParams.get('agent') == sectionAgent |
| 348 | + else: |
| 349 | + assert len(results) == 0 |
| 350 | + |
| 351 | + results = movie.matches(title=title, year="", agent=sectionAgent) |
| 352 | + if results: |
| 353 | + initpath = results[0]._initpath |
| 354 | + assert initpath.startswith(movie.key) |
| 355 | + params = initpath.split(movie.key)[1] |
| 356 | + parsedParams = parse_params(params) |
| 357 | + assert parsedParams.get('manual') == '1' |
| 358 | + assert parsedParams.get('title') == titleUrlEncode |
| 359 | + assert parsedParams.get('year') == "" |
| 360 | + assert parsedParams.get('agent') == sectionAgent |
| 361 | + else: |
| 362 | + assert len(results) == 0 |
| 363 | + |
| 364 | + results = movie.matches(title=title, agent=sectionAgent) |
| 365 | + if results: |
| 366 | + initpath = results[0]._initpath |
| 367 | + assert initpath.startswith(movie.key) |
| 368 | + params = initpath.split(movie.key)[1] |
| 369 | + parsedParams = parse_params(params) |
| 370 | + assert parsedParams.get('manual') == '1' |
| 371 | + assert parsedParams.get('title') == titleUrlEncode |
| 372 | + assert parsedParams.get('year') == year |
| 373 | + assert parsedParams.get('agent') == sectionAgent |
| 374 | + else: |
| 375 | + assert len(results) == 0 |
| 376 | + |
| 377 | + results = movie.matches(title="", year="") |
| 378 | + if results: |
| 379 | + initpath = results[0]._initpath |
| 380 | + assert initpath.startswith(movie.key) |
| 381 | + params = initpath.split(movie.key)[1] |
| 382 | + parsedParams = parse_params(params) |
| 383 | + assert parsedParams.get('manual') == '1' |
| 384 | + assert parsedParams.get('agent') == sectionAgent |
| 385 | + else: |
| 386 | + assert len(results) == 0 |
| 387 | + |
| 388 | + results = movie.matches(title="", year="", agent=altAgent) |
| 389 | + if results: |
| 390 | + initpath = results[0]._initpath |
| 391 | + assert initpath.startswith(movie.key) |
| 392 | + params = initpath.split(movie.key)[1] |
| 393 | + parsedParams = parse_params(params) |
| 394 | + assert parsedParams.get('manual') == '1' |
| 395 | + assert parsedParams.get('agent') == altAgent |
| 396 | + else: |
| 397 | + assert len(results) == 0 |
| 398 | + |
| 399 | + results = movie.matches(agent=altAgent) |
| 400 | + if results: |
| 401 | + initpath = results[0]._initpath |
| 402 | + assert initpath.startswith(movie.key) |
| 403 | + params = initpath.split(movie.key)[1] |
| 404 | + parsedParams = parse_params(params) |
| 405 | + assert parsedParams.get('manual') == '1' |
| 406 | + assert parsedParams.get('agent') == altAgent |
| 407 | + else: |
| 408 | + assert len(results) == 0 |
| 409 | + |
| 410 | + results = movie.matches() |
| 411 | + if results: |
| 412 | + initpath = results[0]._initpath |
| 413 | + assert initpath.startswith(movie.key) |
| 414 | + params = initpath.split(movie.key)[1] |
| 415 | + parsedParams = parse_params(params) |
| 416 | + assert parsedParams.get('manual') == '1' |
| 417 | + else: |
| 418 | + assert len(results) == 0 |
| 419 | + |
| 420 | + |
321 | 421 | def test_video_Show(show): |
322 | 422 | assert show.title == 'Game of Thrones' |
323 | 423 |
|
|
0 commit comments