|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from coverage_comment import github |
| 7 | +from coverage_comment import github, github_client |
8 | 8 |
|
9 | 9 |
|
10 | 10 | @pytest.mark.parametrize( |
@@ -491,3 +491,71 @@ def test_get_branch_diff(gh, session): |
491 | 491 | ) |
492 | 492 |
|
493 | 493 | assert result == "diff --git a/foo.py b/foo.py..." |
| 494 | + |
| 495 | + |
| 496 | +def test_get_pr_diff__too_large(gh, session): |
| 497 | + error_response = { |
| 498 | + "message": "Sorry, the diff exceeded the maximum number of files (300).", |
| 499 | + "errors": [{"resource": "PullRequest", "field": "diff", "code": "too_large"}], |
| 500 | + "documentation_url": "https://docs.github.com/rest/pulls/pulls#list-pull-requests-files", |
| 501 | + "status": "406", |
| 502 | + } |
| 503 | + session.register( |
| 504 | + "GET", |
| 505 | + "/repos/foo/bar/pulls/123", |
| 506 | + headers={"Accept": "application/vnd.github.v3.diff"}, |
| 507 | + )(json=error_response, status_code=406) |
| 508 | + |
| 509 | + with pytest.raises(github.CannotGetDiff) as exc_info: |
| 510 | + github.get_pr_diff(github=gh, repository="foo/bar", pr_number=123) |
| 511 | + |
| 512 | + assert "too large" in str(exc_info.value) |
| 513 | + assert "maximum 300 files" in str(exc_info.value) |
| 514 | + |
| 515 | + |
| 516 | +def test_get_branch_diff__too_large(gh, session): |
| 517 | + error_response = { |
| 518 | + "message": "Sorry, the diff exceeded the maximum number of files (300).", |
| 519 | + "errors": [{"resource": "PullRequest", "field": "diff", "code": "too_large"}], |
| 520 | + "documentation_url": "https://docs.github.com/rest/pulls/pulls#list-pull-requests-files", |
| 521 | + "status": "406", |
| 522 | + } |
| 523 | + session.register( |
| 524 | + "GET", |
| 525 | + "/repos/foo/bar/compare/main...feature", |
| 526 | + headers={"Accept": "application/vnd.github.v3.diff"}, |
| 527 | + )(json=error_response, status_code=406) |
| 528 | + |
| 529 | + with pytest.raises(github.CannotGetDiff) as exc_info: |
| 530 | + github.get_branch_diff( |
| 531 | + github=gh, repository="foo/bar", base_branch="main", head_branch="feature" |
| 532 | + ) |
| 533 | + |
| 534 | + assert "too large" in str(exc_info.value) |
| 535 | + assert "maximum 300 files" in str(exc_info.value) |
| 536 | + |
| 537 | + |
| 538 | +def test_get_pr_diff__other_error(gh, session): |
| 539 | + error_response = {"message": "Some other error", "errors": []} |
| 540 | + session.register( |
| 541 | + "GET", |
| 542 | + "/repos/foo/bar/pulls/123", |
| 543 | + headers={"Accept": "application/vnd.github.v3.diff"}, |
| 544 | + )(json=error_response, status_code=500) |
| 545 | + |
| 546 | + with pytest.raises(github_client.ApiError): |
| 547 | + github.get_pr_diff(github=gh, repository="foo/bar", pr_number=123) |
| 548 | + |
| 549 | + |
| 550 | +def test_get_branch_diff__other_error(gh, session): |
| 551 | + error_response = {"message": "Some other error", "errors": []} |
| 552 | + session.register( |
| 553 | + "GET", |
| 554 | + "/repos/foo/bar/compare/main...feature", |
| 555 | + headers={"Accept": "application/vnd.github.v3.diff"}, |
| 556 | + )(json=error_response, status_code=500) |
| 557 | + |
| 558 | + with pytest.raises(github_client.ApiError): |
| 559 | + github.get_branch_diff( |
| 560 | + github=gh, repository="foo/bar", base_branch="main", head_branch="feature" |
| 561 | + ) |
0 commit comments