| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  | import io | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  | import unittest | 
					
						
							|  |  |  | import json | 
					
						
							| 
									
										
										
										
											2024-01-11 14:44:12 -08:00
										 |  |  | import yaml | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestDocs(unittest.TestCase): | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls) -> None: | 
					
						
							| 
									
										
										
										
											2023-09-20 16:05:56 +02:00
										 |  |  |         from WebHostLib import app as raw_app | 
					
						
							|  |  |  |         from WebHost import get_app | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  |         raw_app.config["PONY"] = { | 
					
						
							|  |  |  |             "provider": "sqlite", | 
					
						
							|  |  |  |             "filename": ":memory:", | 
					
						
							|  |  |  |             "create_db": True, | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-12-14 20:01:06 +01:00
										 |  |  |         raw_app.config.update({ | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  |             "TESTING": True, | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-12-14 20:01:06 +01:00
										 |  |  |         app = get_app() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-05 22:27:15 +01:00
										 |  |  |         cls.client = app.test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-22 06:00:27 -05:00
										 |  |  |     def test_correct_error_empty_request(self): | 
					
						
							| 
									
										
										
										
											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-01-11 14:44:12 -08:00
										 |  |  |     def test_generation_queued_weights(self): | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  |     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.")) |