U
    -h                     @   s   d dl mZ d dlmZ d dlmZmZmZmZ d dl	Z	e	j
e	jdd e	eZeedZeedd	d
Zdeeee ee dddZdS )    )OpenAI)OPENAI_API_KEY)OptionalListDictAnyNz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)levelformat)api_key)	test_typereturnc              	   C   sN   ddddddddddd	dd
dd	dddd	dddd	dd}| | i S )z.Get the configuration for a specific test typeZTC_FUNCzEfunctional test cases focusing on valid inputs and expected behaviors   )prefixdescriptioncountZTC_NEGzNnegative test cases focusing on invalid inputs, error handling, and edge casesZTC_UIz4UI test cases focusing on visual elements and layout   ZTC_UXzDuser experience test cases focusing on user interaction and workflowZ	TC_COMPATz@compatibility test cases across different browsers and platformsZTC_PERFz@performance test cases focusing on load times and responsiveness)Zdashboard_functionalZdashboard_negativeZdashboard_uiZdashboard_uxZdashboard_compatibilityZdashboard_performance)get)r   Zbase_configs r   9/var/www/html/testcasegenerator.evdpl.com/ai/generator.pyget_test_type_config   s4     r    )r   summaryselected_typesr   c                 C   s$  | st d dS |r"t|dkr0t d dS t d|  t d|  t dt|  d g }|D ]z}t d	|  t|}|st d
|  qnd| d|  d|d  d|d  d|d  d| d|d  d}zt d| d tjjj	ddd|d  d| d|d  ddd|dgd d!d"}|j
d jj }|r~t d#| d$ d%| d&| }	||	 nt d'| d W nF tk
r }
 z&t d(| d)t|
  W Y qnW 5 d}
~
X Y nX t d*|  qn|s t d+ dS t d,t| d- d&d&| S ).z0Generate test cases based on user-selected typesz0No description provided for test case generationNr   z/No test types selected for test case generationz!Generating test cases for types: z	Summary: zDescription length: z charactersz#Starting generation for test type: zSkipping unknown test type: z
        Task Title: z
        Task Description: z

        Generate EXACTLY r   z test cases for r   zA.
        
        For each test case:
        1. Use the prefix r   z!
        2. Focus exclusively on z scenarios
        3. Include detailed steps
        4. Specify expected results
        5. Do not mix with other test types

        Use this EXACT format for each test case:

        Title: a+  _[Number]_[Brief_Title]
        Scenario: [Detailed scenario description]
        Steps to reproduce:
        1. [Step 1]
        2. [Step 2]
        ...
        Expected Result: [What should happen]
        Actual Result: [To be filled during execution]
        Priority: [High/Medium/Low]
        zSending request to OpenAI for z test caseszgpt-4osystemz(You are a QA engineer. Generate EXACTLY  z test cases. Use z as the prefix.)Zrolecontentusergffffff?i  )modelmessagesZtemperatureZ
max_tokensz
Generated z test cases successfullyzTEST TYPE: z

zReceived empty response for zError generating z test cases: z$Completed generation for test type: z!Failed to generate any test casesz&Successfully generated test cases for z test types)loggererrorleninfor   warningclientZchatZcompletionscreatechoicesmessager   stripappend	Exceptionstrjoin)r   r   r   Zall_test_casesr   configpromptresponse
test_casesZtest_cases_with_headerer   r   r   generate_test_case1   st    



r2   )r   N)openair   config.settingsr   typingr   r   r   r   loggingbasicConfigINFO	getLogger__name__r   r$   r+   dictr   r2   r   r   r   r   <module>   s   

$