
    |h&                     8    d Z ddlZddlZddlmZ  G d d      Zy)zUtilities for testing. Includes a base test class
for testing parsers.

.. warning::

    Methods and functions in this module may change without
    warning and without a major version change.
    N)jsonc                      e Zd ZdZd Zd Zd Zd Z ej                  d      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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%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1ejd                  jg                  d0d1 e4jj                  d2d3i      d4fd5d2d3id6fg      d7        Z6y8)9CommonTestCasezBase test class that defines test methods for common functionality across all
    parsers. Subclasses must define `create_app`, which returns a WSGI-like app.
    c                     t        d      )zReturn a WSGI appzMust define create_app())NotImplementedErrorselfs    N/var/www/html/test/engine/venv/lib/python3.12/site-packages/webargs/testing.py
create_appzCommonTestCase.create_app   s    !"<==    c                 ,    t        j                  |      S N)webtestTestApp)r	   apps     r
   create_testappzCommonTestCase.create_testapp   s    s##r   c                      y r    r   s    r
   before_create_appz CommonTestCase.before_create_app       r   c                      y r   r   r   s    r
   after_create_appzCommonTestCase.after_create_app   r   r   class)scopec              #      K   | j                          | j                  | j                                | j                          y wr   )r   r   r   r   r   s    r
   testappzCommonTestCase.testapp"   s6      !!$//"344s   AAc                 H    |j                  d      j                  ddik(  sJ y )Nz/echo?name=FrednameFredgetr   r	   r   s     r
   test_parse_querystring_argsz*CommonTestCase.test_parse_querystring_args(   s%    {{,-22vv6FFFFr   c                 N    |j                  dddi      j                  ddik(  sJ y )N
/echo_formr   Joepostr   r"   s     r
   test_parse_formzCommonTestCase.test_parse_form+   s)    ||L65/:??FE?RRRr   c                 N    |j                  dddi      j                  ddik(  sJ y )N
/echo_jsonr   r   	post_jsonr   r"   s     r
   test_parse_jsonzCommonTestCase.test_parse_json.   s7      /?@EEFJ
 
 	
 
r   c                 J    |j                  dd      j                  ddik(  sJ y )Nr+    r   Worldr'   r"   s     r
   test_parse_json_missingz&CommonTestCase.test_parse_json_missing3   &    ||L"-22vw6GGGGr   c                     |j                  dddi      j                  ddik(  sJ |j                  dddi      j                  ddik(  sJ |j                  dd      j                  ddik(  sJ y )Nz/echo_json_or_formr   r   r&   r0   r1   )r-   r   r(   r"   s     r
   test_parse_json_or_formz&CommonTestCase.test_parse_json_or_form6   s      !57GHMMFR
 
 	
 
 ||065/BGGEL
 
 	
 
 ||0"5::vw>OOOOr   c                 H    |j                  d      j                  ddik(  sJ y )Nz/echor   r1   r    r"   s     r
   test_parse_querystring_defaultz-CommonTestCase.test_parse_querystring_default?   s$    {{7#((VW,====r   c                 |    |j                  dt        j                  ddi      d      }|j                  ddik(  sJ y )Nr+   r   Stevezapplication/json;charset=UTF-8content_typer(   r   dumpsr	   r   ress      r
   test_parse_json_with_charsetz+CommonTestCase.test_parse_json_with_charsetB   sE    llJJ()9  

 xxFG,,,,r   c                 |    |j                  dt        j                  ddi      d      }|j                  ddik(  sJ y )Nr+   r   r9   z&application/vnd.api+json;charset=UTF-8r:   r<   r>   s      r
   &test_parse_json_with_vendor_media_typez5CommonTestCase.test_parse_json_with_vendor_media_typeJ   sE    llJJ()A  

 xxFG,,,,r   c                 N    |j                  dddi      j                  ddik(  sJ y )Nz/echo_ignoring_extra_dataextradatar   r1   r,   r"   s     r
   test_parse_ignore_extra_dataz+CommonTestCase.test_parse_ignore_extra_dataR   s5      ''6):

$67#$ 	$ $r   c                 J    |j                  di       j                  ddik(  sJ y )Nr+   r   r1   r,   r"   s     r
   test_parse_json_emptyz$CommonTestCase.test_parse_json_emptyW   s(      r277FG;LLLLr   c                 N    |j                  ddd      }|j                  dk(  sJ y )Nr+      Texpect_errors  r-   status_coder>   s      r
   $test_parse_json_error_unexpected_intz3CommonTestCase.test_parse_json_error_unexpected_intZ   s+    atD#%%%r   c                 T    |j                  dddigd      }|j                  dk(  sJ y )Nr+   rD   rE   TrK   rM   rN   r>   s      r
   %test_parse_json_error_unexpected_listz4CommonTestCase.test_parse_json_error_unexpected_list^   s4    /@.AQUV#%%%r   c                 T    |j                  dddigd      }|j                  dk(  sJ y )N/echo_many_schemar   aTrK   rM   rN   r>   s      r
   )test_parse_json_many_schema_invalid_inputz8CommonTestCase.test_parse_json_many_schema_invalid_inputb   s8    63-   
 #%%%r   c                 V    |j                  dddig      j                  }|ddigk(  sJ y )NrT   r   r9   r,   r>   s      r
   test_parse_json_many_schemaz*CommonTestCase.test_parse_json_many_schemah   s9     3vw6G5HINN())))r   c                 R    |j                  dddid      }|j                  dk(  sJ y )NrT   rD   rE   TrK   rM   rN   r>   s      r
   0test_parse_json_many_schema_error_malformed_dataz?CommonTestCase.test_parse_json_many_schema_error_malformed_datal   s7    '6!2$   
 #%%%r   c                 J    |j                  di       j                  ddik(  sJ y )Nr%   r   r1   r'   r"   s     r
   test_parsing_form_defaultz(CommonTestCase.test_parsing_form_defaultr   r3   r   c                 P    dddgi}|j                  d      j                  |k(  sJ y )Nr   steveLoriaz!/echo_multi?name=steve&name=Loriar    r	   r   expecteds      r
   test_parse_querystring_multiplez.CommonTestCase.test_parse_querystring_multipleu   s/    Wg./{{>?DDPPPr   c                 N    ddgi}|j                  d      j                  |k(  sJ y )Nr   r^   z/echo_multi?name=stever    r`   s      r
   ,test_parse_querystring_multiple_single_valuez;CommonTestCase.test_parse_querystring_multiple_single_value}   s,    WI&{{3499XEEEr   c                 Z    dddgi}|j                  ddddgi      j                  |k(  sJ y )Nr   r^   r_   z/echo_multi_formr'   r`   s      r
   test_parse_form_multiplez'CommonTestCase.test_parse_form_multiple   sB    Wg./LL+fw6H-IJOO	
r   c                 V    ddgi}|j                  dddgi      j                  |k(  sJ y )Nr   r9   /echo_multi_jsonr,   r`   s      r
   test_parse_json_listz#CommonTestCase.test_parse_json_list   s9    WI&06G92EFKKxW	
Wr   c                 R    |j                  dddid      }|j                  dk(  sJ y )Nrh   r   r9   TrK   rM   rN   r>   s      r
   )test_parse_json_list_error_malformed_dataz8CommonTestCase.test_parse_json_list_error_malformed_data   s7     1   
 #%%%r   c                 R    d}|j                  dd|i      j                  d|ik(  sJ y )Nu   øˆƒ£ºº∆ƒˆ∆r+   r   r,   )r	   r   texts      r
   #test_parse_json_with_nonascii_charsz2CommonTestCase.test_parse_json_with_nonascii_chars   s1    '  ~>CCPT~UUUr   c                 ~    |j                  dddddd      }|j                  dk(  sJ |j                  dd	gik(  sJ y )
Nr+      application/jsonAcceptContent-TypeTheadersrL     r   Invalid JSON body.r(   rO   r   r>   s      r
   "test_parse_json_with_nonutf8_charsz1CommonTestCase.test_parse_json_with_nonutf8_chars   sV    ll1CUV	  
 #%%%xxF%9$:;;;;r   c                 R    |j                  dddid      }|j                  dk(  sJ y )Nr+   r   bTrK   rM   rN   r>   s      r
   *test_validation_error_returns_422_responsez9CommonTestCase.test_validation_error_returns_422_response   s/    vsm4P#%%%r   c                 R    |j                  dddid      }|j                  dk(  sJ y )Nz/errorrm   fooTrK   rM   rN   r>   s      r
   :test_user_validation_error_returns_422_response_by_defaultzICommonTestCase.test_user_validation_error_returns_422_response_by_default   s/    65/N#%%%r   c                 H    |j                  d      j                  ddik(  sJ y )Nz/echo_use_args?name=Fredr   r   r    r"   s     r
   test_use_args_decoratorz&CommonTestCase.test_use_args_decorator   s%    {{56;;?OOOOr   c                 V    d}|j                  |dz         }|j                  ddik(  sJ y )Nz"/echo_use_args_with_path_param/foo	?value=42value*   r    r	   r   urlr?   s       r
   test_use_args_with_path_paramz,CommonTestCase.test_use_args_with_path_param   s0    2kk#+,xxGR=(((r   c                     |j                  dddi      }|j                  dk(  sJ |j                  dddid      }|j                  dk(  sJ y )	Nz/echo_use_args_validatedr   +      )   TrK   rM   )r(   rO   )r	   r   results      r
   test_use_args_with_validationz,CommonTestCase.test_use_args_with_validation   s_    87B-H!!S(((&"T  
 !!S(((r   c                 H    |j                  d      j                  ddik(  sJ y )Nz/echo_use_kwargs?name=Fredr   r   r    r"   s     r
   test_use_kwargs_decoratorz(CommonTestCase.test_use_kwargs_decorator   s%    {{78==&&AQQQQr   c                 V    d}|j                  |dz         }|j                  ddik(  sJ y )Nz$/echo_use_kwargs_with_path_param/foor   r   r   r    r   s       r
   test_use_kwargs_with_path_paramz.CommonTestCase.test_use_kwargs_with_path_param   s0    4kk#+,xxGR=(((r   c                 T    |j                  dddi      }|j                  ddik(  sJ y )Nz/echo_headersr   r   rv   r    r>   s      r
   test_parsing_headersz#CommonTestCase.test_parsing_headers   s0    kk/FF3CkDxxFF++++r   c                 p    |j                  dd       |j                  d      }|j                  ddik(  sJ y )Nr   r9   z/echo_cookie)
set_cookier!   r   r>   s      r
   test_parsing_cookiesz#CommonTestCase.test_parsing_cookies   s7    67+kk.)xxFG,,,,r   c                 ^    |j                  dddddi      }|j                  ddddik(  sJ y )Nz/echo_nestedr   r9   r_   )firstlastr,   r>   s      r
   test_parse_nested_jsonz%CommonTestCase.test_parse_nested_json   s?    Vw%HI
 xxFgw$GHHHHr   c                 b    dddddddgi}|j                  d|      }|j                  |k(  sJ y )NusersrJ   r   )idr      bar/echo_nested_manyr,   r	   r   in_datar?   s       r
   test_parse_nested_many_jsonz*CommonTestCase.test_parse_nested_many_json   s@    Au5a7OPQ 3W=xx7"""r   c                 N    i }|j                  d|      }|j                  i k(  sJ y )Nr   r,   r   s       r
   test_parse_nested_many_missingz-CommonTestCase.test_parse_nested_many_missing   s*     3W=xx2~~r   c                 z    |j                  ddt        j                  dd      i      }|j                  ddik(  sJ y )Nz
/echo_filemyfilez
README.rsts   datarE   )r(   r   Uploadr   r>   s      r
   test_parse_fileszCommonTestCase.test_parse_files   s>    ll8W^^L'%JK
 xxHf----r   c                 n    |j                  d      }|j                  dk(  sJ |j                  ddik(  sJ y )Nr+   r   r   r1   ry   r>   s      r
   test_empty_jsonzCommonTestCase.test_empty_json   s9    ll<(#%%%xxFG,,,,r   c                 z    |j                  ddddd      }|j                  dk(  sJ |j                  ddik(  sJ y )	Nr+   r0   rq   rr   r   r   r   r1   ry   r>   s      r
   test_empty_json_with_headersz+CommonTestCase.test_empty_json_with_headers   sO    ll1CUV  

 #%%%xxFG,,,,r   c                 ~    |j                  dddddd      }|j                  dk(  sJ |j                  dd	gik(  sJ y )
Nr+   z{"foo": "bar", }rq   rr   Tru   rw   r   rx   ry   r>   s      r
   test_invalid_jsonz CommonTestCase.test_invalid_json   sV    ll1CUV	  
 #%%%xxF%9$:;;;;r   )pathpayloadr;   r+   r   r   z!application/x-www-form-urlencodedr%   rq   c                 V    |j                  ||d|i      }|j                  ddik(  sJ y )Nrt   r   r   r1   r'   )r	   r   r   r   r;   r?   s         r
   test_content_type_mismatchz)CommonTestCase.test_content_type_mismatch   s4     ll4><2PlQxxFG,,,,r   N)7__name__
__module____qualname____doc__r   r   r   r   pytestfixturer   r#   r)   r.   r2   r5   r7   r@   rB   rF   rH   rP   rR   rV   rX   rZ   r\   rb   rd   rf   ri   rk   rn   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   markparametrizer   r=   r   r   r   r
   r   r      sd   >$ V^^'"  # 
GS

HP>--$
M&&&*&HQF

&V
	<&&P)
)R)
,-
I#
.--< [[+ 

FE?+3
 FE?,>?	

-
-r   r   )r   r   r   webargs.corer   r   r   r   r
   <module>r      s!      |- |-r   