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

clean up some diff-related tests #4793

Merged
merged 3 commits into from
Oct 31, 2024
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
15 changes: 9 additions & 6 deletions backend/infrahub/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,15 @@ async def _update(self, db: InfrahubDatabase, at: Optional[Timestamp] = None) ->
self.validate(value=self.value, name=self.name, schema=self.schema)

# Check if the current value is still the default one
if (
self.is_default
and (self.schema.default_value is not None and self.schema.default_value != self.value)
or (self.schema.default_value is None and self.value is not None)
):
self.is_default = False
if self.is_default:
if isinstance(self.value, Enum):
has_default_value = self.schema.default_value == self.value.value
else:
has_default_value = self.schema.default_value == self.value
if (self.schema.default_value is not None and not has_default_value) or (
self.schema.default_value is None and self.value is not None
):
self.is_default = False

query = await NodeListGetAttributeQuery.init(
db=db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from infrahub.core.initialization import (
create_branch,
)
from infrahub.core.manager import NodeManager
from infrahub.core.node import Node
from infrahub.database import InfrahubDatabase
from infrahub.exceptions import InitializationError, SchemaNotFoundError
Expand Down Expand Up @@ -364,6 +365,29 @@ async def test_step04_load(self, db: InfrahubDatabase, client: InfrahubClient, i
# FIXME after loading the new schema, TestingTag is still present in the branch, need to investigate
# assert registry.schema.has(name=TAG_KIND, branch=self.branch1) is False

# check that tag attributes/relationships are deleted on branch
attr_schemas = await NodeManager.query(
db=db, branch=self.branch1, schema="SchemaAttribute", filters={"node__id": tag_schema.id}
)
assert len(attr_schemas) == 0
rel_schemas = await NodeManager.query(
db=db, branch=self.branch1, schema="SchemaRelationship", filters={"node__id": tag_schema.id}
)
assert len(rel_schemas) == 0
# check that tag attributes/relationships still exist on main
attr_schemas = await NodeManager.query(db=db, schema="SchemaAttribute", filters={"node__id": tag_schema.id})
assert len(attr_schemas) == 1
assert {a.name.value for a in attr_schemas} == {"name"}
rel_schemas = await NodeManager.query(db=db, schema="SchemaRelationship", filters={"node__id": tag_schema.id})
assert len(rel_schemas) == 5
assert {r.name.value for r in rel_schemas} == {
"cars",
"persons",
"profiles",
"subscriber_of_groups",
"member_of_groups",
}

tags = await registry.manager.query(db=db, schema=TAG_KIND)
assert len(tags) == 2

Expand Down
Loading
Loading