
    =Kild                         S SK r S SKrS SKrS SKJrJr  S SKJrJr  SSK	J
r
  S SKJr   " S S\ R                  5      r\S	:X  a  \ R                   " 5         gg)
    N)Mockcall)clientconfig   )Watch)ApiExceptionc                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS r\S 5       rS rSrg)
WatchTests   c                     SU l         g )Nr   	callcount)selfs    ]/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/kubernetes/watch/watch_test.pysetUpWatchTests.setUp   s	        c                 h   [        5       n[        5       Ul        [        5       Ul        [        / SQS9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  5       H  nU R                  SUS   5        U R                  SU-  US   R                  R                  5        U R                  S	U-  US   R                  R                  5        U R                  S	U-  UR                  5        US-  nUS
:X  d  M  UR                  5         M     U R                  S
U5        UR                  R                  SSS9  UR                  R                  S SS9  UR                  R                  5         UR                  R                  5         g )N)n{"type": "ADDED", "object": {"metadata": {"name": "test1","resourceVersion": "1"}, "spec": {}, "status": {}}}
c{"type": "ADDED", "object": {"metadata": {"name": "test2","resourceVersion": "2"}, "spec": {}, "staytus": {}}}
{"type": "ADDED", "object": {"metadata": {"name": "test3","resourceVersion": "3"}, "spec": {}, "status": {}}}
zshould_not_happened
return_value:return: V1NamespaceListr   ADDEDtypetest%dobject%d   FT_preload_contentwatchamtdecode_content)r   closerelease_connstreamget_namespaces__doc__r   assertEqualmetadatanameresource_versionstopassert_called_once_withassert_called_oncer   	fake_respfake_apiwcountes         r   test_watch_with_decode!WatchTests.test_watch_with_decode#   s}   F	&	!%	)	*	 6"&I">*D'G(112AWai0X-q{/C/C/H/HIuak22CCETE\1+=+=>QJE z 3 	E"77"$ 	8 	000U 	1 	,**,113r   c                    [        5       n[        5       Ul        [        5       Ul        [        / SQS9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  SS9 H9  nUc  M  US-  nU R                  SU-  US   R                  R                  5        M;     U R                  S	U5        g )
N)	
z({"type": "ADDED", "object": {"metadata":z={"name": "test1","resourceVersion": "1"}}}
{"type": "ADDED", zC"object": {"metadata": {"name": "test2", "resourceVersion": "2"}}}
r=    zU{"type": "ADDED", "object": {"metadata": {"name": "test3", "resourceVersion": "3"}}}
z


r=   r   r   r   r   timeout_secondsr   r      )
r   r(   r)   r*   r+   r,   r   r-   r.   r/   r4   s         r   %test_watch_with_interspersed_newlines0WatchTests.test_watch_with_interspersed_newlinesP   s    F	&	!%	
	 6"&I">*D'G
 (111EAyQJEX-q{/C/C/H/HI F 	E"r   c                    [        5       n[        5       Ul        [        5       Ul        [        / SQS9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  SS9 H  nUS-  nU R                  SUS   5        U R                  S	U-  US
   R                  R                  5        U R                  SU-  US
   R                  S   5        U R                  SU-  US
   R                  R                  5        U R                  SU-  UR                  5        M     U R                  SU5        g )N)ui   {"type":"MODIFIED","object":{"data":{"utf-8":"© 1"},"metadata":{"name":"test1","resourceVersion":"1"}}}
s   {"type":"MODIFIED","object":{"data":{"utf-8":"© 2"},"metadata":{"name":"test2","resourceVersion":"2"}}}
{"type":"MODIFIED","object":{"data":{"utf-8":"s    3"},"metadata":{"nz"ame":"test3","resourceVersion":"3"}}}   
r   :return: V1ConfigMapListr   r   r?   MODIFIEDr   r   r   u   © %dutf-8r    rA   )r   r(   r)   r*   get_configmapsr,   r   r-   r.   r/   datar0   r   r5   r6   r7   r8   events         r   test_watch_with_multibyte_utf8)WatchTests.test_watch_with_multibyte_utf8s   s7   F	&	!%		 6"&I">*D'G
 XXh55qXIEQJEZv7X-uX/G/G/L/LMWu_eHo.B.B7.KLueHo66GGITE\1+=+=> J 	E"r   c                    [        5       n[        5       Ul        [        5       Ul        [        / SQS9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  SS9 H  nUS-  nU R                  SUS   5        U R                  S	U-  US
   R                  R                  5        U R                  SU-  US
   R                  S   5        U R                  SR                  SSU-  5      U-  US
   R                  S   5        M     U R                  SU5        g )N)se   {"type":"MODIFIED","object":{"data":{"utf-8":"😄 1","invalid":" 1"},"metadata":{"name":"test1"}}}
