Skip to content

Commit d7f1626

Browse files
author
Jakub Klimczak
committed
api: Implement fetching list of test suites in file
1 parent e3c0b7d commit d7f1626

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

protoplaster/api/v1/configs.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from email.utils import format_datetime
44
from datetime import datetime, timezone
55
from werkzeug.utils import secure_filename
6+
from protoplaster.runner.runner import create_test_file
7+
import copy
68

79
configs_blueprint: Blueprint = Blueprint("protoplaster-configs", __name__)
810

@@ -207,6 +209,37 @@ def fetch_config_file(config_name: str):
207209
mimetype="text/yaml")
208210

209211

212+
@configs_blueprint.route("/api/v1/configs/<string:config_name>/test-suites")
213+
def fetch_test_suites(config_name: str):
214+
"""Fetch list of test suites in config file
215+
216+
:status 200: no error
217+
:status 404: config does not exist
218+
219+
:>json array: list of test suites
220+
221+
**Example Request**
222+
223+
.. sourcecode:: http
224+
225+
GET /api/v1/configs/complex.yml/test-suites HTTP/1.1
226+
227+
**Example Response**
228+
229+
.. sourcecode:: http
230+
231+
HTTP/1.1 200 OK
232+
Content-Type: application/json
233+
234+
["local","full"]
235+
""" # noqa: E501
236+
args = copy.copy(current_app.config["ARGS"])
237+
config_dir = args.test_dir
238+
args.test_file = config_name
239+
test_file = create_test_file(args)
240+
return jsonify(list(test_file.test_suites))
241+
242+
210243
@configs_blueprint.route("/api/v1/configs/<string:config_name>",
211244
methods=["DELETE"])
212245
def delete_config(config_name: str):

protoplaster/webui/templates/runs.html

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ <h5 class="modal-title" id="triggerTestRunModalLabel">Trigger Test Run</h5>
6666
</div>
6767

6868
<div class="mb-3">
69-
<label for="testSuiteName" class="form-label">Test suite</label>
70-
<input type="text" name="name" class="form-control" id="testSuiteName">
69+
<label for="testSuiteSelect" class="form-label">Test suite</label>
70+
<select name="testSuite" class="form-select" id="testSuiteSelect">
71+
</select>
7172
</div>
7273

7374
<div class="mb-3">
@@ -226,8 +227,37 @@ <h6>Test Results</h6>
226227
console.error("Failed to fetch configs:", err);
227228
configSelect.innerHTML = '<option disabled>Error loading configs</option>';
228229
}
230+
231+
updateTestSuiteList();
229232
}
230233

234+
async function updateTestSuiteList() {
235+
const testSuiteSelect = document.getElementById("testSuiteSelect");
236+
testSuiteSelect.innerHTML = '<option disabled>Loading...</option>';
237+
const configSelect = document.getElementById('configSelect');
238+
const config = configSelect.value;
239+
240+
try {
241+
// Fetch configs from the local controller
242+
const resp = await fetch(`/api/v1/configs/${config}/test-suites`);
243+
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
244+
const suites = await resp.json();
245+
246+
testSuiteSelect.innerHTML = '<option value="">(all)</option>';
247+
suites.forEach(s => {
248+
const opt = document.createElement('option');
249+
opt.value = s;
250+
opt.textContent = s;
251+
testSuiteSelect.appendChild(opt);
252+
});
253+
} catch (err) {
254+
console.error("Failed to fetch test suites:", err);
255+
configSelect.innerHTML = '<option disabled>Error loading test suites</option>';
256+
}
257+
}
258+
259+
document.getElementById("configSelect").addEventListener("input", updateTestSuiteList);
260+
231261
const modal = document.getElementById('triggerTestRunModal');
232262
modal.addEventListener('show.bs.modal', updateConfigList);
233263

@@ -241,7 +271,7 @@ <h6>Test Results</h6>
241271
document.getElementById('triggerRunForm').addEventListener('submit', async (e) => {
242272
e.preventDefault();
243273
const config = document.getElementById('configSelect').value;
244-
const testSuite = document.getElementById('testSuiteName').value;
274+
const testSuite = document.getElementById('testSuiteSelect').value;
245275
const overrides = document.getElementById('overrides').value;
246276

247277
try {

0 commit comments

Comments
 (0)