WebHost: Fix /api/generate (#2693)
This commit is contained in:
		
							parent
							
								
									b6f3ccb8c5
								
							
						
					
					
						commit
						f530895c33
					
				| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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."))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue