ArvindSelvaraj
commited on
Commit
•
62dd117
1
Parent(s):
16d25e5
Update backend.py
Browse files- backend.py +53 -7
backend.py
CHANGED
@@ -4,7 +4,7 @@ import requests
|
|
4 |
import html # For escaping HTML characters
|
5 |
from bs4 import BeautifulSoup
|
6 |
import pandas as pd # Added pandas for Excel export
|
7 |
-
from openai import OpenAI
|
8 |
|
9 |
# Initialize OpenAI API with Nvidia's Llama model
|
10 |
client = OpenAI(
|
@@ -87,13 +87,59 @@ def generate_testcases(user_story):
|
|
87 |
return []
|
88 |
|
89 |
def export_test_cases(test_cases):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
if not test_cases:
|
91 |
return "No test cases to export."
|
92 |
|
93 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
output = io.BytesIO()
|
95 |
-
df =
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
return output.getvalue()
|
|
|
4 |
import html # For escaping HTML characters
|
5 |
from bs4 import BeautifulSoup
|
6 |
import pandas as pd # Added pandas for Excel export
|
7 |
+
from openai import OpenAI
|
8 |
|
9 |
# Initialize OpenAI API with Nvidia's Llama model
|
10 |
client = OpenAI(
|
|
|
87 |
return []
|
88 |
|
89 |
def export_test_cases(test_cases):
|
90 |
+
"""
|
91 |
+
Exports the test cases to an Excel file with specific columns:
|
92 |
+
- Test Case
|
93 |
+
- Preconditions
|
94 |
+
- Steps
|
95 |
+
- Expected Result
|
96 |
+
|
97 |
+
:param test_cases: A list of test case dictionaries or raw text.
|
98 |
+
:return: Bytes of the Excel file.
|
99 |
+
"""
|
100 |
if not test_cases:
|
101 |
return "No test cases to export."
|
102 |
|
103 |
+
# Define the structure of the Excel file
|
104 |
+
formatted_test_cases = []
|
105 |
+
|
106 |
+
for case in test_cases:
|
107 |
+
# Assuming each test case is a dictionary with 'test_case' content or similar
|
108 |
+
test_case_content = case.get('test_case', '')
|
109 |
+
|
110 |
+
# Split the content into separate sections (you might need to adjust based on actual output structure)
|
111 |
+
lines = test_case_content.split('\n')
|
112 |
+
test_case = ""
|
113 |
+
preconditions = ""
|
114 |
+
steps = ""
|
115 |
+
expected_result = ""
|
116 |
+
|
117 |
+
for line in lines:
|
118 |
+
if "Preconditions" in line:
|
119 |
+
preconditions = line.replace("Preconditions:", "").strip()
|
120 |
+
elif "Steps" in line:
|
121 |
+
steps = line.replace("Steps:", "").strip()
|
122 |
+
elif "Expected Result" in line:
|
123 |
+
expected_result = line.replace("Expected Result:", "").strip()
|
124 |
+
else:
|
125 |
+
# Default to putting the first part as the "Test Case"
|
126 |
+
if not test_case:
|
127 |
+
test_case = line.strip()
|
128 |
+
|
129 |
+
# Append to formatted test cases list
|
130 |
+
formatted_test_cases.append({
|
131 |
+
'Test Case': test_case,
|
132 |
+
'Preconditions': preconditions,
|
133 |
+
'Steps': steps,
|
134 |
+
'Expected Result': expected_result
|
135 |
+
})
|
136 |
+
|
137 |
+
# Convert the list of dictionaries into a DataFrame
|
138 |
+
df = pd.DataFrame(formatted_test_cases)
|
139 |
+
|
140 |
+
# Create an Excel file using pandas
|
141 |
output = io.BytesIO()
|
142 |
+
df.to_excel(output, index=False, engine='openpyxl') # Export to Excel without index
|
143 |
+
output.seek(0) # Rewind the buffer to the beginning
|
144 |
+
|
145 |
+
return output.getvalue()
|
|