2929 from tests .adapters .message_bus import BusSimulator
3030
3131BRANCH_NAME = "branch1"
32+ DELETED_BRANCH_NAME = "deleted_branch"
3233PROPOSED_CHANGE_NAME = "branch1-pc"
3334DIFF_UPDATE_QUERY = """
3435mutation DiffUpdate($branch_name: String!, $wait_for_completion: Boolean = true) {
@@ -195,15 +196,36 @@ async def create_diff(self, db: InfrahubDatabase, initial_dataset, client: Infra
195196 john .age .value = 26 # type: ignore[attr-defined]
196197 await john .save (db = db )
197198
199+ @pytest .fixture (scope = "class" )
200+ async def deleted_branch (self , db : InfrahubDatabase ) -> Branch :
201+ return await create_branch (db = db , branch_name = DELETED_BRANCH_NAME )
202+
203+ @pytest .fixture (scope = "class" )
204+ async def diff_on_deleted_branch (
205+ self , db : InfrahubDatabase , initial_dataset , client : InfrahubClient , deleted_branch : Branch
206+ ) -> EnrichedDiffRoot :
207+ kara = await NodeManager .get_one (db = db , branch = deleted_branch , id = initial_dataset ["kara" ].id )
208+ kara .description .value = "I think she's an angel now"
209+ await kara .save (db = db )
210+
211+ result = await client .execute_graphql (query = DIFF_UPDATE_QUERY , variables = {"branch_name" : DELETED_BRANCH_NAME })
212+ assert result ["DiffUpdate" ]["ok" ]
213+
214+ diff = await self .get_branch_diff (db = db , branch = deleted_branch )
215+ assert len (diff .nodes ) == 1
216+
217+ await deleted_branch .delete (db = db )
218+ return diff
219+
198220 @staticmethod
199221 async def get_branch_diff (db : InfrahubDatabase , branch : Branch ) -> EnrichedDiffRoot :
200222 # Validate if the diff has been updated properly
201223 component_registry = get_component_registry ()
202224 diff_repo = await component_registry .get_component (DiffRepository , db = db , branch = branch )
203225
204226 return await diff_repo .get_one (
205- tracking_id = BranchTrackingId (name = BRANCH_NAME ),
206- diff_branch_name = BRANCH_NAME ,
227+ tracking_id = BranchTrackingId (name = branch . name ),
228+ diff_branch_name = branch . name ,
207229 )
208230
209231 async def _get_proposed_change_and_data_validator (self , db ) -> tuple [Node , Node ]:
@@ -222,7 +244,7 @@ async def _get_proposed_change_and_data_validator(self, db) -> tuple[Node, Node]
222244 return (pc , data_validator )
223245
224246 async def test_diff_first_update (
225- self , db : InfrahubDatabase , initial_dataset , create_diff , client : InfrahubClient
247+ self , db : InfrahubDatabase , initial_dataset , create_diff , diff_on_deleted_branch , client : InfrahubClient
226248 ) -> None :
227249 """Validate if the diff is properly created the first time"""
228250
@@ -1147,7 +1169,13 @@ async def test_create_another_proposed_change_data_checks_created(
11471169 assert len (core_data_checks ) == len (data_checks_by_conflict_id )
11481170
11491171 async def test_merge_proposed_change (
1150- self , db : InfrahubDatabase , initial_dataset , default_branch , client : InfrahubClient
1172+ self ,
1173+ db : InfrahubDatabase ,
1174+ initial_dataset ,
1175+ default_branch ,
1176+ diff_on_deleted_branch : EnrichedDiffRoot ,
1177+ deleted_branch : Branch ,
1178+ client : InfrahubClient ,
11511179 ) -> None :
11521180 pc , _ = await self ._get_proposed_change_and_data_validator (db = db )
11531181 result = await client .execute_graphql (
@@ -1224,3 +1252,7 @@ async def test_merge_proposed_change(
12241252 murphy_customer_rel = omnicorp_customers_rels_by_peer_id [murphy_id ]
12251253 owner_of_property = await murphy_customer_rel .get_owner (db = db )
12261254 assert owner_of_property .get_id () == cardinality_many_property_conflict .expected_value
1255+
1256+ # validate diff not updated for deleted branch
1257+ fresh_deleted_branch_diff = await self .get_branch_diff (db = db , branch = deleted_branch )
1258+ assert fresh_deleted_branch_diff .to_time == diff_on_deleted_branch .to_time
0 commit comments