
    ZTh*                     x    d Z ddlZddlZddlmZmZmZ ddlmZ d Ze	dk(  r ej                   e              yy)zThis test demonstrates the usage of the Runs API.

It creates a new run, updates it, and associates assets with it.
It also lists runs, filters them, and deletes the run.

It uses the SiftClient to interact with the API.
    N)datetime	timedeltatimezone)
SiftClientc                    K   t        j                  dd      } t        j                  dd      }t        j                  dd      }t        || |      }|j                  j	                  d	      }|j
                  }t        d
|j                   d| d       |j                  }t        dt        |       d|D cg c]  }|j                   c} d|j                   d| d	       |d   }|j
                  }t        d|j                   d| d       |j                  }	|	D cg c]  }|j
                  |k7  s| }
}t        dt        |
       d|
 d|j                   d| d	       t        d       |j                  j                  d      }t        dt        |       d       |D ]4  }t        d|j                   d|j
                   d|j                          6 t        d       |j                  j                  d      }|st        d       y|d   }t        d       |j                  }|j                  j                  |d       }t        dt        |       d!| d"       |D ](  }t        d|j                   d|j
                   d       * t        d#       |j                  j                  d$d%      }t        dt        |       d&       |D ]  }t        d|j                           t        d'       |j                  j                  d(d)      }t        dt        |       d*       |D ]  }t        d|j                           t        d+       |j                  ry|j                  j                  |j                  d,      }t        dt        |       d-|j                   d"       |D ]'  }t        d|j                   d.|j                          ) nt        d/       t        d0       |j                  j                  d$d1      }t        dt        |       d2       |D ]'  }t        d|j                   d.|j                          ) t        d3       |j                  r|j                  rt        |j                  |j                  z
  j!                               }|j                  j                  |d4      }t        dt        |       d5| d6       |D ]h  }|j                  s|j                  st        |j                  |j                  z
  j!                               }t        d|j                   d7| d8       j nt        d9       t        d:       |j"                  rz|j                  j                  |j"                  d;      }t        dt        |       d<|j"                   d"       |D ](  }t        d|j                   d=|j"                   d       * nt        d>       t        d?       |j$                  r~|j$                  d   }|j                  j                  |d@      }t        dt        |       dA| dB       |D ]1  }t        d|j                   dCt        |j$                         d       3 nt        dD       t        dE       |j                  j                  ddF      }t        dt        |       dG       |D ]  }t        d|j                           t        dH       |j&                  }|j                  j                  |dI      }t        dt        |       dJ| dB       |D ](  }t        d|j                   dK|j&                   d       * t        dL       |j                  j                  dMdN      }t        dO       |D ]  }t        d|j                           |j                  j                  dPdN      }t        dQ       |D ]  }t        d|j                           |j                  j                  dRdN      }t        dS       |D ](  }t        d|j                   dT|j(                   d       * |j                  j                  dUdN      }t        dV       |D ](  }t        d|j                   dT|j(                   d       * t        dW       dX}|j                  j	                  |	      }|r1t        dY|j                          t        dZ|j                          nt        d[| d\       t        d]       d^d_d`}t+        j,                  t.        j0                        }|t3        dab      z   }|j                  j                  dcd      }|rIt        de|        |D ]6  }t        df|j                          |j                  j5                  |g       8 |j                  j7                  dht+        j,                  t.        j0                  i      j9                  dj       dkdld$g||dmt+        j,                  t.        j0                  i      j;                          |n      }t        do|j                   d|j
                   d       t        dp|j"                          t        dq|j<                          t        dr       |}t        ds|j                          dt}dudvi}dwdxg}|j                  j?                  ||||dyz      }t        d{|j                          t        d||j                          t        d}|j<                          t        d~|j@                          |j                  |k(  sJ tC        |j<                        tC        |      k(  sJ |j@                  |k(  sJ t        d       |j                  j                  dcdd      }|rSt        d       |D ]C  }|j                  t        d|j                          |j                  jE                  |g       E ddg}t        d| d|j                          |j                  jG                  ||       t        d|j                          t        d       |}t        df|j                          |j                  j5                  |g       t        d|j                          yc c}w c c}w w)z/Main function demonstrating the Runs API usage.SIFT_GRPC_URIzlocalhost:50051SIFT_REST_URIzlocalhost:8080SIFT_API_KEY )api_keygrpc_urlrest_urlNostromoLV426)namezUsing asset: z (ID: )zFound z	 run(s): z for asset r   zUsing run: z other asset(s): z	 for run z
1. Listing all runs...   )limitz	   Found z runs:z   - z), Organization ID: z'
2. Testing different filter options...   z'   No runs available for filter testingNz
   2a. Filter by exact name...)r   r   z runs with exact name 'z':z)
   2b. Filter by name containing text...test)name_containsr   z runs with 'test' in name:z%
   2c. Filter by name using regex...z.*test.*)
name_regexr   z" runs with 'test' in name (regex):z&
   2d. Filter by exact description...)descriptionr   z runs with exact description 'z: z'   No description available for testingz0
   2e. Filter by description containing text...)description_containsr   z! runs with 'test' in description:z%
   2f. Filter by duration seconds...)duration_secondsr   z runs with duration z	 seconds:z (duration: zs)z5   No start/stop times available for duration testingz
   2g. Filter by client key...)
