Skip to content

Commit f103cdc

Browse files
committed
Fix regression with Node update
1 parent 0889718 commit f103cdc

File tree

3 files changed

+26
-46
lines changed

3 files changed

+26
-46
lines changed

infrahub_sdk/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ def _strip_unmodified_dict(data: dict, original_data: dict, variables: dict, ite
904904
variables.pop(variable_key)
905905

906906
# TODO: I do not feel _great_ about this
907-
if not data_item and data_item != []:
907+
if not data_item and data_item != [] and item in data:
908908
data.pop(item)
909909

910910
def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:

infrahub_sdk/testing/schemas/car_person.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ async def person_joe(self, client: InfrahubClient, person_joe_data: TestingPerso
170170
await obj.save()
171171
return obj
172172

173+
@pytest.fixture(scope="class")
174+
async def person_jane(self, client: InfrahubClient, person_jane_data: TestingPersonData) -> InfrahubNode:
175+
obj = await client.create(**asdict(person_jane_data))
176+
await obj.save()
177+
return obj
178+
173179
@pytest.fixture(scope="class")
174180
async def manufacturer_mercedes(
175181
self, client: InfrahubClient, manufacturer_mercedes_data: TestingManufacturerData
@@ -202,6 +208,12 @@ async def tag_red(self, client: InfrahubClient) -> InfrahubNode:
202208
await obj.save()
203209
return obj
204210

211+
@pytest.fixture(scope="class")
212+
async def tag_green(self, client: InfrahubClient) -> InfrahubNode:
213+
obj = await client.create(kind=BUILTIN_TAG, name="Green")
214+
await obj.save()
215+
return obj
216+
205217
async def create_persons(self, client: InfrahubClient, branch: str) -> list[InfrahubNode]:
206218
john = await client.create(kind=TESTING_PERSON, name="John Doe", branch=branch)
207219
await john.save()

tests/integration/test_node.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,31 @@ async def test_node_update(
143143
initial_schema: None,
144144
manufacturer_mercedes,
145145
person_joe,
146+
person_jane,
146147
car_golf,
147148
tag_blue,
148149
tag_red,
150+
tag_green,
149151
):
150152
car_golf.color.value = "White"
151153
await car_golf.tags.fetch()
152154
car_golf.tags.add(tag_blue.id)
153155
car_golf.tags.add(tag_red.id)
154156
await car_golf.save()
155157

156-
node_after = await client.get(kind=TESTING_CAR, id=car_golf.id)
157-
assert node_after.color.value == "White"
158-
await node_after.tags.fetch()
159-
assert len(node_after.tags.peers) == 2
158+
car2 = await client.get(kind=TESTING_CAR, id=car_golf.id)
159+
assert car2.color.value == "White"
160+
await car2.tags.fetch()
161+
assert len(car2.tags.peers) == 2
160162

161-
# async def test_node_update_2(
162-
# self,
163-
# db: InfrahubDatabase,
164-
# client: InfrahubClient,
165-
# init_db_base,
166-
# load_builtin_schema,
167-
# tag_green: Node,
168-
# tag_red: Node,
169-
# tag_blue: Node,
170-
# gqlquery02: Node,
171-
# repo99: Node,
172-
# ):
173-
# node = await client.get(kind="CoreGraphQLQuery", name__value="query02")
174-
# assert node.id is not None
163+
car2.owner = person_jane.id
164+
car2.tags.add(tag_green.id)
165+
car2.tags.remove(tag_red.id)
166+
await car2.save()
175167

176-
# node.name.value = "query021"
177-
# node.repository = repo99.id
178-
# node.tags.add(tag_green.id)
179-
# node.tags.remove(tag_red.id)
180-
# await node.save()
181-
182-
# nodedb = await NodeManager.get_one(id=node.id, db=db, include_owner=True, include_source=True)
183-
# repodb = await nodedb.repository.get_peer(db=db)
184-
# assert repodb.id == repo99.id
185-
186-
# tags = await nodedb.tags.get(db=db)
187-
# assert sorted([tag.peer_id for tag in tags]) == sorted([tag_green.id, tag_blue.id])
168+
car3 = await client.get(kind=TESTING_CAR, id=car_golf.id)
169+
await car3.tags.fetch()
170+
assert sorted([tag.id for tag in car3.tags.peers]) == sorted([tag_green.id, tag_blue.id])
188171

189172
# async def test_node_update_3_idempotency(
190173
# self,
@@ -222,21 +205,6 @@ async def test_node_update(
222205
# assert "query" not in second_update["data"]["data"]
223206
# assert not second_update["variables"]
224207

225-
# async def test_convert_node(
226-
# self,
227-
# db: InfrahubDatabase,
228-
# client: InfrahubClient,
229-
# location_schema,
230-
# init_db_base,
231-
# load_builtin_schema,
232-
# location_cdg: Node,
233-
# ):
234-
# data = await location_cdg.to_graphql(db=db)
235-
# node = InfrahubNode(client=client, schema=location_schema, data=data)
236-
237-
# # pylint: disable=no-member
238-
# assert node.name.value == "cdg01"
239-
240208
# async def test_relationship_manager_errors_without_fetch(self, client: InfrahubClient, load_builtin_schema):
241209
# organization = await client.create("TestOrganization", name="organization-1")
242210
# await organization.save()

0 commit comments

Comments
 (0)