ArvindSelvaraj
commited on
Update backend.py
Browse files- backend.py +5 -3
backend.py
CHANGED
@@ -4,7 +4,7 @@ import io
|
|
4 |
import requests
|
5 |
import html # For escaping HTML characters
|
6 |
from bs4 import BeautifulSoup
|
7 |
-
|
8 |
|
9 |
# Initialize OpenAI API with Nvidia's Llama model
|
10 |
client = OpenAI(
|
@@ -89,7 +89,6 @@ def generate_testcases(user_story):
|
|
89 |
print(f"API request failed: {str(e)}")
|
90 |
return []
|
91 |
|
92 |
-
# Add options for multiple test case formats
|
93 |
def export_test_cases(test_cases, format='json'):
|
94 |
if not test_cases:
|
95 |
return "No test cases to export."
|
@@ -110,7 +109,6 @@ def export_test_cases(test_cases, format='json'):
|
|
110 |
else:
|
111 |
raise ValueError("Test cases must be a list of dictionaries for CSV export.")
|
112 |
|
113 |
-
# 2. Save test cases as a downloadable file
|
114 |
def save_test_cases_as_file(test_cases, format='json'):
|
115 |
if not test_cases:
|
116 |
return "No test cases to save."
|
@@ -123,6 +121,10 @@ def save_test_cases_as_file(test_cases, format='json'):
|
|
123 |
dict_writer = csv.DictWriter(file, fieldnames=test_cases[0].keys())
|
124 |
dict_writer.writeheader()
|
125 |
dict_writer.writerows(test_cases)
|
|
|
|
|
|
|
|
|
126 |
else:
|
127 |
return f"Unsupported format: {format}"
|
128 |
return f'{format} file saved'
|
|
|
4 |
import requests
|
5 |
import html # For escaping HTML characters
|
6 |
from bs4 import BeautifulSoup
|
7 |
+
import pandas as pd # Add pandas for Excel export
|
8 |
|
9 |
# Initialize OpenAI API with Nvidia's Llama model
|
10 |
client = OpenAI(
|
|
|
89 |
print(f"API request failed: {str(e)}")
|
90 |
return []
|
91 |
|
|
|
92 |
def export_test_cases(test_cases, format='json'):
|
93 |
if not test_cases:
|
94 |
return "No test cases to export."
|
|
|
109 |
else:
|
110 |
raise ValueError("Test cases must be a list of dictionaries for CSV export.")
|
111 |
|
|
|
112 |
def save_test_cases_as_file(test_cases, format='json'):
|
113 |
if not test_cases:
|
114 |
return "No test cases to save."
|
|
|
121 |
dict_writer = csv.DictWriter(file, fieldnames=test_cases[0].keys())
|
122 |
dict_writer.writeheader()
|
123 |
dict_writer.writerows(test_cases)
|
124 |
+
elif format == 'excel':
|
125 |
+
# Use pandas to export the test cases to Excel
|
126 |
+
df = pd.DataFrame(test_cases)
|
127 |
+
df.to_excel('test_cases.xlsx', index=False)
|
128 |
else:
|
129 |
return f"Unsupported format: {format}"
|
130 |
return f'{format} file saved'
|