aboutsummaryrefslogtreecommitdiffstats
path: root/tests/api/test_eval.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2019-09-14 22:11:22 +0200
committerGravatar GitHub <[email protected]>2019-09-14 22:11:22 +0200
commit4d4691bc4feffb89470625e013a70d7d64f46a2f (patch)
tree298a514d6ccce9af6ee3ca41bcf3f35794cfe503 /tests/api/test_eval.py
parentRename .github/FUNDING.yml to .github/.github/FUNDING.yml (diff)
parentMerge pull request #41 from python-discord/fix-flake8-docstrings (diff)
Merge pull request #22 from python-discord/revitalisation
Revitalisation
Diffstat (limited to 'tests/api/test_eval.py')
-rw-r--r--tests/api/test_eval.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/api/test_eval.py b/tests/api/test_eval.py
new file mode 100644
index 0000000..3350763
--- /dev/null
+++ b/tests/api/test_eval.py
@@ -0,0 +1,49 @@
+from tests.api import SnekAPITestCase
+
+
+class TestEvalResource(SnekAPITestCase):
+ PATH = "/eval"
+
+ def test_post_valid_200(self):
+ body = {"input": "foo"}
+ result = self.simulate_post(self.PATH, json=body)
+
+ self.assertEqual(result.status_code, 200)
+ self.assertEqual("output", result.json["stdout"])
+ self.assertEqual(0, result.json["returncode"])
+
+ def test_post_invalid_schema_400(self):
+ body = {"stuff": "foo"}
+ result = self.simulate_post(self.PATH, json=body)
+
+ self.assertEqual(result.status_code, 400)
+
+ expected = {
+ "title": "Request data failed validation",
+ "description": "'input' is a required property"
+ }
+
+ self.assertEqual(expected, result.json)
+
+ def test_post_invalid_content_type_415(self):
+ body = "{'input': 'foo'}"
+ headers = {"Content-Type": "application/xml"}
+ result = self.simulate_post(self.PATH, body=body, headers=headers)
+
+ self.assertEqual(result.status_code, 415)
+
+ expected = {
+ "title": "Unsupported media type",
+ "description": "application/xml is an unsupported media type."
+ }
+
+ self.assertEqual(expected, result.json)
+
+ def test_disallowed_method_405(self):
+ result = self.simulate_get(self.PATH)
+ self.assertEqual(result.status_code, 405)
+
+ def test_options_allow_post_only(self):
+ result = self.simulate_options(self.PATH)
+ self.assertEqual(result.status_code, 200)
+ self.assertEqual(result.headers.get("Allow"), "POST")