
    p[i                         d Z ddlmZ ddlmZ ddlm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y)z0Tests for client behavior when issuing requests.   )_api_client)Client)typesc                 :    | j                  dd       t               S )NGOOGLE_API_KEYgoogle_api_key)setenvr   monkeypatchs    g/mnt/data/GridWatch/venv/lib/python3.12/site-packages/google/genai/tests/client/test_client_requests.pybuild_test_clientr      s    %'78	/    c                  B    d} d}t        j                  | |      dk(  sJ y )Nhttps://fake-url.com/some_path//v1beta/models,https://fake-url.com/some_path/v1beta/models
api_clientjoin_url_pathbase_urlpaths     r   Ktest_join_url_path_base_url_with_trailing_slash_and_path_with_leading_slashr      s.    .(	$x.	788r   c                  B    d} d}t        j                  | |      dk(  sJ y )Nr   v1beta/modelsr   r   r   s     r   Stest_join_url_path_with_base_url_with_trailing_slash_and_path_without_leading_slashr   &   s.    .(	$x.	788r   c                  B    d} d}t        j                  | |      dk(  sJ y )Nhttps://fake-url.com/some_pathr   r   r   r   s     r   Stest_join_url_path_with_base_url_without_trailing_slash_and_path_with_leading_slashr   /   s.    -(	$x.	788r   c                  B    d} d}t        j                  | |      dk(  sJ y )Nr   r   r   r   r   s     r   Vtest_join_url_path_with_base_url_without_trailing_slash_and_path_without_leading_slashr!   8   s.    -(	$x.	788r   c                  B    d} d}t        j                  | |      dk(  sJ y )Nzhttps://fake-url.com/r   "https://fake-url.com/v1beta/modelsr   r   s     r   <test_join_url_path_base_url_without_path_with_trailing_slashr$   A   s.    $(	$x.	-..r   c                  B    d} d}t        j                  | |      dk(  sJ y )Nzhttps://fake-url.comr   r#   r   r   s     r   ?test_join_url_path_base_url_without_path_without_trailing_slashr&   J   s.    #(	$x.	-..r   c                    t        |       j                  j                  }|j                  ddddi      }d|j                  d   v sJ d|j                  d   v sJ d|j                  d   v sJ d|j                  d   v sJ y )	NGET	test/pathkeyvaluegoogle-genai-sdk/
user-agent
gl-python/x-goog-api-client)r   modelsr   _build_requestheadersr   request_clientrequests      r   /test_build_request_sets_library_version_headersr6   S   s    $[188DD.))%ug>NO'	 =	==	=	6	66	6	0C D	DD	D	)<=	==	=r   c                 6   t        |       j                  j                  }|j                  ddddit	        j
                  ddddi	            }d|j                  d   v sJ d
|j                  d   v sJ d|j                  d   v sJ d
|j                  d   v sJ y )Nr(   r)   r*   r+   test/url1r-   ztest-user-agentr   api_versionr2   r,   r.   r/   r   r0   r   r1   r   HttpOptionsDictr2   r3   s      r   0test_build_request_appends_to_user_agent_headersr>   \   s    $[188DD.))g!23		' 
gool;	;;	;	 =	==	=	6	66	6	0C D	DD	Dr   c                 6   t        |       j                  j                  }|j                  ddddit	        j
                  ddddi	            }d
|j                  d   v sJ d|j                  d   v sJ d
|j                  d   v sJ d|j                  d   v sJ y )Nr(   r)   r*   r+   r8   r9   r/   ztest-goog-api-clientr:   r,   r-   r.   r<   r3   s      r   5test_build_request_appends_to_goog_api_client_headersr@   n   s    $[188DD.))g&(>?		' 
 =	==	=	7??3F#G	GG	G	0C D	DD	D	)<=	==	=r   c           
      r   i }t        j                  |       d|d   v sJ t        |       j                  j                  }|j                  ddddit        j                  dd|	            }d|j                  d   v sJ d
|j                  d   v sJ d|j                  d   v sJ d
|j                  d   v sJ y )Nr,   r-   r(   r)   r*   r+   r8   r9   r:   r.   r/   )	r   append_library_version_headersr   r0   r   r1   r   r=   r2   )r   headers_to_injectr4   r5   s       r   ,test_build_request_keeps_sdk_version_headersrD      s    ++,=>	 1, ?	??	?$[188DD.))g#		' 
 =	==	=	)<=	==	=	0C D	DD	D	)<=	==	=r   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       t        dt        j                  dt        j                  j
                  	      
      }|j                  j                  j                  ddddi      }|j                  dk(  sJ y )Nr   FraisingGEMINI_API_KEYGOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_LOCATIONThttps://custom-base-url.comr   base_url_resource_scopevertexaihttp_optionspost-publishers/google/models/gemini-3-pro-previewr*   r+   Ihttps://custom-base-url.com/publishers/google/models/gemini-3-pro-preview
delenvr   r   r=   ResourceScope
COLLECTIONr0   r   r1   urlr   clientr5   s      r   &test_build_request_with_resource_scoper[      s    %u5%u5+U;,e<((0"'"5"5"@"@& MM%%445g'
 
c	cc	cr   c           	         | j                  dd       | j                  dd       | j                  dd       | j                  dd       t        ddd	t        j                  d
t        j                  j
                              }|j                  j                  j                  ddddi      }|j                  dk(  sJ y )Nr   FrF   rH   rI   rJ   Tztest-projectztest-locationrK   rL   )rO   projectlocationrP   rQ   rR   r*   r+   rS   rT   rY   s      r   @test_build_request_with_resource_scope_with_project_and_locationr_      s     %u5%u5+U;,e<((0"'"5"5"@"@	& MM%%445g'
 
c	cc	cr   c                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       t        dt        j                  dd	d
i            S )Nr   FrF   rH   rI   rJ   TrK   AuthorizationzBearer fake_access_token)r   r2   rN   )rU   r   r   r=   r
   s    r   build_test_client_no_env_varsrb      s|    %u5%u5+U;,e<	((0"$>?
 r   c                     t        |       j                  j                  }|j                  ddddi      }|j                  dk(  sJ y )Nr(   r)   r*   r+   rK   )rb   r0   r   r1   rX   r3   s      r   3test_build_request_with_custom_base_url_no_env_varsrd      sP    #K077CC  ))g'
 
5	55	5r   N)__doc__ r   r   r   r   r   r   r   r   r!   r$   r&   r6   r>   r@   rD   r[   r_   rb   rd    r   r   <module>rh      sa   " 7 )  
>E$>$>*d,d6	6r   