@@ -38,8 +38,35 @@ def test_valid_full_schema(self) -> None:
38
38
data = {
39
39
"checksum" : "a" * 40 ,
40
40
"chunks" : ["b" * 40 , "c" * 40 ],
41
- "git_sha" : "d" * 40 ,
42
41
"build_configuration" : "release" ,
42
+ "head_sha" : "e" * 40 ,
43
+ "base_sha" : "f" * 40 ,
44
+ "provider" : "github" ,
45
+ "head_repo_name" : "owner/repo" ,
46
+ "base_repo_name" : "owner/repo" ,
47
+ "head_ref" : "feature/xyz" ,
48
+ "base_ref" : "main" ,
49
+ "pr_number" : 123 ,
50
+ }
51
+ body = orjson .dumps (data )
52
+ result , error = validate_preprod_artifact_schema (body )
53
+ assert error is None
54
+ assert result == data
55
+
56
+ def test_valid_schema_with_commit_comparison (self ) -> None :
57
+ """Test valid schema with CommitComparison fields passes validation."""
58
+ data = {
59
+ "checksum" : "a" * 40 ,
60
+ "chunks" : ["b" * 40 , "c" * 40 ],
61
+ "build_configuration" : "release" ,
62
+ "head_sha" : "e" * 40 ,
63
+ "base_sha" : "f" * 40 ,
64
+ "provider" : "github" ,
65
+ "head_repo_name" : "owner/repo" ,
66
+ "base_repo_name" : "owner/repo" ,
67
+ "head_ref" : "feature/xyz" ,
68
+ "base_ref" : "main" ,
69
+ "pr_number" : 123 ,
43
70
}
44
71
body = orjson .dumps (data )
45
72
result , error = validate_preprod_artifact_schema (body )
@@ -105,24 +132,46 @@ def test_chunks_invalid_item_type(self) -> None:
105
132
assert error is not None
106
133
assert result == {}
107
134
108
- def test_git_sha_wrong_type (self ) -> None :
109
- """Test non-string git_sha returns error."""
110
- body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "git_sha" : 123 })
135
+ def test_build_configuration_wrong_type (self ) -> None :
136
+ """Test non-string build_configuration returns error."""
137
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "build_configuration" : 123 })
138
+ result , error = validate_preprod_artifact_schema (body )
139
+ assert error is not None
140
+ assert result == {}
141
+
142
+ def test_head_sha_invalid_format (self ) -> None :
143
+ """Test invalid head_sha format returns error."""
144
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "head_sha" : "invalid" })
111
145
result , error = validate_preprod_artifact_schema (body )
112
146
assert error is not None
147
+ assert "head_sha" in error
113
148
assert result == {}
114
149
115
- def test_git_sha_invalid_format (self ) -> None :
116
- """Test invalid git_sha format returns error."""
117
- body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "git_sha " : "invalid" })
150
+ def test_base_sha_invalid_format (self ) -> None :
151
+ """Test invalid base_sha format returns error."""
152
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "base_sha " : "invalid" })
118
153
result , error = validate_preprod_artifact_schema (body )
119
154
assert error is not None
120
- assert "git_sha " in error
155
+ assert "base_sha " in error
121
156
assert result == {}
122
157
123
- def test_build_configuration_wrong_type (self ) -> None :
124
- """Test non-string build_configuration returns error."""
125
- body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "build_configuration" : 123 })
158
+ def test_provider_too_long (self ) -> None :
159
+ """Test provider field too long returns error."""
160
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "provider" : "a" * 65 })
161
+ result , error = validate_preprod_artifact_schema (body )
162
+ assert error is not None
163
+ assert result == {}
164
+
165
+ def test_head_repo_name_too_long (self ) -> None :
166
+ """Test head_repo_name field too long returns error."""
167
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "head_repo_name" : "a" * 256 })
168
+ result , error = validate_preprod_artifact_schema (body )
169
+ assert error is not None
170
+ assert result == {}
171
+
172
+ def test_pr_number_invalid (self ) -> None :
173
+ """Test invalid pr_number returns error."""
174
+ body = orjson .dumps ({"checksum" : "a" * 40 , "chunks" : [], "pr_number" : 0 })
126
175
result , error = validate_preprod_artifact_schema (body )
127
176
assert error is not None
128
177
assert result == {}
@@ -255,26 +304,6 @@ def test_assemble_json_schema_chunks_invalid_item_type(self) -> None:
255
304
)
256
305
assert response .status_code == 400 , response .content
257
306
258
- def test_assemble_json_schema_git_sha_wrong_type (self ) -> None :
259
- """Test that non-string git_sha is rejected."""
260
- checksum = sha1 (b"1" ).hexdigest ()
261
- response = self .client .post (
262
- self .url ,
263
- data = {"checksum" : checksum , "chunks" : [], "git_sha" : 123 },
264
- HTTP_AUTHORIZATION = f"Bearer { self .token .token } " ,
265
- )
266
- assert response .status_code == 400 , response .content
267
-
268
- def test_assemble_json_schema_git_sha_invalid_format (self ) -> None :
269
- """Test that invalid git_sha format is rejected."""
270
- checksum = sha1 (b"1" ).hexdigest ()
271
- response = self .client .post (
272
- self .url ,
273
- data = {"checksum" : checksum , "chunks" : [], "git_sha" : "invalid_sha" },
274
- HTTP_AUTHORIZATION = f"Bearer { self .token .token } " ,
275
- )
276
- assert response .status_code == 400 , response .content
277
-
278
307
def test_assemble_json_schema_build_configuration_wrong_type (self ) -> None :
279
308
"""Test that non-string build_configuration is rejected."""
280
309
checksum = sha1 (b"1" ).hexdigest ()
@@ -304,8 +333,15 @@ def test_assemble_json_schema_optional_fields(self) -> None:
304
333
data = {
305
334
"checksum" : checksum ,
306
335
"chunks" : [],
307
- "git_sha" : "c076e3b84d9d7c43f456908535ea78b9de6ec59b" ,
308
336
"build_configuration" : "release" ,
337
+ "head_sha" : "e" * 40 ,
338
+ "base_sha" : "f" * 40 ,
339
+ "provider" : "github" ,
340
+ "head_repo_name" : "owner/repo" ,
341
+ "base_repo_name" : "owner/repo" ,
342
+ "head_ref" : "feature/xyz" ,
343
+ "base_ref" : "main" ,
344
+ "pr_number" : 123 ,
309
345
},
310
346
HTTP_AUTHORIZATION = f"Bearer { self .token .token } " ,
311
347
)
@@ -356,6 +392,15 @@ def test_assemble_basic(
356
392
"checksum" : total_checksum ,
357
393
"chunks" : [blob .checksum ],
358
394
"artifact_id" : artifact_id ,
395
+ "build_configuration" : None ,
396
+ "head_sha" : None ,
397
+ "base_sha" : None ,
398
+ "provider" : None ,
399
+ "head_repo_name" : None ,
400
+ "base_repo_name" : None ,
401
+ "head_ref" : None ,
402
+ "base_ref" : None ,
403
+ "pr_number" : None ,
359
404
}
360
405
)
361
406
@@ -382,8 +427,15 @@ def test_assemble_with_metadata(
382
427
data = {
383
428
"checksum" : total_checksum ,
384
429
"chunks" : [blob .checksum ],
385
- "git_sha" : "c076e3b84d9d7c43f456908535ea78b9de6ec59b" ,
386
430
"build_configuration" : "release" ,
431
+ "head_sha" : "e" * 40 ,
432
+ "base_sha" : "f" * 40 ,
433
+ "provider" : "github" ,
434
+ "head_repo_name" : "owner/repo" ,
435
+ "base_repo_name" : "owner/repo" ,
436
+ "head_ref" : "feature/xyz" ,
437
+ "base_ref" : "main" ,
438
+ "pr_number" : 123 ,
387
439
},
388
440
HTTP_AUTHORIZATION = f"Bearer { self .token .token } " ,
389
441
)
@@ -406,6 +458,15 @@ def test_assemble_with_metadata(
406
458
"checksum" : total_checksum ,
407
459
"chunks" : [blob .checksum ],
408
460
"artifact_id" : artifact_id ,
461
+ "build_configuration" : "release" ,
462
+ "head_sha" : "e" * 40 ,
463
+ "base_sha" : "f" * 40 ,
464
+ "provider" : "github" ,
465
+ "head_repo_name" : "owner/repo" ,
466
+ "base_repo_name" : "owner/repo" ,
467
+ "head_ref" : "feature/xyz" ,
468
+ "base_ref" : "main" ,
469
+ "pr_number" : 123 ,
409
470
}
410
471
)
411
472
0 commit comments