|
1 | 1 | import itertools
|
| 2 | +import json |
2 | 3 | import logging
|
3 | 4 | import os
|
4 | 5 | import re
|
@@ -481,6 +482,57 @@ def test_parse_links__requires_python(
|
481 | 482 | _test_parse_links_data_attribute(anchor_html, "requires_python", expected)
|
482 | 483 |
|
483 | 484 |
|
| 485 | +def test_parse_links_json() -> None: |
| 486 | + json_bytes = json.dumps( |
| 487 | + { |
| 488 | + "meta": {"api-version": "1.0"}, |
| 489 | + "name": "holygrail", |
| 490 | + "files": [ |
| 491 | + { |
| 492 | + "filename": "holygrail-1.0.tar.gz", |
| 493 | + "url": "https://example.com/files/holygrail-1.0.tar.gz", |
| 494 | + "hashes": {"sha256": "sha256 hash", "blake2b": "blake2b hash"}, |
| 495 | + "requires-python": ">=3.7", |
| 496 | + "yanked": "Had a vulnerability", |
| 497 | + }, |
| 498 | + { |
| 499 | + "filename": "holygrail-1.0-py3-none-any.whl", |
| 500 | + "url": "/files/holygrail-1.0-py3-none-any.whl", |
| 501 | + "hashes": {"sha256": "sha256 hash", "blake2b": "blake2b hash"}, |
| 502 | + "requires-python": ">=3.7", |
| 503 | + "dist-info-metadata": False, |
| 504 | + }, |
| 505 | + ], |
| 506 | + } |
| 507 | + ).encode("utf8") |
| 508 | + page = IndexContent( |
| 509 | + json_bytes, |
| 510 | + "application/vnd.pypi.simple.v1+json", |
| 511 | + encoding=None, |
| 512 | + # parse_links() is cached by url, so we inject a random uuid to ensure |
| 513 | + # the page content isn't cached. |
| 514 | + url=f"https://example.com/simple-{uuid.uuid4()}/", |
| 515 | + ) |
| 516 | + links = list(parse_links(page, use_deprecated_html5lib=False)) |
| 517 | + |
| 518 | + assert links == [ |
| 519 | + Link( |
| 520 | + "https://example.com/files/holygrail-1.0.tar.gz", |
| 521 | + comes_from=page.url, |
| 522 | + requires_python=">=3.7", |
| 523 | + yanked_reason="Had a vulnerability", |
| 524 | + hashes={"sha256": "sha256 hash", "blake2b": "blake2b hash"}, |
| 525 | + ), |
| 526 | + Link( |
| 527 | + "https://example.com/files/holygrail-1.0-py3-none-any.whl", |
| 528 | + comes_from=page.url, |
| 529 | + requires_python=">=3.7", |
| 530 | + yanked_reason=None, |
| 531 | + hashes={"sha256": "sha256 hash", "blake2b": "blake2b hash"}, |
| 532 | + ), |
| 533 | + ] |
| 534 | + |
| 535 | + |
484 | 536 | @pytest.mark.parametrize(
|
485 | 537 | "anchor_html, expected",
|
486 | 538 | [
|
|
0 commit comments