|
52 | 52 | "ci_service": "ci_service", |
53 | 53 | "git_service": "github", |
54 | 54 | } |
| 55 | + |
| 56 | + |
| 57 | +def _upload_ingest_post_json_base(*, file_not_found: bool) -> dict: |
| 58 | + return { |
| 59 | + "ci_service": "ci_service", |
| 60 | + "ci_url": "build_url", |
| 61 | + "cli_args": None, |
| 62 | + "env": {}, |
| 63 | + "flags": "flags", |
| 64 | + "job_code": "job_code", |
| 65 | + "name": "name", |
| 66 | + "version": codecov_cli_version, |
| 67 | + "file_not_found": file_not_found, |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | +_report_payload_bytes_coverage = len( |
| 72 | + UploadSender()._generate_payload( |
| 73 | + upload_collection, {}, ReportType.COVERAGE |
| 74 | + ) |
| 75 | +) |
| 76 | + |
55 | 77 | request_data = { |
56 | | - "ci_service": "ci_service", |
57 | | - "ci_url": "build_url", |
58 | | - "cli_args": None, |
59 | | - "env": {}, |
60 | | - "flags": "flags", |
61 | | - "job_code": "job_code", |
62 | | - "name": "name", |
63 | | - "version": codecov_cli_version, |
64 | | - "file_not_found": False, |
| 78 | + **_upload_ingest_post_json_base(file_not_found=False), |
| 79 | + "report_payload_bytes": _report_payload_bytes_coverage, |
65 | 80 | } |
66 | 81 |
|
67 | 82 |
|
| 83 | +def _test_results_ingest_post_json( |
| 84 | + upload_data: UploadCollectionResult, *, file_not_found: bool |
| 85 | +) -> dict: |
| 86 | + return { |
| 87 | + **_upload_ingest_post_json_base(file_not_found=file_not_found), |
| 88 | + "slug": encode_slug("org/repo"), |
| 89 | + "branch": "branch", |
| 90 | + "commit": random_sha, |
| 91 | + "service": "github", |
| 92 | + "report_payload_bytes": len( |
| 93 | + UploadSender()._generate_payload( |
| 94 | + upload_data, {}, ReportType.TEST_RESULTS |
| 95 | + ) |
| 96 | + ), |
| 97 | + } |
| 98 | + |
| 99 | + |
68 | 100 | @pytest.fixture |
69 | 101 | def mocked_responses(): |
70 | 102 | with responses.RequestsMock() as rsps: |
@@ -266,18 +298,22 @@ def test_upload_sender_post_called_with_right_parameters_test_results( |
266 | 298 | ): |
267 | 299 | headers = {"Authorization": f"token {random_token}"} |
268 | 300 |
|
269 | | - mocked_legacy_upload_endpoint.match = [ |
270 | | - matchers.json_params_matcher(request_data), |
271 | | - matchers.header_matcher(headers), |
272 | | - ] |
273 | | - |
274 | 301 | ta_upload_collection = deepcopy(upload_collection) |
275 | 302 |
|
276 | 303 | test_path = tmp_path / "test_results.xml" |
277 | 304 | test_path.write_bytes(b"test_data") |
278 | 305 |
|
279 | 306 | ta_upload_collection.files = [UploadCollectionResultFile(test_path)] |
280 | 307 |
|
| 308 | + mocked_test_results_endpoint.match = [ |
| 309 | + matchers.json_params_matcher( |
| 310 | + _test_results_ingest_post_json( |
| 311 | + ta_upload_collection, file_not_found=False |
| 312 | + ) |
| 313 | + ), |
| 314 | + matchers.header_matcher(headers), |
| 315 | + ] |
| 316 | + |
281 | 317 | sending_result = UploadSender().send_upload_data( |
282 | 318 | ta_upload_collection, |
283 | 319 | random_sha, |
@@ -309,10 +345,11 @@ def test_upload_sender_post_called_with_right_parameters_test_results_file_not_f |
309 | 345 | ): |
310 | 346 | headers = {"Authorization": f"token {random_token}"} |
311 | 347 |
|
312 | | - req_data = deepcopy(request_data) |
313 | | - req_data["file_not_found"] = True |
| 348 | + req_data = _test_results_ingest_post_json( |
| 349 | + upload_collection, file_not_found=True |
| 350 | + ) |
314 | 351 |
|
315 | | - mocked_legacy_upload_endpoint.match = [ |
| 352 | + mocked_test_results_endpoint_file_not_found.match = [ |
316 | 353 | matchers.json_params_matcher(req_data), |
317 | 354 | matchers.header_matcher(headers), |
318 | 355 | ] |
|
0 commit comments