Skip to content

Commit

Permalink
Validate GitHub API info
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Jul 14, 2021
1 parent c76dd61 commit 4217eee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion conbench/entities/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ class SummarySerializer:
many = _Serializer(many=True)


class GitHubCreate(marshmallow.Schema):
commit = marshmallow.fields.String(required=True)
repository = marshmallow.fields.String(required=True)


class _BenchmarkFacadeSchemaCreate(marshmallow.Schema):
run_id = marshmallow.fields.String(required=True)
run_name = marshmallow.fields.String(required=False)
Expand All @@ -228,7 +233,7 @@ class _BenchmarkFacadeSchemaCreate(marshmallow.Schema):
stats = marshmallow.fields.Nested(SummarySchema().create, required=True)
tags = marshmallow.fields.Dict(required=True)
context = marshmallow.fields.Dict(required=True)
github = marshmallow.fields.Dict(required=True)
github = marshmallow.fields.Nested(GitHubCreate(), required=True)


class BenchmarkFacadeSchema:
Expand Down
10 changes: 9 additions & 1 deletion conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@
"properties": {
"batch_id": {"type": "string"},
"context": {"type": "object"},
"github": {"type": "object"},
"github": {"$ref": "#/components/schemas/GitHubCreate"},
"machine_info": {"$ref": "#/components/schemas/MachineCreate"},
"run_id": {"type": "string"},
"run_name": {"type": "string"},
Expand Down Expand Up @@ -755,6 +755,14 @@
},
"type": "object",
},
"GitHubCreate": {
"properties": {
"commit": {"type": "string"},
"repository": {"type": "string"},
},
"required": ["commit", "repository"],
"type": "object",
},
"Login": {
"properties": {
"email": {"format": "email", "type": "string"},
Expand Down
6 changes: 6 additions & 0 deletions conbench/tests/api/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,18 @@ def test_nested_schema_validation(self, client):
self.authenticate(client)
data = copy.deepcopy(self.valid_payload)
del data["stats"]["iterations"]
del data["github"]["commit"]
del data["machine_info"]["os_name"]
data["machine_info"]["os_version"] = None
data["stats"]["extra"] = "field"
data["github"]["extra"] = "field"
data["machine_info"]["extra"] = "field"
response = client.post("/api/benchmarks/", json=data)
message = {
"github": {
"extra": ["Unknown field."],
"commit": ["Missing data for required field."],
},
"machine_info": {
"extra": ["Unknown field."],
"os_name": ["Missing data for required field."],
Expand Down

0 comments on commit 4217eee

Please sign in to comment.