
    	]js'                     `   d Z ddl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 dd	lmZ ej                   d
        Z ej                   ddg      d        Zej&                  j)                  dddg      ej&                  j)                  ddddddfdddddgidfdddddgidfdddddgidfdddddfdddddfg      ej&                  j*                  d                       Zej&                  j)                  dddidd!fddiddgidfddiddgidfg      ej&                  j*                  d"               Z ej0                  d#      ej&                  j)                  d$d%g      ej&                  j*                  d&                      Zej&                  j*                  d'        Zy)(zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    N)mock)Project)Token)	APIClient)
Annotation   )ml_backend_mockc                     t         j                  j                  | j                  j                        }t               }|j                  d|j                  z          | j                  j                  |_
        ||fS )N)userToken )HTTP_AUTHORIZATION)r   objectsgetbusinessadminr   credentialskeyorganizationpkorganization_pk)business_clienttokenclients      E/root/env/lib/python3.12/site-packages/label_studio/tests/test_api.pyclient_and_tokenr      sd    MM?#;#;#A#ABE[F
(UYY*>?,99<<F5=    business_authorizeduser_with_token)paramsc                     |\  }}| j                   |d}| j                   dk(  r||d<   |S | j                   dk(  r||d<   |S )N)typer   r   r   r   )param)requestr   r   r   r   results         r   any_api_clientr%      sU    $MFEmme4F}}--*x M 
+	+!xMr   use_x_api_keyTFzpayload, response, status_code111z<View><Text name="my_text" value="$text"/><Choices name="my_class" toName="my_text"><Choice value="pos"/><Choice value="neg"/></Choices></View>)titlelabel_config   z<View><Text name="my_text" value="$text"/><Choices name="my_class" toName="unexisted"><Choice value="pos"/><Choice value="neg"/></Choices></View>r)   z>toName="unexisted" not found in names: ['my_class', 'my_text']  z~<View><Text name="my_text" value="$text"/><Choices name="my_class"><Choice value="pos"/><Choice value="neg"/></Choices></View>z6Validation failed on : 'toName' is a required propertyzcan only parse stringsz<View><Text name="my_text" value="$text"/><View className="non-root"><Choices name="my_class" toName="my_text"><Choice value="pos"/><Choice value="neg"/></Choices></View></View>a1  
                <View>
  
  <Header value="Search request" size="5"/> 
  <Text name="text" value="$text"/>
 
  <Header value="Generated responses" size="5"/> 
  <View className="dynamic_choices">
    <Choices name="dynamic_choices" toName="text" selection="checkbox" value="$options" layout="vertical" choice="multiple" allownested="true"/>
  </View>
  <View style="box-shadow: 2px 2px 5px #999; padding: 20px; margin-top: 1em; border-radius: 5px;">
    <Header value="Search Quality"/>
    <Rating name="relevance" toName="text"/>
  </View>
  <View style="box-shadow: 2px 2px 5px #999; padding: 15px 5px 10px 20px; margin-top: 1.5em; margin-bottom: 1.25em; border-radius: 5px; display: flex; align-items: center;">
    <Header value="Labeling Confidence" style="font-size: 1.25em"/>
    <View style="margin: 0 1em 0.5em 1.5em">
      <Choices name="confidence" toName="text" choice="single" showInLine="true">
        <Choice value="Low" html="&lt;img width='40' src='https://www.iconsdb.com/icons/preview/green/thumbs-up-xxl.png'/&gt;"/>
        <Choice value="High" html="&lt;img width='40' src='https://www.iconsdb.com/icons/preview/red/thumbs-down-xxl.png'/&gt;"/>
      </Choices>
    </View>
  </View>
  
  <Style>
  .searchresultsarea {
    margin-left: 10px;
    font-family: 'Arial';
  }
  .searchresult {
    margin-left: 8px;
  }
  .searchresult h2 {
    font-size: 19px;
    line-height: 18px;
    font-weight: normal;
    color: rgb(29, 1, 189);
    margin-bottom: 0px;
    margin-top: 25px;
  }
  .searchresult a {
    font-size: 14px;
    line-height: 14px;
    color: green;
    margin-bottom: 0px;
  }
  .searchresult button {
    font-size: 10px;
    line-height: 14px;
    color: green;
    margin-bottom: 0px;
    padding: 0px;
    border-width: 0px;
    background-color: white;
  }
  </Style>
