Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/create entity use default on optional #694

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pygments = "^2.16.1"
pytest = "^7.4.3"
dictdiffer = "^0.9.0"
setuptools = "^68.2.2"
icecream = "^2.1.3"

[tool.pytest]
addopts = ["--ignore gen"]
Expand Down
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
7 changes: 6 additions & 1 deletion src/tests/bdd/entity/instantiate_entity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ Feature: Instantiate entity
"type": "dmss://system/SIMOS/Reference",
"referenceType": "link"
}
]
],
"bestFriendAtWork": {
"type": "dmss://data-source-name/root_package/Employee",
"name": "Kari",
"isManager": false
}
}
"""
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