diff options
Diffstat (limited to 'tests/test_decorators.py')
-rw-r--r-- | tests/test_decorators.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_decorators.py b/tests/test_decorators.py new file mode 100644 index 00000000..a73052e4 --- /dev/null +++ b/tests/test_decorators.py @@ -0,0 +1,25 @@ +from tests import SiteTest + +class DecoratorTests(SiteTest): + def test_decorator_api_json(self): + """ Check the json validation decorator """ + from pysite.decorators import api_params + from pysite.constants import ValidationTypes + from schema import Schema + + SCHEMA = Schema([{"user_id": int, "role": int}]) + + @api_params(schema=SCHEMA, validation_type=ValidationTypes.json) + def try_json_type(data): + return data + + with self.assertRaises(AttributeError): + try_json_type("not json") + + def test_decorator_params(self): + """ Check the params validation decorator """ + + response = self.client.post('/testparams?test=params') + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json, [{'test': 'params'}]) |