Skip to content

Commit

Permalink
fix: CreateEntity will now correctly use default, even on optional
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Nov 14, 2023
1 parent 8668212 commit a3adfe9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _get_entity(self, blueprint: Blueprint, entity: dict):
for attr in blueprint.attributes:
if attr.attribute_type == BuiltinDataTypes.BINARY.value:
continue
if attr.is_optional:
if attr.is_optional and not attr.default:
# skip attribute if it is optional
continue
if attr.attribute_type in PRIMITIVES:
Expand Down
6 changes: 4 additions & 2 deletions src/home/system/SIMOS/Blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
{
"name": "name",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
"attributeType": "string",
"optional": true
},
{
"name": "type",
Expand All @@ -58,7 +59,8 @@
{
"name": "description",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
"attributeType": "string",
"optional": true
}
],
"contained": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setUp(self):
"dmss://system/SIMOS/BlueprintAttribute",
"dmss://system/SIMOS/Entity",
"dmss://system/SIMOS/NamedEntity",
"dmss://system/SIMOS/Blueprint",
]
mock_blueprint_folder = "src/tests/unit/use_cases/instantiate_entity_use_case/mock_data/"
mock_blueprints_and_file_names = {
Expand Down Expand Up @@ -55,10 +56,43 @@ def test_blueprint_entity(self):
"intValues": [1, 5, 4, 2],
"boolValues": [True, False, True],
"stringValues": ["one", "two", "three"],
"engine3": {
"name": "default engine",
"type": "EngineTest",
"fuelPump": {"name": "fuelPump", "type": "FuelPumpTest", "description": "A standard fuel pump"},
"power": 9,
},
}

entity = CreateEntity(blueprint_provider=self.mock_document_service.get_blueprint, type="CarTest").entity

self.assertDictEqual(expected_entity, entity)

def test_create_default_blueprint(self):
expected_entity = {
"type": "dmss://system/SIMOS/Blueprint",
"name": "",
"attributes": [
{
"name": "name",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string",
"optional": True,
},
{"name": "type", "type": "dmss://system/SIMOS/BlueprintAttribute", "attributeType": "string"},
{
"name": "description",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string",
"optional": True,
},
],
}

entity = CreateEntity(
blueprint_provider=self.mock_document_service.get_blueprint, type="dmss://system/SIMOS/Blueprint"
).entity

self.assertEqual(expected_entity, entity)

def test_is_not_json(self):
Expand Down

0 comments on commit a3adfe9

Please sign in to comment.