99from  uuid  import  uuid4 
1010
1111import  pytest 
12+ from  infrahub_sdk .context  import  ContextAccount , RequestContext 
1213from  infrahub_sdk .exceptions  import  GraphQLError 
1314from  infrahub_sdk .protocols  import  CoreDataCheck , CoreProposedChange 
1415
1516from  infrahub .core .constants  import  InfrahubKind , ValidatorConclusion 
16- from  infrahub .core .initialization  import  create_branch 
17+ from  infrahub .core .initialization  import  create_account ,  create_branch 
1718from  infrahub .core .manager  import  NodeManager 
1819from  infrahub .core .merge  import  BranchMerger 
1920from  infrahub .core .node  import  Node 
@@ -203,11 +204,14 @@ async def test_conflict_pipeline(
203204        assert  john .description .value  ==  "Oh boy"   # type: ignore[attr-defined] 
204205
205206    async  def  test_happy_pipeline (self , db : InfrahubDatabase , happy_data_branch : str , client : InfrahubClient ) ->  None :
207+         proposed_change_user  =  await  create_account (db = db , name = "jimmy-change-user" , password = "Password123" )
206208        proposed_change_create  =  await  client .create (
207209            kind = CoreProposedChange ,
208210            data = {"source_branch" : happy_data_branch , "destination_branch" : "main" , "name" : "happy-test" },
209211        )
210-         await  proposed_change_create .save ()
212+         await  proposed_change_create .save (
213+             request_context = RequestContext (account = ContextAccount (id = proposed_change_user .id ))
214+         )
211215
212216        # ------------------------------------------------- 
213217        # Ensure that all validators have been executed and aren't reporting errors 
@@ -292,6 +296,7 @@ async def test_happy_pipeline(self, db: InfrahubDatabase, happy_data_branch: str
292296        assert  artifact_events ["InfrahubEvent" ]["count" ] >  0 
293297        latest_artifact_event  =  artifact_events ["InfrahubEvent" ]["edges" ][0 ]["node" ]
294298        assert  sorted (latest_artifact_event .keys ()) ==  [
299+             "account_id" ,
295300            "artifact_definition_id" ,
296301            "branch" ,
297302            "checksum" ,
@@ -348,6 +353,14 @@ async def test_happy_pipeline(self, db: InfrahubDatabase, happy_data_branch: str
348353            "CoreUserValidator" ,
349354        ]
350355
356+         pr_account_events  =  await  client .execute_graphql (
357+             query = QUERY_EVENT ,
358+             variables = {"account__ids" : [proposed_change_user .id ]},
359+         )
360+         pr_account_events_types  =  {event ["node" ]["event" ] for  event  in  pr_account_events ["InfrahubEvent" ]["edges" ]}
361+         assert  "infrahub.validator.passed"  in  pr_account_events_types 
362+         assert  "infrahub.artifact.updated"  in  pr_account_events_types 
363+ 
351364    async  def  test_merge_failure (
352365        self ,
353366        db : InfrahubDatabase ,
@@ -389,6 +402,7 @@ async def test_connectivity(self, db: InfrahubDatabase, initial_dataset: str, cl
389402    $branch: [String!], 
390403    $parent__ids: [String!], 
391404    $event_type: [String!] 
405+     $account__ids: [String!], 
392406    $related_node__ids: [String!], 
393407    $event_type_filter: EventTypeFilter 
394408) { 
@@ -397,6 +411,7 @@ async def test_connectivity(self, db: InfrahubDatabase, initial_dataset: str, cl
397411    parent__ids: $parent__ids 
398412    event_type: $event_type 
399413    event_type_filter: $event_type_filter 
414+     account__ids: $account__ids 
400415    related_node__ids: $related_node__ids 
401416  ) { 
402417    count 
@@ -409,6 +424,7 @@ async def test_connectivity(self, db: InfrahubDatabase, initial_dataset: str, cl
409424        parent_id 
410425        level 
411426        occurred_at 
427+         account_id 
412428        primary_node { 
413429          id 
414430          kind 
@@ -425,6 +441,14 @@ async def test_connectivity(self, db: InfrahubDatabase, initial_dataset: str, cl
425441          checksum_previous 
426442          checksum 
427443        } 
444+        ... on NodeMutatedEvent { 
445+           id 
446+           attributes { 
447+             name 
448+             value 
449+             value_previous 
450+           } 
451+         } 
428452      } 
429453    } 
430454  } 
0 commit comments