Skip to content

Commit 96c4fe1

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

File tree

5 files changed

+300
-78
lines changed

5 files changed

+300
-78
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()

tests/unit/sdk/conftest.py

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,47 @@ async def location_data02_no_pagination():
373373

374374
@pytest.fixture
375375
async def location_data01():
376+
data = {
377+
"node": {
378+
"__typename": "BuiltinLocation",
379+
"id": "llllllll-llll-llll-llll-llllllllllll",
380+
"display_label": "dfw1",
381+
"name": {
382+
"value": "DFW",
383+
},
384+
"description": {
385+
"value": None,
386+
},
387+
"type": {
388+
"value": "SITE",
389+
},
390+
"primary_tag": {
391+
"node": {
392+
"id": "rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr",
393+
"display_label": "red",
394+
"__typename": "BuiltinTag",
395+
},
396+
},
397+
"tags": {
398+
"count": 1,
399+
"edges": [
400+
{
401+
"node": {
402+
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
403+
"display_label": "blue",
404+
"__typename": "BuiltinTag",
405+
},
406+
}
407+
],
408+
},
409+
}
410+
}
411+
412+
return data
413+
414+
415+
@pytest.fixture
416+
async def location_data01_property():
376417
data = {
377418
"node": {
378419
"__typename": "BuiltinLocation",
@@ -435,9 +476,49 @@ async def location_data01():
435476

436477
return data
437478

438-
439479
@pytest.fixture
440480
async def location_data02():
481+
data = {
482+
"node": {
483+
"__typename": "BuiltinLocation",
484+
"id": "llllllll-llll-llll-llll-llllllllllll",
485+
"display_label": "dfw1",
486+
"name": {
487+
"value": "dfw1",
488+
},
489+
"description": {
490+
"value": None,
491+
},
492+
"type": {
493+
"value": "SITE",
494+
},
495+
"primary_tag": {
496+
"node": {
497+
"id": "rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr",
498+
"display_label": "red",
499+
"__typename": "BuiltinTag",
500+
},
501+
},
502+
"tags": {
503+
"count": 1,
504+
"edges": [
505+
{
506+
"node": {
507+
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
508+
"display_label": "blue",
509+
"__typename": "BuiltinTag",
510+
},
511+
}
512+
],
513+
},
514+
}
515+
}
516+
517+
return data
518+
519+
520+
@pytest.fixture
521+
async def location_data02_property():
441522
data = {
442523
"node": {
443524
"__typename": "BuiltinLocation",
@@ -517,6 +598,31 @@ async def location_data02():
517598
return data
518599

519600

601+
602+
603+
604+
@pytest.fixture
605+
async def rfile_userdata01():
606+
return {
607+
"name": {"value": "rfile01"},
608+
"template_path": {"value": "mytemplate.j2"},
609+
"query": {"id": "qqqqqqqq"},
610+
"repository": {"id": "rrrrrrrr"},
611+
"tags": [{"id": "t1t1t1t1"}, "t2t2t2t2"],
612+
}
613+
614+
615+
@pytest.fixture
616+
async def rfile_userdata01_property():
617+
return {
618+
"name": {"value": "rfile01", "is_protected": True, "source": "ffffffff"},
619+
"template_path": {"value": "mytemplate.j2"},
620+
"query": {"id": "qqqqqqqq", "source": "ffffffff", "owner": "ffffffff", "is_protected": True},
621+
"repository": {"id": "rrrrrrrr", "source": "ffffffff", "owner": "ffffffff"},
622+
"tags": [{"id": "t1t1t1t1"}, "t2t2t2t2"],
623+
}
624+
625+
520626
@pytest.fixture
521627
async def tag_schema() -> NodeSchemaAPI:
522628
data = {

0 commit comments

Comments
 (0)