Skip to content

Commit

Permalink
[DISCO-2325] Create JSON Schema Validation for Control Mechanism (#93)
Browse files Browse the repository at this point in the history
schema allocation file, gitignore adjustments, rename of original schema

Closes #93
  • Loading branch information
taddes committed Apr 21, 2023
1 parent 01e5f18 commit 9136f97
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ dmypy.json

# Pyre type checker
.pyre/

# DS_Store files for macOS
**/.DS_Store

# VS Code configuration files
.vscode/*
!.vscode/launch.json
2 changes: 1 addition & 1 deletion consvc_shepherd/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def publish_snapshot(modeladmin, request, queryset):
snapshot.launched_by = request.user
snapshot.launched_date = timezone.now()
content = json.dumps(snapshot.json_settings, indent=2)
with open("./schema/shepherd.schema.json", "r") as f:
with open("./schema/adm_filter.schema.json", "r") as f:
settings_schema = json.load(f)
try:
validate(snapshot.json_settings, schema=settings_schema)
Expand Down
2 changes: 1 addition & 1 deletion consvc_shepherd/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
self.request = request_factory.get("/admin")
self.request.user = UserFactory()

with open("./schema/shepherd.schema.json", "r") as f:
with open("./schema/adm_filter.schema.json", "r") as f:
self.settings_schema = json.load(f)

site = AdminSite()
Expand Down
File renamed without changes.
56 changes: 56 additions & 0 deletions schema/allocation.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Shepherd Partner Allocation",
"description": "The schema for Allocation Configuration of Partners for Shepherd.",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"pattern": "^(SOV-)([0-9]{4})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])(2[0-3]|[01][0-9])([0-5][0-9])([0-5][0-9])$",
"description": "Allocation Update Title Label. SOV-<UTC datetime:YYYYMMDDHHMMSS>",
"type": "string"
},
"allocations": {
"type": "array",
"description": "Allocations distributing partner percentages for each tile, left to right.",
"uniqueItems": true,
"minItems": 2,
"items": [
{
"type": "object",
"properties": {
"position": {
"type": "integer",
"description": "0-based position of tile from left side, 0 for the first slot."
},
"allocation": {
"type": "object",
"properties": {
"adm": {
"type": "integer",
"description": "adM percentage of allocation 0 - 100."
},
"kevel": {
"type": "integer",
"description": "Kevel percentage of allocation 0 - 100."
}
},
"required": [
"adm",
"kevel"
]
}
},
"required": [
"position",
"allocation"
]
}
],
"required": [
"name",
"allocations"
]
}
}
}
2 changes: 1 addition & 1 deletion schema/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class JSONSchema(TestCase):

def test_schema(self):

with open("./schema/shepherd.schema.json", "r") as f:
with open("./schema/adm_filter.schema.json", "r") as f:
settings_schema = json.load(f)
partner = Partner.objects.create(
name="Partner Advertiser",
Expand Down

0 comments on commit 9136f97

Please sign in to comment.