
    	]jE                     ~    d dl Z d dlmZ e j                  j                  Zd dlmZ d dlm	Z	 d dl
mZmZ d Zd Zd Zy)	    N)LABEL_CONFIG_AND_TASKS)LabelStudio)LabelInterface)PredictionValue	TaskValuec                    t        | |j                        }t        t        d         }|j                  j                  d|j                        }|j                  j                  |j                  ddi      }t        |j                  d      j                  d	g      gd
d      } |j                  j
                  dd|j                  i|j                         }|j                  j                  |j                        }|j                  d   d   d   d	gk(  sJ |j                   d
k(  sJ |j"                  dk(  sJ t        |j                  d      j                  dg      |j                  d      j                  dg      gdd      } |j                  j
                  dd|j                  i|j                         }|j                  j%                  |j                        }	t'        |	      dk(  sJ |j                  j)                  |j                         |j                  j%                  |j                        }	t'        |	      dk(  sJ |	d   j                  |j                  k(  sJ y )Nbase_urlapi_keylabel_configNew Projecttitler   my_textz	Test taskprojectdatasentiment_classPositiveg?z1.0.0resultscoremodel_versiontaskidr   valuechoicesNeutralNegativeg?z1.0.1r          )r   r   r   r   projectscreateconfigtasksr   r   get_controllabelpredictions
model_dumpgetr   r   r   listlendelete)
django_live_urlbusiness_clientlslipr   pv
predictionanother_predictionr+   s
             Q/root/env/lib/python3.12/site-packages/label_studio/tests/sdk/test_predictions.pytest_predictions_CRUDr:      s;   	o7N7N	OB	.~>	?B
RYYGA88??144y+.F?GD 
0177EF
B
 '&& WW
--/J ##z}}#5JQ(3
|CCCs"""##w... 
NN,-33YK@NN,-33ZLA
 
B /..ODGGOr}}O ..%%477%3K{q    NNZ]]+..%%477%3K{q   q> 2 5 5555    c                     t        | |j                        }t        t        d         }|j                  j                  d|j                        }|j                  j                  |j                  ddddd	dd
ddgdg       g }|j                  j                  |j                        D ]Q  }t        |j                  j                  |j                              dk(  sJ |j                  |j                         S t        |      dk(  sJ t        ddit        |j!                  d      j#                  dg      gdd      g      }t        ddit        |j!                  d      j#                  d	g      gdd      g      }|j                  j                  |j                  |j%                         |j%                         g       |j                  j                  |j                        D ]v  }|j                  j                  |j                        }	t        |	      dk(  sJ |j                  |vsH|	d   j&                  dk(  sJ |j                  |j                         x t        |      dk(  sJ |j&                  dk(  sJ |j                  j)                  |j                  d       |j                  j+                  |j                        }
|
j&                  dk(  sJ ddlm} t1        j2                  |      5 }|j                  j)                  |j                  d       d d d        j4                  j6                  dk(  sJ |j4                  j8                  d    d!   d   j;                  d"      sJ y # 1 sw Y   UxY w)#Nr	   r   r   r   zHello worldr   )r   r   zGoodbye Label Studior    zWhat a beautiful dayr   )r   requestpreannotated_from_fields)r   r!   r#      r   gffffff?z3.4.5r   )r   r+   g333333?r   r=   r       )r   r   r   )ApiErrorz3.4.6i  validation_errorsr   zModel version doesn't exist)r   r   r   r   r%   r&   r'   import_tasksr   r(   r.   r/   r+   appendr   r   r)   r*   r,   r   updater-   label_studio_sdk.core.api_errorrC   pytestraisesr   status_codebody
startswith)r1   r2   r3   r4   r5   task_idsr   task1task2r+   r   rC   es                r9   #test_create_predictions_with_importrR   :   s<   	o7N7N	OB	.~>	?B
RYYGA KK44%*E.:N.:N

 #4!4   Hadd+ !2>>&&DGG&45::: ! x=A ''89??MN%
	E /0'89??MN%
	E KK44!!#U%5%5%78   add+ %nn))tww)7;1$$$77("q>//7:::OODGG$% x=A ??b   KK!$$g6kkooo&G  G+++ 9	x	  ;A
add':;77#%%%77<<+,_=a@KKLijjj; ;s   (NNc                    t        | |j                        }t        t        d         }|j                  j                  d|j                        }|j                  j                  |j                  ddi      }g d}d	gd
gdgg}g }t        ||      D ]-  \  }	}
|j                  dddd|
idg|	d|j                  d       / |j                  j                  |j                  |      }|j                  dk(  sJ |j                  j                  |j                        }t        |      dk(  sJ t!        |D cg c]  }|j"                   c}      }|t!        |      k(  sJ yc c}w )a
  Import multiple predictions via projects.import_predictions

    Purpose:
    - Verify that the bulk predictions import endpoint creates predictions for a project

    Setup:
    - Create a project with a simple text classification config
    - Create one task in the project

    Actions:
    - Call ls.projects.import_predictions with three predictions for the same task

    Validations:
    - API returns created == 3
    - Listing predictions for the task returns exactly three items with expected model versions
    r	   r   zPredictions Import Projectr   r   zClassify this sentencer   )zhumor__gpt-5-minizhumor__gpt-4.1-minizhumor__gpt-4o-minir   r   r    r   messager   )	from_nameto_nametyper   r#   )r   r   r   r   r@   r?   r!   N)r   r   r   r   r%   r&   r'   r(   r   ziprF   import_predictionscreatedr+   r.   r/   sortedr   )r1   r2   r3   r4   r   r   model_versionsr   predictions_payloadmvchresponsepredsr5   returned_versionss                  r9    test_projects_import_predictionsrc      sn   $ 
o7N7N	OB	.~>	?Bkk  'CRTR[R[ \G88??7::Y@X4Y?ZDWN|i[:,7Gng. 
B"" &7#, )"+R	 "$	

" {{--EX-YHq   NNTWW-Eu:???A?@~ 6666  @s   ;E&)rI   label_studio.tests.sdk.commonr   mark	django_db
pytestmarklabel_studio_sdk.clientr    label_studio_sdk.label_interfacer   (label_studio_sdk.label_interface.objectsr   r   r:   rR   rc   r$   r;   r9   <module>rk      s6     @[[""
 / ; O,6^HkV37r;   