
    jKjj                     X   d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlZd dlZd dlmZ d dl	m
Z d dlmZ d dl	mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ ej:                  j=                  dg d	      d
        Zej:                  j=                  dddg      d        Z d Z!d Z" G d dejF                        Z$ G d dejF                        Z%ej:                  j=                  dg d      d        Z&d Z'd Z(d Z)d Z* G d dejF                        Z+ G d dejF                        Z,y)     N)datedatetime)mock)parameterized)capture_message_only_logs)APIErrorDatetimeSerializerGetResponseKEEP_ALIVE_SOCKET_OPTIONSQuotaLimitError_mask_tokens_in_url
batch_postdetermine_server_hostdisable_connection_reuseenable_keep_aliveflagsgetset_socket_options)TEST_API_KEYzurl, expected))zAhttps://example.com/api/flags?token=phc_abc123xyz789&send_cohortsz>https://example.com/api/flags?token=phc_abc123...&send_cohorts)z4https://example.com/api/flags?token=phc_abc123xyz789z1https://example.com/api/flags?token=phc_abc123...))https://example.com/api/flags?other=valuer   ))https://example.com/api/flags?token=shortr   )z.https://example.com/api/flags?token=1234567890z1https://example.com/api/flags?token=1234567890...c                 $    t        |       |k(  sJ y N)r   )urlexpecteds     j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/test/test_request.pytest_mask_tokens_in_urlr      s    > s#x///    zkey, expected_present)sent_atT)sentAtFc                 <   t        j                         }d|_        t        j                         }||j
                  _        t        j
                  t        dd|g        t        j                  |j
                  j                  j                  d         }| |v |u sJ y )N   https://test.posthog.com/batch/hostpathsessionbatchdatarequestsResponsestatus_coder   	MagicMockpostreturn_valuerequest_moduler   jsonloads	call_argskwargs)keyexpected_presentmock_responsemock_sessionr*   s        r   "test_post_sends_snake_case_sent_atr;   A   s     %%'M #M>>#L%2L"' ::l''1188@AD4K,,,,r   c                  T   t        j                         } d| _        t        j                         }| |j
                  _        t        j
                  t        dd|g        t        j                  |j
                  j                  j                  d         }|d   t        k(  sJ d|vsJ y )Nr"   r#   r$   r%   r*   api_keytokenr+   )r9   r:   r*   s      r   %test_post_sends_project_api_key_fieldr?   Z   s    %%'M #M>>#L%2L"' ::l''1188@AD	?l***$r   c                     t        j                         } d| _        t        j                         }| |j
                  _        t               5 }t        j
                  t        dd|g        d d d        j                         j                         t        j                  dgk(  sJ |j                         j                         d   j                  d      sJ y # 1 sw Y   oxY w)Nr"   r#   r$   r%   z$[PostHog] data uploaded successfullyr   z[PostHog] making request: )r,   r-   r.   r   r/   r0   r1   r   r2   r   getvalue
splitlinesANY
startswith)r9   r:   logss      r   3test_message_only_debug_logs_include_posthog_prefixrF   m   s    %%'M #M>>#L%2L"	"	$+ 	
 
% ==?%%'.,    ==?%%'*556RSSS 
%	$s   CC!c                   Z    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)TestRequestsc                 h    t        t        ddddg      }| j                  |j                  d       y )Ndistinct_idpython eventtrackrJ   eventtyper)   r"   r   r   assertEqualr.   selfress     r   test_valid_requestzTestRequests.test_valid_request   s5     -PWX
 	#.r   c                 @    | j                  t        t        dddd       y )N