client_keyr   z runs with client key 'z (client_key: z&   No client key available for testingz
   2h. Filter by asset ID...)asset_idr   z runs associated with asset :z (asset_ids: z%   No asset IDs available for testingz
   2i. Filter by asset name...)
asset_namer   z, runs associated with asset 'NostromoLV426':z'
   2j. Filter by created by user ID...)created_by_user_idr   z runs created by user z (created by: z#
   2l. Testing ordering options...r   )order_byr   z,   First 3 runs ordered by name (ascending):z	name descz-   First 3 runs ordered by name (descending):zcreated_date descz8   First 3 runs ordered by creation date (newest first):z (created: created_datez8   First 3 runs ordered by creation date (oldest first):z#
3. Finding a single run by name...ztest-runz   Found run: z   Description: z   No run found with name ''z
4. Creating a new run...
productionintegration)environment	test_type   )minuteszExample Test Run.*)r   z%   Deleting previously created runs: z   Deleting run: )runzExample Test Run )tzz%Y-%m-%d %H:%M:%SzA test run created via the APIzapi-createdzexample-run-key-)r   r   tags
start_time	stop_timer   metadataz   Created run: z   Client key: z	   Tags: z
5. Updating a run...z   Updating run: zUpdated description via APIr&   ciupdatedzapi-modified)r   r+   r.   )r)   updatez   Updated run: z   New description: z   New tags: z   New metadata: z$
6. Associating assets with a run...TF)r   include_archived
is_stoppedz0   Ensuring previously created runs are stopped:z   Stopping run: asset1asset2z   Associating assets z with run: )r)   asset_namesz,   Successfully associated assets with run: z
7. Deleting a runz   Successfully archived run: )$osgetenvr   assetsfindid_printr   runslenlistorganization_idr   r,   r-   inttotal_secondsr   	asset_idsr   r!   r   nowr   utcr   archivecreatestrftime	timestampr+   r1   r.   sortedstop'create_automatic_association_for_assets)r   r   r   clientassetr   r=   r)   run_id
all_assetsother_assetssample_runs
sample_runrun_namer   run_durationr   r.   r,   r-   previously_created_runsnew_runrun_to_updatenew_descriptionnew_metadatanew_tagsupdated_runongoing_runsr6   run_to_deletes                                 g/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/_tests/integrated/runs.pymainr`      sl     yy*;<Hyy*:;Hii+GF MMO4EyyH	M%**VH:Q
78 ::D	
T9$%?3chh%?$@EJJ<W]^f]gghi
 q'CWWF	Kzxq
12 J'1KeUYY(5JEKLK	
\"##4\N)CHH:U[\b[ccde
 

$%;;!$D	Ic$i[
'( ZchhZvcggY.B3CVCVBWXYZ 

45 ++"""+K78QJ 

,-H;;3D	Ic$i[ 7z
DE 2chhZvcggYa012 

67;;&:D	Ic$i[ :
;< "chhZ !" 

23;;z;D	Ic$i[ B
CD "chhZ !" 

34{{J,B,B!L	#d)$B:CYCYBZZ\]^ 	9CE#((2coo%678	9 	78 

=>;;qAD	Ic$i[ A
BC 5chhZr#//!2345 

23!5!5
 4 4z7L7L L[[]^{{1AK	#d)$89I8J)TU 	FC~~#--"CMMCNN$B#Q#Q#STchhZ|L>DE	F
 	EF 

,-{{:+@+@J	#d)$;J<Q<Q;RRTUV 	ECE#((>#..1ACD	E 	67 

*+''*{{;	#d)$@
!LM 	ICE#((=cmm1D0EQGH	I 	56 

,-;;a@D	Ic$i[ L
MN "chhZ !" 

45#66;;/AKD	Ic$i[ 67I6J!
LM IchhZ~c.D.D-EQGHI 

01 ;;V15D	
89 "chhZ !" ;;[:D	
9: "chhZ !" ;;%8BD	
DE @chhZ{3+;+;*<A>?@ ;;^1=D	
DE @chhZ{3+;+;*<A>?@ 

01H
++



)C
sxxj)*  123+H:Q78 

&' $"H hll+JYq11I$kk..:N.O56M5NOP* 	)C%chhZ01KKC(	) kk   !>!G!GH[!\ ]^4V$%hllhll&C&M&M&O%PQ ! 	G 
W\\N&Q
?@	OG../
01	Igll^
$% 

"#M	m001
23 4OTL >*H++$$*$
 % K 
[--.
/0	 !8!8 9
:;	M+**+
,-	k223
45""o555+""#vh'7777</// 

12;;##'$5 $ L @A 	*C}}$)#((45  S )	* X&K	";-{7<<.
IJ
KK77GQ\7]	8
GH 

 M	m001
23
KKM*	*=+=+=*>
?@i &@ Ls:   B7s9sAs#s8s<N<s9s[%s,C.s__main__)__doc__asyncior7   r   r   r   sift_clientr   r`   __name__r)        r_   <module>rh      sB     	 2 2 "IAX zGKK rg   