diff options
| author | 2021-05-18 18:34:44 -0400 | |
|---|---|---|
| committer | 2021-05-18 18:34:44 -0400 | |
| commit | 4dfd47afed5f870bcfb09c7d5d29f4373eeac420 (patch) | |
| tree | 992d5faa9cb51fcf3227c1558f1abb51a1b5541f | |
| parent | chore: Improve documentation for arguments in /eval (diff) | |
chore: Add tests for py_args and ns_jail args
Diffstat (limited to '')
| -rw-r--r-- | docker-compose.yml | 2 | ||||
| -rw-r--r-- | tests/api/test_eval.py | 18 | ||||
| -rw-r--r-- | tests/test_nsjail.py | 13 | 
3 files changed, 32 insertions, 1 deletions
| diff --git a/docker-compose.yml b/docker-compose.yml index f546024..e962524 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services:        cache_from:          - ghcr.io/python-discord/snekbox:latest      volumes: -      - $PWD:$PWD +      - .:/snekbox        - user-base:/snekbox/user_base  volumes: diff --git a/tests/api/test_eval.py b/tests/api/test_eval.py index 3350763..7270905 100644 --- a/tests/api/test_eval.py +++ b/tests/api/test_eval.py @@ -25,6 +25,24 @@ class TestEvalResource(SnekAPITestCase):          self.assertEqual(expected, result.json) +    def test_post_invalid_data_400(self): +        input_body = {"input": 400} +        args_body = {"input": "", "args": [400]} + +        input_result = self.simulate_post(self.PATH, json=input_body) +        args_result = self.simulate_post(self.PATH, json=args_body) + +        self.assertEqual(input_result.status_code, 400) +        self.assertEqual(args_result.status_code, 400) + +        expected = { +            "title": "Request data failed validation", +            "description": "400 is not of type 'string'" +        } + +        self.assertEqual(expected, input_result.json) +        self.assertEqual(expected, args_result.json) +      def test_post_invalid_content_type_415(self):          body = "{'input': 'foo'}"          headers = {"Content-Type": "application/xml"} diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py index 46193b2..8955b4a 100644 --- a/tests/test_nsjail.py +++ b/tests/test_nsjail.py @@ -217,3 +217,16 @@ class NsJailTests(unittest.TestCase):          output = self.nsjail._consume_stdout(nsjail_subprocess)          self.assertEqual(output, chunk * expected_chunks) + +    def test_nsjail_args(self): +        args = ("foo", "bar") +        result = self.nsjail.python3("", nsjail_args=args) + +        self.assertEqual(result.args[9:11], args) + +    def test_py_args(self): +        args = ("-m", "timeit") +        result = self.nsjail.python3("", py_args=args) + +        self.assertEqual(result.returncode, 0) +        self.assertEqual(result.args[-3:-1], args) | 