testsecrethttps://t.posthog.comFz[{]assertRaises	Exceptionr   rT   s    r   test_invalid_request_errorz'TestRequests.test_invalid_request_error   s    z<1H%QV	
r   c                 @    | j                  t        t        ddg        y )NrX   t.posthog.com/rP   rZ   r]   s    r   test_invalid_hostzTestRequests.test_invalid_host   s!    z<1A 	 	
r   c                     t        j                         }| j                  t              5  t	        j
                  t        d|       d d d        |j
                  j                          y # 1 sw Y   $xY w)Nr#   )r&   r(   )r   r/   r[   	TypeErrorr2   r0   r   assert_not_called)rT   r:   s     r   +test_post_without_path_preserves_type_errorz8TestRequests.test_post_without_path_preserves_type_error   sU    ~~'y)/$ * 	++- *)s   A**A3c                    t        j                         }d|_        t        j                         }||j
                  _        t        j
                  t        dd|g        |j
                  j                          |j
                  j                  j                  d   }|j
                  j                  j                  d   }| j                  |d       | j                  |t               y )Nr"   r#   r$   r%   r   r*   zhttps://test.posthog.com/batch/)r,   r-   r.   r   r/   r0   r1   r2   r   assert_called_oncer5   argsr6   rR   assertIsInstancestr)rT   r9   r:   r   r*   s        r   +test_post_sends_string_payload_without_gzipz8TestRequests.test_post_sends_string_payload_without_gzip   s     ))+$'!~~')6&+ 	
 	,,.))..q1  **11&9?@dC(r   c                    t        j                         }d|_        t        j                         }||j
                  _        t        j
                  t        ddd|g        |j
                  j                  j                  d   }|j
                  j                  j                  d   }| j                  |t               | j                  |d   d	       y )
Nr"   r#   r$   Tr&   r'   gzipr(   r)   r*   headersContent-Encodingrn   )r,   r-   r.   r   r/   r0   r1   r2   r   r5   r6   ri   bytesrR   )rT   r9   r:   r*   ro   s        r   'test_post_sends_bytes_payload_with_gzipz4TestRequests.test_post_sends_bytes_payload_with_gzip   s     ))+$'!~~')6&+ 	
   **11&9##--44Y?dE*!34f=r   c                    t        d      t        j                  d      fD ]#  }| j                  t	        |            5  t        j                         }d|_        t        j                         }||j                  _        t        j                  j                  t        d|      5  t        j                  t        ddd|g 	       d d d        |j                  j                   j"                  d
   }|j                  j                   j"                  d   }| j%                  |t&               | j)                  d|       d d d        & y # 1 sw Y   xY w# 1 sw Y   >xY w)Nboom)compression_errorr"   GzipFile)side_effectr#   r$   Trm   r*   ro   rp   )OSErrorzliberrorsubTestrO   r,   r-   r.   r   r/   r0   r1   patchobjectr2   r   r5   r6   ri   rj   assertNotIn)rT   ru   r9   r:   r*   ro   s         r   <test_post_falls_back_to_uncompressed_payload_when_gzip_failszITestRequests.test_post_falls_back_to_uncompressed_payload_when_gzip_fails   s#   ")&/4::f3E!F5F0GH ( 1 1 3,/)#~~/1>!!.ZZ&&"J<M '  #''$7&! ,  $((2299&A&++55<<YG%%dC0  !3W=+ IH "G  IHs&    A'E' E	A6E	EEE	c           
          dt        ddddddd      i}t        j                  |t        	      }| j	                  |d
       y )Ncreatedi                 i clsz){"created": "2012-03-04T05:06:07.891011"})r   r3   dumpsr	   rR   )rT   r*   results      r   test_datetime_serializationz(TestRequests.test_datetime_serialization   s?    8D!Q1a@AD&89!LMr   c                     t        j                         }d|i}t        j                  |t              }d|j                         z  }| j                  ||       y )Nr   r   z{"created": "%s"})r   todayr3   r   r	   	isoformatrR   )rT   r   r*   r   r   s        r   test_date_serializationz$TestRequests.test_date_serialization   sI    

