ArvindSelvaraj
commited on
Commit
•
439d8a3
1
Parent(s):
3aaa8da
init
Browse files- backend.py +59 -13
backend.py
CHANGED
@@ -16,15 +16,9 @@ def clean_test_case_output(text):
|
|
16 |
"""
|
17 |
Cleans the output to handle HTML characters and unwanted tags.
|
18 |
"""
|
19 |
-
# Unescape HTML entities
|
20 |
-
|
21 |
-
|
22 |
-
# Use BeautifulSoup to handle HTML tags more comprehensively
|
23 |
-
soup = BeautifulSoup(text, 'html.parser')
|
24 |
-
|
25 |
-
# Convert <br> tags to newlines and remove all other tags
|
26 |
-
cleaned_text = soup.get_text(separator="\n").strip()
|
27 |
-
|
28 |
return cleaned_text
|
29 |
|
30 |
def generate_testcases(user_story):
|
@@ -36,12 +30,65 @@ def generate_testcases(user_story):
|
|
36 |
:param user_story: A string representing the user story for which to generate test cases.
|
37 |
:return: A list of test cases in the form of dictionaries.
|
38 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
try:
|
40 |
-
#
|
41 |
completion = client.chat.completions.create(
|
42 |
model="nv-mistralai/mistral-nemo-12b-instruct", # Using Mistral model
|
43 |
messages=[
|
44 |
-
{"role": "user", "content":
|
45 |
],
|
46 |
temperature=0.06, # Further lowering temperature for precise and deterministic output
|
47 |
top_p=0.5, # Prioritize high-probability tokens even more
|
@@ -81,6 +128,7 @@ def generate_testcases(user_story):
|
|
81 |
except requests.exceptions.RequestException as e:
|
82 |
print(f"API request failed: {str(e)}")
|
83 |
return []
|
|
|
84 |
# Add options for multiple test case formats
|
85 |
def export_test_cases(test_cases, format='json'):
|
86 |
if not test_cases:
|
@@ -93,7 +141,6 @@ def export_test_cases(test_cases, format='json'):
|
|
93 |
# Improve JSON export to be line-by-line formatted
|
94 |
return json.dumps(test_cases, indent=4, separators=(',', ': ')) # More readable format
|
95 |
elif format == 'csv':
|
96 |
-
# Check if test_cases is a list of dicts
|
97 |
if isinstance(test_cases, list) and isinstance(test_cases[0], dict):
|
98 |
output = io.StringIO()
|
99 |
csv_writer = csv.DictWriter(output, fieldnames=test_cases[0].keys(), quoting=csv.QUOTE_ALL)
|
@@ -119,4 +166,3 @@ def save_test_cases_as_file(test_cases, format='json'):
|
|
119 |
else:
|
120 |
return f"Unsupported format: {format}"
|
121 |
return f'{format} file saved'
|
122 |
-
|
|
|
16 |
"""
|
17 |
Cleans the output to handle HTML characters and unwanted tags.
|
18 |
"""
|
19 |
+
text = html.unescape(text) # Unescape HTML entities
|
20 |
+
soup = BeautifulSoup(text, 'html.parser') # Use BeautifulSoup to handle HTML tags
|
21 |
+
cleaned_text = soup.get_text(separator="\n").strip() # Remove tags and handle newlines
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return cleaned_text
|
23 |
|
24 |
def generate_testcases(user_story):
|
|
|
30 |
:param user_story: A string representing the user story for which to generate test cases.
|
31 |
:return: A list of test cases in the form of dictionaries.
|
32 |
"""
|
33 |
+
|
34 |
+
# Few-shot learning examples to guide the model
|
35 |
+
few_shot_examples = """
|
36 |
+
Example 1:
|
37 |
+
User Story:
|
38 |
+
Ensure the "Key Details" feature is enabled in the backend.
|
39 |
+
1. Open the Tech 360 app.
|
40 |
+
2. Click on the Search tab.
|
41 |
+
3. Enter the account number and click on Enter.
|
42 |
+
4. Choose the account from the Search result.
|
43 |
+
5. Verify that the "Key Details" button is displayed under the recommendation section.
|
44 |
+
6. Clicking on "Key Details" should navigate to the key details screen.
|
45 |
+
|
46 |
+
Test Case:
|
47 |
+
Test Case: Verify "Key Details" Feature in Tech 360 App
|
48 |
+
Steps:
|
49 |
+
1. Launch the Tech 360 app.
|
50 |
+
2. Go to the Search tab.
|
51 |
+
3. Enter a valid account number and click Enter.
|
52 |
+
4. Select an account from the search results.
|
53 |
+
5. Ensure the "Key Details" button is displayed under the recommendation section.
|
54 |
+
6. Click on "Key Details" and verify that it navigates to the Key Details screen.
|
55 |
+
Expected Result: User is navigated to the Key Details screen successfully.
|
56 |
+
|
57 |
+
Example 2:
|
58 |
+
User Story:
|
59 |
+
Open the Tech 360 app. Go On-Job on a Wi-Fi Ready Preinstall Job. Wait for PHT to finish. Go to the Device Details Page for XB7 and ONU.
|
60 |
+
|
61 |
+
Test Case:
|
62 |
+
Test Case: Verify Device Details Page for XB7 and ONU in Wi-Fi Ready Preinstall Job
|
63 |
+
Steps:
|
64 |
+
1. Launch the Tech 360 app.
|
65 |
+
2. Go On-Job on a Wi-Fi Ready Preinstall Job.
|
66 |
+
3. Wait for PHT to finish.
|
67 |
+
4. Navigate to the Device Details Page for XB7 and ONU.
|
68 |
+
Expected Result: Device details for XB7 and ONU are displayed correctly.
|
69 |
+
|
70 |
+
Example 3:
|
71 |
+
User Story:
|
72 |
+
Open the Tech 360 app. Go On-Job on a Wi-Fi Ready Preinstall Job. Initiate Add/Remove/Swap Flows for ONU and XB7.
|
73 |
+
|
74 |
+
Test Case:
|
75 |
+
Test Case: Verify Add/Remove/Swap Flows for ONU and XB7 in Wi-Fi Ready Preinstall Job
|
76 |
+
Steps:
|
77 |
+
1. Launch the Tech 360 app.
|
78 |
+
2. Go On-Job on a Wi-Fi Ready Preinstall Job.
|
79 |
+
3. Initiate Add/Remove/Swap flows for ONU and XB7.
|
80 |
+
Expected Result: Add/Remove/Swap flows for ONU and XB7 are initiated and processed successfully.
|
81 |
+
"""
|
82 |
+
|
83 |
+
# Combine the few-shot examples with the user story for the model to process
|
84 |
+
prompt = few_shot_examples + f"\nUser Story: {user_story}\n"
|
85 |
+
|
86 |
try:
|
87 |
+
# Call the Nvidia Mistral API with the refined prompt
|
88 |
completion = client.chat.completions.create(
|
89 |
model="nv-mistralai/mistral-nemo-12b-instruct", # Using Mistral model
|
90 |
messages=[
|
91 |
+
{"role": "user", "content": prompt}
|
92 |
],
|
93 |
temperature=0.06, # Further lowering temperature for precise and deterministic output
|
94 |
top_p=0.5, # Prioritize high-probability tokens even more
|
|
|
128 |
except requests.exceptions.RequestException as e:
|
129 |
print(f"API request failed: {str(e)}")
|
130 |
return []
|
131 |
+
|
132 |
# Add options for multiple test case formats
|
133 |
def export_test_cases(test_cases, format='json'):
|
134 |
if not test_cases:
|
|
|
141 |
# Improve JSON export to be line-by-line formatted
|
142 |
return json.dumps(test_cases, indent=4, separators=(',', ': ')) # More readable format
|
143 |
elif format == 'csv':
|
|
|
144 |
if isinstance(test_cases, list) and isinstance(test_cases[0], dict):
|
145 |
output = io.StringIO()
|
146 |
csv_writer = csv.DictWriter(output, fieldnames=test_cases[0].keys(), quoting=csv.QUOTE_ALL)
|
|
|
166 |
else:
|
167 |
return f"Unsupported format: {format}"
|
168 |
return f'{format} file saved'
|
|