sf   {"type":"MODIFIED","object":{"data":{"utf-8":"😄 2","invalid":" 2"},"metadata":{"name":"test2"}}}
s1   {"type":"MODIFIED","object":{"data":{"utf-8":"s    r   s   3","invalid":"s    z3"},"metadata":{"nzame":"test3"rE   rF   r   rG   r   r   r?   rH   r   r   r   u   😄 %drI   u   � %du   �invalidrA   )r   r(   r)   r*   rJ   r,   r   r-   r.   r/   rK   replacerL   s         r   test_watch_with_invalid_utf8'WatchTests.test_watch_with_invalid_utf8   s2   F	&	!%			, 6"&I">*D'G
 XXh55qXIEQJEZv7X-uX/G/G/L/LMY.h0D0DW0MNX--eU5[A"#$)(O$8$8$CE J 	E"r   c                 P   [        5       n[        5       Ul        [        5       Ul        [        SS/S9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  5       H2  nU R                  SU5        US-  nUS:X  d  M"  UR                  5         M4     UR                  R                  SS	S
9  UR                  R                  S SS9  UR                  R                  5         UR                  R                  5         g )Nzlog_line_1
zlog_line_2
r   z :param bool follow:
:return: strr   
log_line_1   FT)r#   followr%   )r   r(   r)   r*   read_namespaced_pod_logr,   r   r-   r1   r2   r3   r4   s         r   test_watch_for_follow WatchTests.test_watch_for_follow   s	   F	&	!%	 !	
 6+/Y+G(3V((0G(::;A\1-QJE z < 	((@@"4 	A 	100U 	1 	,**,113r   c           	        ^ ^
 [        5       n[        5       Ul        [        5       Ul        / SQm
U U
4S jn[        US9Ul        [        5       n[        US9Ul        SUR                  l        [        5       n/ nSnUR                  [        SSS	S
95        UR                  [        SSS	S
95        [        U5       H  nUR                  [        SSSS
95        M     [        UR                  UR                  S	S95       H)  u  pU[        T
5      U-  :X  d  M  UR                  5         M+     UR                  R                  U5        T R                  UR                  R                  U5        g )N)r   r   r   c                  V   > T=R                   S-  sl         TR                   S:X  a  / $ T$ )Nr   r   )argskwargsr   valuess     r   
get_values>WatchTests.test_watch_resource_version_set.<locals>.get_values   s'    NNaN~~"	r   side_effectr   r   rW   FT5)r#   r$   r0   3r0   )r   r(   r)   r*   r+   r,   r   appendr   range	enumeratelenr1   assert_has_callsr-   
mock_calls)r   r5   ra   r6   r7   calls
iterationsicr9   r`   s   `         @r   test_watch_resource_version_set*WatchTests.test_watch_resource_version_set   sO    F	&	!%	
	  "$	 6"&I">*D'G
 
 	T5+.0 	1T5+.0 	1z"A LLuD/24 5	 # ahhx'>'>8; ' = >DACK*,,> 	00700;;UCr   c                 t   [        [        5      nS GH"  n[        5       n[        5       Ul        [        5       Ul        [        S/S-  S9Ul        [        5       n[        US9Ul        SUR                  l        SnUR                  UR                  5       H   nUS-  nUS:X  d  M  UR                  5         M"     U R                  US5        UR                  R                  SS	S
9  UR
                  R                  S SS9  UR                  R                  5         UR                  R                  5         GM%     g )N)firstsecond{"type": "ADDED", "object": 1}
r!   r   r   r   rA   FTr"   r%   )r   floatr   r(   r)   r*   r+   r,   r1   r-   r2   r3   )r   r7   stepr5   r6   r8   r9   s          r   test_watch_stream_twice"WatchTests.test_watch_stream_twice+  s   %L'DI"fIO%)VI"#@AAE GI vH&*	&BH#.HH##+EXXh556
A:FFH 7
 UA&##;;!&d < 444 5 0OO..0""557/ (r   c                 (   [        [        5      n[        5       n[        5       Ul        [        5       Ul        [        S/S9Ul        [        5       n[        US9Ul        SUR                  l        SnUR                  UR                  SS9 H  nUS-   nM
     U R                  US5        UR                  UR                  5       H   nUS-   nUS:X  d  M  UR                  5         M"     U R                  US5        U R                  UR                  R                  S5        U R                  UR
                  R                  S5        U R                  UR                  R                  S5        U R                  UR                  R                  S5        g )Nrw   r   r   r   r   r?   rW   )r   rx   r   r(   r)   r*   r+   r,   r-   r1   
call_count)r   r7   r5   r6   r8   r9   s         r   test_watch_stream_loop!WatchTests.test_watch_stream_loopF  sN   %LF	&	!%	<=?	 6"&I">*D' (111EAAIE F" (112AAIEz 3
 	"00;;Q?))44a833Q7//::A>r   c                     [        5       nUR                  SS5      nU R                  SUS   5        U R                  SUS   5        U R                  [	        US   [
        5      5        U R                  SUS   5        g )	Nz{"type": "ADDED", "object": 1}rx   r   r   g      ?r   r   
raw_object)r   unmarshal_eventr-   
assertTrue
isinstancerx   r   r7   rM   s      r    test_unmarshal_with_float_object+WatchTests.test_unmarshal_with_float_objectf  sp    G!!"BGL%-0eHo.
5?E:;E,/0r   c                     [        5       nUR                  SS 5      nU R                  SUS   5        U R                  S/US   5        U R                  S/US   5        g )Nz&{"type": "ADDED", "object": ["test1"]}r   r   test1r   r   )r   r   r-   r   s      r   "test_unmarshal_with_no_return_type-WatchTests.test_unmarshal_with_no_return_typen  s`    G!!"J"&(%-0'E(O4'E,$78r   c                    [        5       nUR                  SS5      nU R                  SUS   5        U R                  [	        US   [
        5      5        U R                  SUS   S   S   5        U R                  SUR                  5        g )Nz~{"type": "ADDED", "object": {"apiVersion":"test.com/v1beta1","kind":"foo","metadata":{"name": "bar", "resourceVersion": "1"}}}r   r   r   1r.   resourceVersion)r   r   r-   r   r   dictr0   r   s      r   !test_unmarshal_with_custom_object,WatchTests.test_unmarshal_with_custom_objectv  s    G!! #N #+, 	%-0 	
5?D9:eHoj9:KLMa001r   c                     [        5       nUR                  SS5      nU R                  SUS   5        U R                  S UR                  5        g )Nz{"type":"BOOKMARK","object":{"kind":"Job","apiVersion":"batch/v1","metadata":{"resourceVersion":"1"},"spec":{"template":{"metadata":{},"spec":{"containers":null}}},"status":{}}}V1JobBOOKMARKr   )r   r   r-   r0   r   s      r   test_unmarshal_with_bookmark'WatchTests.test_unmarshal_with_bookmark  sR    G!!G 	
 	U6]3 	q112r   c                     [        5       n[        5       Ul        [        5       Ul        [        [        S5      S9Ul        [        5       n[        US9Ul        [        5       n UR	                  UR
                  5       H  nU R                  U S5        M     UR
                  R                  SSS9  UR                  R                  S SS9  UR                  R                  5         UR                  R                  5         g ! [         a     Nuf = f)	Nexpectedrc   r   zShould fail on exception.FTr"   r%   )
r   r(   r)   KeyErrorr*   	get_thingr   failr2   r3   r   r5   r6   r7   _s        r   test_watch_with_exception$WatchTests.test_watch_with_exception  s    F	&	!%	HZ,@A	6!y9G	XXh001		$ ;< 2 	22"$ 	3 	000U 	1 	,**,113  		s   #4D   
DDc                    [        5       n[        5       Ul        [        5       Ul        [        S/S9Ul        [        5       n[        US9Ul        [        5       n[        UR                  UR                  5      5      (       a   eUR                  R                  SSS9  UR                  R                  S SS9  UR                  R                  5         UR                  R                  5         g )NY{"type": "ERROR", "object": {"code": 410, "reason": "Gone", "message": "error message"}}
r   FTr"   r%   )	r   r(   r)   r*   r   r   listr2   r3   )r   r5   r6   r7   s       r   test_watch_with_error_event&WatchTests.test_watch_with_error_event  s    F	&	!%	CDE	
 6!y9G !3!34555522"$ 	3 	000U 	1 	,**,113r   c                 t   [        5       n[        5       Ul        [        5       Ul        [        S/S9Ul        [        5       n[        US9Ul        [        5       n UR                  UR                  SS9 H  nU R                  U S5        M     UR                  R                  [        SSSS9/S	-  5        UR                  R                  [        S SS
9/S	-  5        UR                  R                  S	:X  d   eUR                  R                  S	:X  d   eg ! [        R                  R                   a     Nf = f)Nr   r   r   rg   Should fail with ApiException.FT)r0   r#   r$   rW   r%   )r   r(   r)   r*   r   r   r   r   restr	   rl   r   r}   r   s        r   !test_watch_retries_on_error_event,WatchTests.test_watch_retries_on_error_event  s&   F	&	!%	CDE	
 6!y9G	XXh001XE		$ @A F 	++1uDIJQN	P))d512Q6	8))Q...%%00A555 {{'' 		s   3D D76D7c                 8   [        5       n[        5       Ul        [        5       Ul        [        S/S9Ul        [        5       n[        US9Ul        [        5       n UR                  UR                  SS9 H  nU R                  U S5        M     UR                  R                  SSSS9  UR                  R                  S SS	9  UR                  R                  5         UR                  R                  5         g ! [        R                  R                   a     Nf = f)
Nr   r   
   r?   r   FT)r#   r$   r@   r%   )r   r(   r)   r*   r   r   r   r   r   r	   r2   r3   r   s        r   -test_watch_with_error_event_and_timeout_param8WatchTests.test_watch_with_error_event_and_timeout_param  s   F	&	!%	CDE	
 6!y9G	XXh00"XE		$ @A F
 	22"$ 	3 	D00U 	1 	,**,113 {{'' 		s   3C8 8DDc                 0    [        5       U l        SU l        g )Ndefault)r   api	namespace)clss    r   
setUpClassWatchTests.setUpClass  s    &!r   c                    Sn [        5       U R                  l        [        5       U R                  l        [        5       U R                  l        [        5       U R                  l        S U R                  R                  l        [        5       nSUR                  l        X R                  R                  l        [        S/5      U R                  R
                  l        Sn[        R                  " 5       n[        R                  " 5       U-
  U:  ar  U R                  R                  XR                  S9nUR                  R                  S:X  a  OE[        R                  " S5        [        R                  " 5       U-
  U:  a  Mr  U R                  S5        [        5       n/ n[        / SQS	9Ul        UR                  U R                  R
                  XR                  S
S9 H  nUR!                  U5        [#        U5        M!     [#        SU 35        / SQn	U R%                  XyS5        U R                  R	                  XR                  S9  U R                  R                  R)                  XR                  S9  g ! [&         a  n
U R                  SU
 35         S n
A
NtS n
A
ff = f! U R                  R	                  XR                  S9  U R                  R                  R)                  XR                  S9  f = f)Nzdemo-bugRunningzHello from Docker
<   )r/   r   rW   z0Pod did not reach 'Running' state within timeout)zHello from Dockerr>   r>   z

zAnother log liner>   r=   z	Final logr   T)r/   r   rX   zCaptured logs: z(Captured logs do not match expected logszKubernetes API exception: )r   r   create_namespaced_podread_namespaced_poddelete_namespaced_podrY   r   statusphaseitertimer   sleepr   r   r*   rh   printr-   r	   r2   )r   pod_namemock_podtimeout
start_timepodr7   
log_outputrM   expected_logr9   s              r   test_pod_log_empty_lines#WatchTests.test_pod_log_empty_lines  sO   D	l-1VDHH*+/6DHH(-1VDHH*/3vDHH, ;?DHH**7 vH$-HOO!8@HH((5 =ABWAX<YDHH,,9 GJ))+
*W4hh22NN2[::##y0

1	 ))+
*W4 		LM AJ 	* 	AH $(("B"B]k]ktxy!!%(e z
 OJ<01	L Z7ab HH**NN*SHH**BB\j\jBk  	8II21#677	8 HH**NN*SHH**BB\j\jBks2   E<I6 B#I6 6
J JJ! JJ! !AK3r   N)__name__
__module____qualname____firstlineno__r   r:   rB   rN   rS   rZ   rr   rz   r~   r   r   r   r   r   r   r   r   classmethodr   r   __static_attributes__ r   r   r   r      sz    +4Z!#F%#N,#\4<CDJ86?@192340406644 " "Glr   r   __main__)unittestosr   unittest.mockr   r   
kubernetesr   r   r$   r   kubernetes.clientr	   TestCaser   r   mainr   r   r   <module>r      sK     	  $ $  *cl"" cl\ zMMO r   