5!D&89&)::*r   c                 j    t        t        ddddgd      }| j                  |j                  d       y )NrJ   rK   rL   rM      r)   timeoutr"   rQ   rS   s     r   test_should_not_timeoutz$TestRequests.test_should_not_timeout   s:     -PWX 
 	#.r   c                     | j                  t        j                        5  t        dddddgd       d d d        y # 1 sw Y   y xY w)Nr7   rJ   rK   rL   rM   g-C6?r   )r[   r,   ReadTimeoutr   r]   s    r   test_should_timeoutz TestRequests.test_should_timeout   sG    x334 (5!/ ' 
 544s	   =Ac                    t        j                         }d|_        t        j                  dgi i dd      j                  d      |_        t        j                  d|      5  | j                  t              5 }t        dd	       d d d        | j                  j                  j                  d       | j                  |j                  j                  d
       d d d        y # 1 sw Y   ^xY w# 1 sw Y   y xY w)Nr"   feature_flagsFquotaLimitedfeatureFlagsfeatureFlagPayloadserrorsWhileComputingFlagsutf-8#posthog.request._flags_session.postr1   fake_key	fake_hostzFeature flags quota limited)r,   r-   r.   r3   r   encode_contentr   r|   r[   r   r   rR   	exceptionstatusmessage)rT   r9   cms      r   !test_quota_limited_flags_responsez.TestRequests.test_quota_limited_flags_response  s     ))+$'!!%!0 1 "')-2	"
 &/ 	 ZZ1
 ""?3rj+. 4 R\\00#6R\\113PQ
 
 43
 
s%   "C.8C"AC."C+	'C..C7c                 6   t        j                         }d|_        t        j                  ddii dd      j                  d      |_        t        j                  d|      5  t        d	d
      }| j                  |d   ddi       d d d        y # 1 sw Y   y xY w)Nr"   flag1TFr   r   r   r   r   r   r   r   r   )r,   r-   r.   r3   r   r   r   r   r|   r   rR   )rT   r9   responses      r   test_normal_flags_responsez'TestRequests.test_normal_flags_response  s     ))+$'!!%!($')-2"
 &/ 	 ZZ1
 Z5HXn5G	
 
 
s   "$BBN)__name__
__module____qualname__rV   r^   ra   re   rk   rr   r   r   r   r   r   r   r    r   r   rH   rH      sF    /




.)(>(>2N
+/R*Hr   rH   c                   P   e Zd ZdZ ej
                  d      d        Z ej
                  d      d        Z ej
                  d      d        Z ej
                  d      d        Z	 ej
                  d      d        Z
 ej
                  d      d        Z ej
                  d      d	        Z ej
                  d      d
        Z ej
                  d      d        Z ej
                  d      d        Z ej
                  d      d        Z ej
                  d      d        Zy)TestGetz6Unit tests for the get() function HTTP-level behavior.zposthog.request._session.getc                    t        j                         }d|_        d|j                  d<   t	        j
                  dddigi      j                  d      |_        ||_        t        dd	d
      }| j                  |t               | j                  |j                  dddigi       | j                  |j                  d       | j                  |j                          y)zDTest that get() returns GetResponse with data and etag from headers.r"   z"abc123"ETagr   r7   	test-flagr   r=   	/test-urlhttps://example.comr&   N)r,   r-   r.   ro   r3   r   r   r   r1   r   ri   r
   rR   r*   etagassertFalsenot_modifiedrT   mock_getr9   r   s       r   test_get_returns_data_and_etagz&TestGet.test_get_returns_data_and_etag2  s     !))+$'!(2f%!%W{7K6L,M!N!U!U"
 !.y+4IJh4E;3G2H(IJ
3../r   c                 (   t        j                         }d|_        d|j                  d<   t	        j
                  dg i      j                  d      |_        ||_        t        dddd	
       |j                  d   }| j                  |d   d   d	       y)zGTest that If-None-Match header is sent when etag parameter is provided.r"   z
