
    	]jX	                     x    d Z ddlZddlZddlZddlmZmZmZmZ d Z	g dZ
d Z G d de      Z G d	 d
e      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)HttpUserTaskSetbetweentaskc                 j    t         j                  dj                  fdt        |       D              S )z(Generate a random string of fixed length c              3   H   K   | ]  }t        j                          y wN)randomchoice).0iletterss     Y/root/env/lib/python3.12/site-packages/label_studio/tests/loadtests/locustfile_collabs.py	<genexpr>zrandomString.<locals>.<genexpr>   s     Ga6==)Gs   ")stringascii_lowercasejoinrange)stringLengthr   s    @r   randomStringr   
   s(    $$G77G53FGGG    )PersonOrganizationFactMoneyDateTimeOrdinalPercentProductLanguageLocationc           
      L   t        j                  dt        |             }t        t        |       |t        j                  dd      z         }g }t	        t        j                  dd            D ]4  }|j                  dddt        j                  t              g||d	d
       6 |S )Nr            
   labelsnertext)r)   startend)type	from_nameto_namevalue)r   randintlenminr   appendr   
all_labels)r+   r,   r-   resultsr   s        r   
get_resultr8      s    NN1c$i(E
c$i2!66
7CG6>>!R() 
 "!%+]]:%>$?%X[\		

 Nr   c                   J    e Zd Zd Z ed      d        Z ed      d        Zy)UserWorksWithProjectc                     | j                   j                  d      }|j                         }t        j                  |      | _        y )Nz/api/annotator/projects)clientgetjsonr   r   
project_id)selfrall_projectss      r   on_startzUserWorksWithProject.on_start0   s0    KKOO56vvx --5r   d   c                 "   | j                   j                  d| j                  z  d      }|j                         }|d   }|d   d   }t	        |      }t        j
                  d|i      }dd	i}| j                   j                  d
|z  ||d       y )Nz/api/projects/%i/next/z/api/projects/<id>/next)nameiddatar+   resultzcontent-typezapplication/jsonz/api/tasks/%i/annotationsz/api/tasks/<id>/annotations)headersrF   )r<   r=   r?   r>   r8   dumpspost)r@   rA   r   task_id	task_textr7   payloadrJ   s           r   complete_task_via_apiz*UserWorksWithProject.complete_task_via_api5   s    KKOO4tFMfOgvvxt*L(	Y'**h01!#56''17GRo 	 	
r   r'   c                 $    | j                          y r
   )	interruptr@   s    r   stopzUserWorksWithProject.stopB   s    r   N)__name__
__module____qualname__rC   r   rP   rT    r   r   r:   r:   /   s7    6
 
#Y

 

 
!W r   r:   c                   2    e Zd Z edd      ZediZd Zd Zy)WebsiteUserr%   	   r(   c                 $    | j                          y r
   )loginrS   s    r   rC   zWebsiteUser.on_startL   s    

r   c                     | j                   j                  d      }|j                  d   }d}dt        j                  d|       ddd}| j                   j                  d	|d
|i       y )N/	csrftokenrD   collab_r   z@loadtests.me	123456789)emailpasswordz/annotator/loginzX-CSRFToken)rJ   )r<   r=   cookiesr   r2   rL   )r@   responser`   num_collabsrO   s        r   r]   zWebsiteUser.loginO   sh    ;;??3'$$[1	%fnnQ&D%E]Salm+W}i>XYr   N)	rU   rV   rW   r   	wait_timer:   tasksrC   r]   rX   r   r   rZ   rZ   G   s"    1I!2&EZr   rZ   )__doc__r>   r   r   locustr   r   r   r   r   r6   r8   r:   rZ   rX   r   r   <module>rl      sE       3 3H
 7 0Z( Zr   