|
10 | 10 | Content, |
11 | 11 | Cookies, |
12 | 12 | Data, |
| 13 | + Files, |
13 | 14 | Headers, |
14 | 15 | Host, |
15 | 16 | Lookup, |
@@ -389,6 +390,112 @@ def test_data_pattern(lookup, data, request_data, expected): |
389 | 390 | assert bool(match) is expected |
390 | 391 |
|
391 | 392 |
|
| 393 | +@pytest.mark.parametrize( |
| 394 | + ("lookup", "files", "request_files", "expected"), |
| 395 | + [ |
| 396 | + ( |
| 397 | + Lookup.EQUAL, |
| 398 | + [("file_1", b"foo..."), ("file_2", b"bar...")], |
| 399 | + None, |
| 400 | + True, |
| 401 | + ), |
| 402 | + ( |
| 403 | + Lookup.EQUAL, |
| 404 | + {"file_1": b"foo...", "file_2": b"bar..."}, |
| 405 | + None, |
| 406 | + True, |
| 407 | + ), |
| 408 | + ( |
| 409 | + Lookup.EQUAL, |
| 410 | + {"file_1": ANY}, |
| 411 | + {"file_1": b"foobar..."}, |
| 412 | + True, |
| 413 | + ), |
| 414 | + ( |
| 415 | + Lookup.EQUAL, |
| 416 | + { |
| 417 | + "file_1": ("filename_1.txt", b"foo..."), |
| 418 | + "file_2": ("filename_2.txt", b"bar..."), |
| 419 | + }, |
| 420 | + None, |
| 421 | + True, |
| 422 | + ), |
| 423 | + ( |
| 424 | + Lookup.EQUAL, |
| 425 | + {"file_1": ("filename_1.txt", ANY)}, |
| 426 | + {"file_1": ("filename_1.txt", b"...")}, |
| 427 | + True, |
| 428 | + ), |
| 429 | + ( |
| 430 | + Lookup.EQUAL, |
| 431 | + {"upload": b"foo..."}, |
| 432 | + {"upload": b"bar..."}, # Wrong file data |
| 433 | + False, |
| 434 | + ), |
| 435 | + ( |
| 436 | + Lookup.EQUAL, |
| 437 | + { |
| 438 | + "file_1": ("filename_1.txt", b"foo..."), |
| 439 | + "file_2": ("filename_2.txt", b"bar..."), |
| 440 | + }, |
| 441 | + { |
| 442 | + "file_1": ("filename_1.txt", b"foo..."), |
| 443 | + "file_2": ("filename_2.txt", b"ham..."), # Wrong file data |
| 444 | + }, |
| 445 | + False, |
| 446 | + ), |
| 447 | + ( |
| 448 | + Lookup.CONTAINS, |
| 449 | + { |
| 450 | + "file_1": ("filename_1.txt", b"foo..."), |
| 451 | + }, |
| 452 | + { |
| 453 | + "file_1": ("filename_1.txt", b"foo..."), |
| 454 | + "file_2": ("filename_2.txt", b"bar..."), |
| 455 | + }, |
| 456 | + True, |
| 457 | + ), |
| 458 | + ( |
| 459 | + Lookup.CONTAINS, |
| 460 | + { |
| 461 | + "file_1": ("filename_1.txt", ANY), |
| 462 | + }, |
| 463 | + { |
| 464 | + "file_1": ("filename_1.txt", b"foo..."), |
| 465 | + "file_2": ("filename_2.txt", b"bar..."), |
| 466 | + }, |
| 467 | + True, |
| 468 | + ), |
| 469 | + ( |
| 470 | + Lookup.CONTAINS, |
| 471 | + [("file_1", ANY)], |
| 472 | + { |
| 473 | + "file_1": ("filename_1.txt", b"foo..."), |
| 474 | + "file_2": ("filename_2.txt", b"bar..."), |
| 475 | + }, |
| 476 | + True, |
| 477 | + ), |
| 478 | + ( |
| 479 | + Lookup.CONTAINS, |
| 480 | + [("file_1", b"ham...")], |
| 481 | + { |
| 482 | + "file_1": ("filename_1.txt", b"foo..."), |
| 483 | + "file_2": ("filename_2.txt", b"bar..."), |
| 484 | + }, |
| 485 | + False, |
| 486 | + ), |
| 487 | + ], |
| 488 | +) |
| 489 | +def test_files_pattern(lookup, files, request_files, expected): |
| 490 | + request = httpx.Request( |
| 491 | + "POST", |
| 492 | + "https://foo.bar/", |
| 493 | + files=request_files or files, |
| 494 | + ) |
| 495 | + match = Files(files, lookup=lookup).match(request) |
| 496 | + assert bool(match) is expected |
| 497 | + |
| 498 | + |
392 | 499 | @pytest.mark.parametrize( |
393 | 500 | ("lookup", "value", "json", "expected"), |
394 | 501 | [ |
|
0 commit comments