</View>
                c           	         | \  }}|r|j                  |j                         |j                  |d<   t               5  |j	                  dt        j                  |      ddd| i      }d d d        j                  |k(  sJ |r2|j                         }|j                  dk(  r|d	   |k(  sJ y ||k(  sJ y y # 1 sw Y   OxY w)
N)HTTP_X_API_KEYr   /api/projects/application/jsonAuthorizationr   datacontent_typeheadersr+   validation_errors)r   r   r   r	   postjsondumpsstatus_code)	r   payloadresponser9   r&   r   r   rresponse_datas	            r   test_create_projectr>   $   s    b %MFE%))4!'!7!7G		 
KKG$+$ug&67	  

 ==K'''==C !45AAA H,,, 
 
s   .B99C   c                 ,   | \  }}|j                   |d<   |j                  d|j                   dt        j                  |      ddd| i      }|j
                  |k(  sJ |r2|j                         }|j
                  dk(  r|d	   |k(  sJ y ||k(  sJ y y )
Nr   r.   /r/   r0   r   r1   r+   r5   )r   patchidr7   r8   r9   )	r   configured_projectr:   r;   r9   r   r   r<   r=   s	            r   test_patch_projectrE      s    N %MFE!'!7!7G
+../q1ZZ ' F5'"23	 	 	A ==K'''==C !45AAA H,,, r   z"ml.serializers.validate_upload_urlzJexternal_status_code, current_active_ml_backend_url, ml_backend_call_count)r*   zhttp://my.super.ai   c           
      V   d|_         |\  }}t        j                         5 }	|}
|	j                  |
 dt	        j
                  ddi             |	j                  |
 dt	        j
                  ddi             |j                  d	t	        j
                  |j                  d
|
d      ddd| i      }|j                  |k(  sJ |	j                  sJ |	j                  |k(  sJ t        j                  j                  |j                        }|j                  j                         D 	cg c]  }	|	j                   }}	|D cg c]
  }||k(  s	| }}t!        |      dk(  sJ dj#                  |             | j%                  |
d       d d d        y c c}	w c c}w # 1 sw Y   y xY w)NFz/setupmodel_versionzVersion from My Super AI)textz/healthstatusUPz/api/mlzMy Super AI)projectr(   urlr/   r0   r   r1   )rC   r   
)block_local_urls)COLLECT_ANALYTICSrequests_mockMockerr6   r7   r8   r   rC   r9   called
call_countr   r   ml_backendsallrM   lenjoinassert_called_once_with)mock_validate_upload_urlr   rD   external_status_codecurrent_active_ml_backend_urlml_backend_call_countsettingsr   r   mmy_urlr<   rL   all_urlsrM   connected_mls                   r   'test_creating_activating_new_ml_backendrc      s   & "'H-OU				 Y1.	& tzz?D^2_'`a	 tzz8T2B'CD  (:(=(=^def+$ug&67	 ! 
 }} 4444xxx||4444//%%);)>)>%?#*#6#6#:#:#<=aAEE=='/X3:W3WXX< A%:tyy'::% 88RW8X%Y Y >X!Y Ys0   D
F+F>F
FF9F
FF(c                     | j                  d|j                   d       t        j                  j	                  |j                        j                         rJ y )Nr.   z/annotations/)task__project)deleterC   r   r   filterexists)r   rD   s     r   test_delete_annotationsri     sQ    ^,>,A,A+B-PQ!!((7I7L7L(MTTVVVVr   )__doc__r7   unittestr   pytestrQ   projects.modelsr   rest_framework.authtoken.modelsr   rest_framework.testr   tasks.modelsr   utilsr	   fixturer   r%   markparametrize	django_dbr>   rE   rB   rc   ri    r   r   <module>rw      s       # 1 ) # "   -/@AB C 4-8$
  !r 	
  !t `ab	
  !a VWX	
 $	/.C[B\1]_bc  !T 	
 9!<z @	
Sjm\ - ]m 9`-. $
   !r 	
$   !t `ab	
   !a VWX	
5!$J - K$L-$ 01P&  Y  2 YF W Wr   