WebHost: Fix /api/generate (#2693)

This commit is contained in:
Remy Jette 2024-01-11 14:44:12 -08:00 committed by GitHub
parent b6f3ccb8c5
commit f530895c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -20,8 +20,8 @@ def generate_api():
race = False
meta_options_source = {}
if 'file' in request.files:
file = request.files['file']
options = get_yaml_data(file)
files = request.files.getlist('file')
options = get_yaml_data(files)
if isinstance(options, Markup):
return {"text": options.striptags()}, 400
if isinstance(options, str):

View File

@ -1,5 +1,7 @@
import io
import unittest
import json
import yaml
class TestDocs(unittest.TestCase):
@ -23,7 +25,7 @@ class TestDocs(unittest.TestCase):
response = self.client.post("/api/generate")
self.assertIn("No options found. Expected file attachment or json weights.", response.text)
def test_generation_queued(self):
def test_generation_queued_weights(self):
options = {
"Tester1":
{
@ -40,3 +42,19 @@ class TestDocs(unittest.TestCase):
json_data = response.get_json()
self.assertTrue(json_data["text"].startswith("Generation of seed "))
self.assertTrue(json_data["text"].endswith(" started successfully."))
def test_generation_queued_file(self):
options = {
"game": "Archipelago",
"name": "Tester",
"Archipelago": {}
}
response = self.client.post(
"/api/generate",
data={
'file': (io.BytesIO(yaml.dump(options, encoding="utf-8")), "test.yaml")
},
)
json_data = response.get_json()
self.assertTrue(json_data["text"].startswith("Generation of seed "))
self.assertTrue(json_data["text"].endswith(" started successfully."))