-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for hierarchy in RelationshipManager
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
backend/tests/unit/core/hierarchy/test_hierarchy_create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
|
||
from infrahub.core import registry | ||
from infrahub.core.manager import NodeManager | ||
from infrahub.core.node import Node | ||
from infrahub.database import InfrahubDatabase | ||
from infrahub.exceptions import ValidationError | ||
|
||
|
||
async def test_create_node_with_invalid_hierarchy(db: InfrahubDatabase, hierarchical_location_data): | ||
region_schema = registry.schema.get_node_schema(name="LocationRegion", duplicate=True) | ||
rack_schema = registry.schema.get_node_schema(name="LocationRack", duplicate=True) | ||
europe = await NodeManager.get_one(db=db, id=hierarchical_location_data["europe"].id) | ||
city = await NodeManager.get_one(db=db, id=hierarchical_location_data["seattle"].id) | ||
|
||
with pytest.raises(ValidationError) as exc: | ||
region = await Node.init(db=db, schema=region_schema) | ||
await region.new(db=db, name="region2", parent=city) | ||
assert "Not supported to assign a value to parent" in str(exc.value) | ||
|
||
with pytest.raises(ValidationError) as exc: | ||
rack = await Node.init(db=db, schema=rack_schema) | ||
await rack.new(db=db, name="rack2", parent=city, children=[europe]) | ||
assert "Not supported to assign some children" in str(exc.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hierarchical node that don't have a parent or a children defined in the schema will properly enforce that constraint |