"new-etag"r   r   r   r=   r   r   z"previous-etag"r&   r      ro   If-None-MatchN)r,   r-   r.   ro   r3   r   r   r   r1   r   r5   rR   rT   r   r9   call_kwargss       r   6test_get_sends_if_none_match_header_when_etag_providedz>TestGet.test_get_sends_if_none_match_header_when_etag_providedD  s     !))+$'!(4f%!%WbM!:!A!A'!J -I{)>EVW((+Y/@BSTr   c                    t        j                         }d|_        t        j                  dg i      j                  d      |_        ||_        t        ddd       |j                  d   }| j                  d	|d
          y)zATest that If-None-Match header is not sent when no etag provided.r"   r   r   r=   r   r   r   r   r   ro   N)r,   r-   r.   r3   r   r   r   r1   r   r5   r~   r   s       r   1test_get_does_not_send_if_none_match_when_no_etagz9TestGet.test_get_does_not_send_if_none_match_when_no_etagR  st     !))+$'!!%WbM!:!A!A'!J -I{)>?((++i*@Ar   c                 T   t        j                         }d|_        d|j                  d<   ||_        t        dddd      }| j                  |t               | j                  |j                         | j                  |j                  d       | j                  |j                         y)	zKTest that 304 Not Modified response returns not_modified=True with no data.0  z"unchanged-etag"r   r=   r   r   r   N)r,   r-   r.   ro   r1   r   ri   r
   assertIsNoner*   rR   r   
