Skip to content

Commit

Permalink
fix: remove item from required list attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Oct 5, 2023
1 parent fafa326 commit 91c774b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/common/tree/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def type(self):
def type(self, value): # Type can be changed after initiation. e.g Multiple valid specialised types
self._type = value

@property
def is_optional(self):
if not self.parent:
return True
if self.parent.is_array():
return True
return self.attribute.is_optional

@property
def blueprint(self) -> Blueprint:
if self.type == BuiltinDataTypes.OBJECT.value:
Expand Down
2 changes: 1 addition & 1 deletion src/home/system/SIMOS/Package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"attributeType": "object",
"contained": true,
"dimensions": "*",
"optional": true
"optional": false
}
]
}
2 changes: 1 addition & 1 deletion src/services/document_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def get_document(self, address: Address, depth: int = 0) -> Node | ListNode:

def remove(self, address: Address) -> None:
node = self.get_document(address)
if node.parent and not node.attribute.is_optional:
if node.parent and not node.is_optional:
raise ValidationException("Tried to remove a required attribute")

data_source = self.repository_provider(address.data_source, self.user)
Expand Down
8 changes: 8 additions & 0 deletions src/tests/bdd/document/remove_2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ Feature: Explorer - Remove by path
}
"""

Scenario: Remove item from list
Given i access the resource url "/api/documents/data-source-name/blueprints.content[1]"
When i make a "DELETE" request
Then the response status should be "OK"
Given I access the resource url "/api/documents/data-source-name/$4"
When I make a "GET" request
Then the response status should be "Not Found"

Scenario: Remove file with children
Given i access the resource url "/api/documents/data-source-name/blueprints/sub_package_1"
When i make a "DELETE" request
Expand Down
2 changes: 1 addition & 1 deletion src/tests/unit/common/utils/test_create_default_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_creation_of_default_array_complex_type(self):
empty_string_blueprint_attribute,
)

assert default_array == [[{"name": "", "type": "dmss://system/SIMOS/Package", "isRoot": False}]]
assert default_array == [[{"name": "", "type": "dmss://system/SIMOS/Package", "isRoot": False, "content": []}]]

def test_creation_of_default_array_unfixed_rank2(self):
default_array = create_default_array(Dimension("*,*", "integer"), blueprint_provider, CreateEntity)
Expand Down
3 changes: 0 additions & 3 deletions src/tests/unit/use_cases/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ def mock_update(entity: dict, *args, **kwargs):
repository.get = lambda x: doc_storage[str(x)]
repository.update = mock_update
self.document_service.repository_provider = lambda x, y: repository
self.assertRaises(
ValidationException, self.document_service.remove, Address("$1.uncontained_in_every_way[0]", "testing")
)

def test_add_reference_in_list(self):
repository = mock.Mock()
Expand Down

0 comments on commit 91c774b

Please sign in to comment.