| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  | import io | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  | import yaml | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 16:51:10 +02:00
										 |  |  | from . import TestBase | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 16:51:10 +02:00
										 |  |  | class TestAPIGenerate(TestBase): | 
					
						
							|  |  |  |     def test_correct_error_empty_request(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  |         response = self.client.post("/api/generate") | 
					
						
							|  |  |  |         self.assertIn("No options found. Expected file attachment or json weights.", response.text) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 16:51:10 +02:00
										 |  |  |     def test_generation_queued_weights(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  |         options = { | 
					
						
							|  |  |  |             "Tester1": | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "game": "Archipelago", | 
					
						
							|  |  |  |                     "name": "Tester", | 
					
						
							|  |  |  |                     "Archipelago": {} | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         response = self.client.post( | 
					
						
							|  |  |  |             "/api/generate", | 
					
						
							|  |  |  |             data=json.dumps({"weights": options}), | 
					
						
							|  |  |  |             content_type='application/json' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         json_data = response.get_json() | 
					
						
							|  |  |  |         self.assertTrue(json_data["text"].startswith("Generation of seed ")) | 
					
						
							|  |  |  |         self.assertTrue(json_data["text"].endswith(" started successfully.")) | 
					
						
							| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 16:51:10 +02:00
										 |  |  |     def test_generation_queued_file(self) -> None: | 
					
						
							| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  |         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.")) |