assertTruer   r   s       r   !test_get_handles_304_not_modifiedz)TestGet.test_get_handles_304_not_modified_  s     !))+$'!(:f% -{)>EW
 	h4(--((:;--.r   c                     t        j                         }d|_        ||_        t	        dddd      }| j                  |j                         | j                  |j                  d       y)zFTest that 304 response without ETag header falls back to request etag.r   r=   r   r   z"original-etag"r   N)	r,   r-   r.   r1   r   r   r   rR   r   r   s       r   2test_get_304_without_etag_header_uses_request_etagz:TestGet.test_get_304_without_etag_header_uses_request_etagp  s`     !))+$'! -{)>EV
 	--.(9:r   c                 b   t        j                         }d|_        t        j                  dg i      j                  d      |_        ||_        t        ddd      }| j                  |j                         | j                  |j                         | j                  |j                  dg i       y)	zATest that 200 response without ETag header returns None for etag.r"   r   r   r=   r   r   r   N)r,   r-   r.   r3   r   r   r   r1   r   r   r   r   r   rR   r*   r   s       r    test_get_200_without_etag_headerz(TestGet.test_get_200_without_etag_header  s     !))+$'!!%WbM!:!A!A'!J -y+4IJ../(--("6r   c                    t        j                         }d|_        t        j                  ddi      j                  d      |_        ||_        | j                  t              5 }t        ddd       d	d	d	       | j                  j                  j                  d       | j                  |j                  j                  d       y	# 1 sw Y   VxY w)
z)Test that error responses raise APIError.i  detailUnauthorizedr   bad_keyr   r   r   N)r,   r-   r.   r3   r   r   r   r1   r[   r   r   rR   r   r   r   )rT   r   r9   ctxs       r   (test_get_error_response_raises_api_errorz0TestGet.test_get_error_response_raises_api_error  s     !))+$'!!%X~,F!G!N!Nw!W -x(C	;-BC ) 	--s3..?	 )(s   #CCc                    t        j                         }d|_        t        j                  i       j                  d      |_        ||_        t        ddd       |j                  d   }| j                  |d   d	   d
       y)z9Test that Authorization header is sent with Bearer token.r"   r   z
my-api-keyr   r   r   r   ro   AuthorizationzBearer my-api-keyNr,   r-   r.   r3   r   r   r   r1   r   r5   rR   r   s       r   #test_get_sends_authorization_headerz+TestGet.test_get_sends_authorization_header  su     !))+$'!!%B!6!6w!? -L+,AB((+Y/@BUVr   c                 J   t        j                         }d|_        t        j                  i       j                  d      |_        ||_        t        ddd       |j                  d   }| j                  d|d	          | j                  |d	   d   j                  d
             y)z$Test that User-Agent header is sent.r"   r   r=   r   r   r   r   z
User-Agentro   zposthog-python/N)r,   r-   r.   r3   r   r   r   r1   r   r5   assertInr   rD   r   s       r    test_get_sends_user_agent_headerz(TestGet.test_get_sends_user_agent_header  s     !))+$'!!%B!6!6w!? -I{)>?((+lK	$:;	"<0;;<MN	
r   c                     t        j                         }d|_        t        j                  i       j                  d      |_        ||_        t        dddd       |j                  d   }| j                  |d	   d       y
)z5Test that timeout parameter is passed to the request.r"   r   r=   r   r      )r&   r   r   r   Nr   r   s       r   test_get_passes_timeoutzTestGet.test_get_passes_timeout  sq     !))+$'!!%B!6!6w!? -I{)>K((+Y/4r   c                     t        j                         }d|_        t        j                  i       j                  d      |_        ||_        t        ddd       |j                  d   }| j                  |d   d       y	)
z.Test that host and url are combined correctly.r"   r   r=   
/api/flagsr   r   r   https://example.com/api/flagsNr   rT   r   r9   r5   s       r   test_get_constructs_full_urlz$TestGet.test_get_constructs_full_url  so     !))+$'!!%B!6!6w!? -I|*?@&&q)	1'FGr   c                     t        j                         }d|_        t        j                  i       j                  d      |_        ||_        t        ddd       |j                  d   }| j                  |d   d       y	)
z.Test that trailing slash is removed from host.r"   r   r=   r   zhttps://example.com/r   r   r   Nr   r   s       r   )test_get_removes_trailing_slash_from_hostz1TestGet.test_get_removes_trailing_slash_from_host  so     !))+$'!!%B!6!6w!? -I|*@A&&q)	1'FGr   N)r   r   r   __doc__r   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   /  s   @TZZ./0 00" TZZ./U 0U TZZ./
B 0
B TZZ.// 0/  TZZ./; 0; TZZ./7 07 TZZ./@ 0@ TZZ./
W 0
W TZZ./
 0
 TZZ./
5 0
5 TZZ./
H 0
H TZZ./
H 0
Hr   r   zhost, expected))rY   rY   )https://t.posthog.com/r   )t.posthog.comr   )r`   r`   )#https://us.posthog.com.rg.proxy.comr   )app.posthog.comr   )eu.posthog.comr   )zhttps://app.posthog.comhttps://us.i.posthog.com)zhttps://eu.posthog.comhttps://eu.i.posthog.com)zhttps://us.posthog.comr   )zhttps://app.posthog.com/r   )zhttps://eu.posthog.com/r   )zhttps://us.posthog.com/r   )z 
https://eu.posthog.com/	 r   )z 
	 r   )Nr   c                 $    t        |       |k(  sJ y r   )r   )r&   r   s     r   test_routing_to_custom_hostr     s    , !&(222r   c                      	 t                ddlm}  | j                  d      }|j                  t
        k(  sJ 	 t        d        y # t        d        w xY wNr   )_sessionr   )r   posthog.requestr   get_adaptersocket_optionsr   r   r   adapters     r   *test_enable_keep_alive_sets_socket_optionsr     sH    !,&&'<=%%)BBBB4 4 s   6A Ac                      	 t                t        d        ddlm}  | j	                  d      }|j
                  J 	 t        d        y # t        d        w xY wr   )r   r   r   r   r   r   r   s     r   (test_set_socket_options_clears_with_noner     sM    !4 ,&&'<=%%---4 4    :A	 	Ac                      	 t                t        j                         } t        j                         }| |usJ 	 dt        _        y # dt        _        w xY w)NT)r   r2   _get_session_pooling_enabledsession1session2s     r   4test_disable_connection_reuse_creates_fresh_sessionsr    sH    / "!..0!..0x'''*.'$'s   8A Ac                      	 t                t        j                  } t                t        j                  }| |u sJ 	 t        d        y # t        d        w xY wr   )r   r2   r   r   r  s     r   %test_set_socket_options_is_idempotentr	    sI    !!**!**8###4 4 r   c                   v    e Zd ZdZd Z ej                  d      d        Z ej                  d      d        Zy)TestFlagsSessionz&Tests for flags session configuration.c                 8   ddl m}  |       }|j                  d      }|j                  }| j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       y)zCHTTP adapter retries are disabled; flags() handles bounded retries.r   )_build_flags_sessionr#   N)	r   r  r   max_retriesrR   totalconnectreadr   )rT   r  r(   r   retrys        r   +test_flags_session_disables_adapter_retriesz<TestFlagsSession.test_flags_session_disables_adapter_retries)  sy    8&(%%&@A##a(*Q'q)r   "posthog.request._get_flags_sessionc                    t        j                         }d|_        t        j                  ddii dd      j                  d      |_        t        j                         }||j                  _
        ||_
        t        ddd	
      }| j                  |d   d   d       |j                          |j                  j                          y)zBflags() uses the dedicated flags session, not the general session.r"   r   TFr   r   test-keyr#   user123rJ   r   N)r,   r-   r.   r3   r   r   r   r   r/   r0   r1   r   rR   rg   )rT   mock_get_flags_sessionr9   r:   r   s        r   test_flags_uses_flags_sessionz.TestFlagsSession.test_flags_uses_flags_session6  s     !))+$'!!%!,d 3')-2"
 &/ 	 ~~')6&.:+z#=9U/<dC113,,.r   c                    t        j                         }d|_        t        j                  dgi i dd      j                  d      |_        t        j                         }||j                  _
        ||_
        | j                  t              5  t        ddd	       d
d
d
       | j                  |j                  j                  d       y
# 1 sw Y   0xY w)zGflags() raises QuotaLimitError without retrying (at application level).r"   r   Fr   r   r  r#   r  r  Nr   )r,   r-   r.   r3   r   r   r   r   r/   r0   r1   r[   r   r   rR   
call_count)rT   r  r9   r:   s       r   "test_flags_no_retry_on_quota_limitz3TestFlagsSession.test_flags_no_retry_on_quota_limitM  s     !))+$'!!%!0 1 "')-2	"
 &/ 	 ~~')6&.:+/*8iP 0 	**55q9	 0/s   C

CN)	r   r   r   r   r  r   r|   r  r  r   r   r   r  r  &  sJ    0* TZZ45/ 6/, TZZ45: 6:r   r  c                      e Zd ZdZ ej
                  d       ej
                  d      d               Z ej
                  d       ej
                  d      d               Z ej
                  d       ej
                  d      d               Z e	j                  ddg      d	        Z e	j                  g d
      d        Zy)TestFlagsRetriesz Tests for /flags retry behavior.posthog.request.time.sleepr  c                    t        j                         }d|_        t        j                  ddii dd      j                  d      |_        t        j                         }t         j                  j                  d      |g|j                  _        ||_        t        dd	d
      }| j                  |d   ddi       | j                  |j                  j                   d       |j#                  d       y )Nr"   r   TFr   r   connection failedr  r#   r  r  r      333333?)r,   r-   r.   r3   r   r   r   r   r/   
exceptionsConnectionErrorr0   rw   r1   r   rR   r  assert_called_once_with)rT   r  
mock_sleepr9   r:   r   s         r   3test_flags_retries_transport_errors_once_by_defaultzDTestFlagsRetries.test_flags_retries_transport_errors_once_by_defaulti  s    
 !))+$'!!%!,d 3')-2"
 &/ 	 ~~'//0CD)
% /;+%?YW.1K3FG**55q9**3/r   c                    t        j                         }t        j                  j	                  d      |j
                  _        ||_        | j                  t        j                  j                        5  t        dddd       d d d        | j                  |j
                  j                  d       |j                          y # 1 sw Y   @xY w)N	timed outr  r#   r   r  r  rJ   r   )r   r/   r,   r%  Timeoutr0   rw   r1   r[   r   rR   r  rd   )rT   r  r(  r:   s       r   ,test_flags_retry_count_zero_disables_retriesz=TestFlagsRetries.test_flags_retry_count_zero_disables_retries  s    
 ~~'(0(;(;(C(CK(P%.:+x22::;*%	 < 	**55q9$$& <;s   3CCc                 ~   t        j                         }d|_        t        j                  ddii dd      j                  d      |_        t        j                         }t         j                  j                  d      t         j                  j                  d      |g|j                  _        ||_        t        d	d
dd      }| j!                  |d   ddi       | j!                  |j                  j"                  d       | j!                  |j$                  D cg c]  }|j&                  d    c}ddg       y c c}w )Nr"   r   TFr   r   r"  r+  r  r#   r#  r  r,  r   r   r   r$  g333333?)r,   r-   r.   r3   r   r   r   r   r/   r%  r&  r-  r0   rw   r1   r   rR   r  call_args_listrh   )rT   r  r(  r9   r:   r   calls          r   2test_flags_retry_delay_starts_at_300ms_and_doubleszCTestFlagsRetries.test_flags_retry_delay_starts_at_300ms_and_doubles  s(   
 !))+$'!!%!,d 3')-2"
 &/ 	 ~~'//0CD''4)
%
 /;+&!	
 	.1K3FG**55q9&0&?&?@&?dTYYq\&?@3*	
@s   D:)i  )i  c                    t        j                         }||_        d|_        t        j                         }d|_        t	        j
                  d| ddii dd      j                  d      |_        t        j                         }||g|j                  _
        t        j                  d	|
      5  t        j                  d      5 }t        ddd      }d d d        d d d        | j                  d   d| ddi       | j                  |j                  j                  d       j                  d       y # 1 sw Y   dxY w# 1 sw Y   hxY w)Ns   {"detail": "transient error"}r"   z
transient-z-flagTFr   r   r  r   r   r  r#   r  r  r   r#  r$  )r,   r-   r.   r   r3   r   r   r   r/   r0   rw   r|   r   rR   r  r'  )rT   r.   retry_responsesuccess_responser:   r(  r   s          r   .test_flags_retries_contract_http_status_errorsz?TestFlagsRetries.test_flags_retries_contract_http_status_errors  s9   !**,%0""B#,,.'*$$(JJ#-k]%!@$ G')-2%
 &/ 	! ~~')79I(J% JJ;,WJJ34
6IH 5 X 	^$K='F&M	
 	**55q9**3/ 54 XWs$   /ED7E7E 	<EE))i  )i  )i  )i  c                    t        j                         }||_        d|_        t	        j
                         }||j                  _        t	        j                  d|      5  | j                  t              5 }t        ddd       d d d        d d d        | j                  j                  j                  |       | j                  |j                  j                  d       y # 1 sw Y   ^xY w# 1 sw Y   bxY w)	Ns!   {"detail": "Service unavailable"}r  r   r  r#   r  r  r   )r,   r-   r.   r   r   r/   r0   r1   r|   r[   r   r   rR   r   r   r  )rT   r.   r9   r:   r   s        r   2test_flags_does_not_retry_other_http_status_errorszCTestFlagsRetries.test_flags_does_not_retry_other_http_status_errors  s     ))+$/!!E~~')6&ZZ0|
 ""8,j"<)T -
 	,,k:**55q9	 -,
 
s$   C-5C!C-!C*	&C--C6N)r   r   r   r   r   r|   r)  r.  r2  r   expandr6  r8  r   r   r   r  r  f  s    *TZZ,-TZZ450 6 .04 TZZ,-TZZ45' 6 .'$ TZZ,-TZZ45 
 6 . 
D ]66*+0 ,0@ ]:;: <:r   r  )-r3   unittestry   r   r   r   pytestr,   r   r   requestr2   posthog.test.logging_helpersr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   posthog.test.test_utilsr   markparametrizer   r;   r?   rF   TestCaserH   r   r   r   r   r  r	  r  r  r   r   r   <module>rB     s7      #    ' ( B    1 <0=<0 --$&T,iH8$$ iHXoHh oHd *3+*3!	!/!=:x(( =:@H:x(( H:r   