Skip to content

Commit

Permalink
test: validate core SIMOS package
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Nov 14, 2023
1 parent acb81ae commit 8668212
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 51 deletions.
3 changes: 2 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def add_process_time_header(request: Request, call_next: Callable) -> Resp
response = await call_next(request)
process_time = time.time() - start_time
milliseconds = int(round(process_time * 1000))
logger.debug(f"{request.method} {request.url.path} - {milliseconds}ms - {response.status_code}")
logger.info(f"{request.method} {request.url.path} - {milliseconds}ms - {response.status_code}")
response.headers["X-Process-Time"] = str(process_time)
return response

Expand Down Expand Up @@ -150,6 +150,7 @@ def run():
"app:create_app",
host="0.0.0.0", # noqa: S104
port=5000,
access_log=False,
reload=config.ENVIRONMENT == "local",
log_level=config.LOGGER_LEVEL.lower(),
)
Expand Down
25 changes: 18 additions & 7 deletions src/common/entity/validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections.abc import Callable
from typing import Any, Literal

from common.exceptions import ValidationException
from common.exceptions import ApplicationException, ValidationException
from common.utils.logging import logger
from domain_classes.blueprint import Blueprint
from domain_classes.blueprint_attribute import BlueprintAttribute
from enums import SIMOS, BuiltinDataTypes
Expand All @@ -26,13 +27,17 @@ def is_blueprint_instance_of(
the blueprint extends a blueprint that fulfills one of these three rules
Otherwise it returns false.
"""
if minimum_blueprint_type == BuiltinDataTypes.OBJECT.value:
return True
if minimum_blueprint_type == blueprint_type:
return True
for inherited_type in get_blueprint(blueprint_type).extends:
if is_blueprint_instance_of(minimum_blueprint_type, inherited_type, get_blueprint):
try:
if minimum_blueprint_type == BuiltinDataTypes.OBJECT.value:
return True
if minimum_blueprint_type == blueprint_type:
return True
for inherited_type in get_blueprint(blueprint_type).extends:
if is_blueprint_instance_of(minimum_blueprint_type, inherited_type, get_blueprint):
return True
except ApplicationException as ex:
logger.warn(ex)
return False
return False


Expand Down Expand Up @@ -105,6 +110,12 @@ def _validate_entity(
implementation_mode: Literal["exact", "extend", "minimum"],
key: str,
) -> None:
if not entity.get("type"):
raise ValidationException(
'Entity is missing required attribute "type"',
debug=_get_debug_message(key),
data=entity,
)
if implementation_mode == "extend":
if entity["type"] != SIMOS.REFERENCE.value:
if not is_blueprint_instance_of(blueprint.path, entity["type"], get_blueprint):
Expand Down
16 changes: 6 additions & 10 deletions src/home/system/SIMOS/Blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
"contained": true,
"optional": true
},
{
"name": "abstract",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "boolean",
"default": false,
"optional": true
},
{
"name": "name",
"type": "dmss://system/SIMOS/BlueprintAttribute",
Expand Down Expand Up @@ -54,15 +47,18 @@
"default": [
{
"name": "name",
"type": "string"
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "type",
"type": "string"
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "description",
"type": "string"
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
}
],
"contained": true,
Expand Down
3 changes: 2 additions & 1 deletion src/home/system/SIMOS/Meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"name": "dependencies",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "dmss://system/SIMOS/Dependency",
"dimensions": "*"
"dimensions": "*",
"optional": true
},
{
"name": "version",
Expand Down
8 changes: 8 additions & 0 deletions src/home/system/SIMOS/RecipeLink.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
"contained": true,
"optional": false
},
{
"name": "extends",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string",
"default": [],
"optional": true,
"dimensions": "*"
},
{
"name": "initialUiRecipe",
"type": "dmss://system/SIMOS/BlueprintAttribute",
Expand Down
8 changes: 8 additions & 0 deletions src/home/system/SIMOS/StorageAttribute.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
"attributeType": "string",
"default": "",
"optional": true
},
{
"name": "dimensions",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"description": "dimensions",
"attributeType": "string",
"default": "",
"optional": true
}
]
}
2 changes: 1 addition & 1 deletion src/home/system/SIMOS/ViewConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "boolean",
"optional": true,
"default": "true"
"default": true
},
{
"name": "label",
Expand Down
11 changes: 1 addition & 10 deletions src/home/system/SIMOS/recipe_links/entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
"name": "DEFAULT_CREATE",
"type": "dmss://system/SIMOS/UiRecipe",
"description": "",
"plugin": "@development-framework/dm-core-plugins/form",
"attributes": [
{
"name": "type",
"type": "dmss://system/SIMOS/UiAttribute",
"attributeType": "string",
"field": "blueprint",
"label": "Type"
}
]
"plugin": "@development-framework/dm-core-plugins/form"
}
]
}
19 changes: 1 addition & 18 deletions src/home/system/SIMOS/recipe_links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@
"name": "DEFAULT_CREATE",
"type": "dmss://system/SIMOS/UiRecipe",
"description": "",
"plugin": "@development-framework/dm-core-plugins/form",
"attributes": [
{
"name": "isRoot",
"type": "dmss://system/SIMOS/UiAttribute",
"contained": false
},
{
"name": "type",
"type": "dmss://system/SIMOS/UiAttribute",
"contained": false
},
{
"name": "content",
"type": "dmss://system/SIMOS/UiAttribute",
"contained": false
}
]
"plugin": "@development-framework/dm-core-plugins/form"
}
]
}
3 changes: 1 addition & 2 deletions src/home/system/SIMOS/recipe_links/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"name": "PDFView",
"type": "dmss://system/SIMOS/UiRecipe",
"description": "Embedded PDF View",
"plugin": "'@development-framework/dm-core-plugins/pdf",
"attributes": []
"plugin": "'@development-framework/dm-core-plugins/pdf"
}
]
}
2 changes: 1 addition & 1 deletion src/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "$1" = 'api' ]; then

if [ "${ENVIRONMENT:-'local'}" != "local" ]; then
cat version.txt || true
gunicorn app:create_app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:5000
gunicorn app:create_app --workers 4 --disable-redirect-access-to-syslog --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:5000
else
python3 /code/src/app.py run
fi
Expand Down
12 changes: 12 additions & 0 deletions src/tests/bdd/entity/validate_SIMOS.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Validate entities in database

Background: There are data sources in the system
Given the system data source and SIMOS core package are available


Scenario: Validate existing SIMOS CORE
Given i access the resource url "/api/entity/validate-existing-entity/system/SIMOS/"
When i make a "POST" request
Then the response status should be "OK"


0 comments on commit 8668212

Please sign in to comment.