forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api_generate.py
60 lines (54 loc) · 1.84 KB
/
test_api_generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import io
import unittest
import json
import yaml
class TestDocs(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
from WebHostLib import app as raw_app
from WebHost import get_app
raw_app.config["PONY"] = {
"provider": "sqlite",
"filename": ":memory:",
"create_db": True,
}
raw_app.config.update({
"TESTING": True,
})
app = get_app()
cls.client = app.test_client()
def test_correct_error_empty_request(self):
response = self.client.post("/api/generate")
self.assertIn("No options found. Expected file attachment or json weights.", response.text)
def test_generation_queued_weights(self):
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."))
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."))