def test_validation(self): app = TestApp(main({})) app.get('/service', status=400) res = app.post('/service', params='buh', status=400) self.assertTrue('Not a json body' in res.body) res = app.post('/service', params=json.dumps('buh')) self.assertEqual(res.body, json.dumps({'body': '"buh"'})) app.get('/service?paid=yup') # valid = foo is one res = app.get('/service?foo=1&paid=yup') self.assertEqual(res.json['foo'], 1) # invalid value for foo res = app.get('/service?foo=buh&paid=yup', status=400) # check that json is returned errors = Errors.from_json(res.body) self.assertEqual(len(errors), 1) # the "apidocs" registry entry contains all the needed information # to build up documentation # in this case, this means the function is registered and the argument # of the service are defined (e.g "validator" is set) apidocs = app.app.registry.settings['apidocs'] self.assertTrue(_json in apidocs[('/service', 'POST')]['validators'])
def test_validation(self): app = TestApp(main({})) app.get('/service', status=400) res = app.post('/service', params='buh', status=400) self.assertTrue(b'Not a json body' in res.body) res = app.post('/service', params=json.dumps('buh')) self.assertEqual(res.body, json.dumps({ 'body': '"buh"' }).encode('ascii')) app.get('/service?paid=yup') # valid = foo is one res = app.get('/service?foo=1&paid=yup') self.assertEqual(res.json['foo'], 1) # invalid value for foo res = app.get('/service?foo=buh&paid=yup', status=400) # check that json is returned errors = Errors.from_json(res.body) self.assertEqual(len(errors), 1)
def test_validation(self): app = TestApp(main({})) app.get('/service', status=400) res = app.post('/service', params='buh', status=400) self.assertTrue('Not a json body' in res.body) res = app.post('/service', params=json.dumps('buh')) self.assertEqual(res.body, json.dumps({'body': '"buh"'})) app.get('/service?paid=yup') # valid = foo is one res = app.get('/service?foo=1&paid=yup') self.assertEqual(res.json['foo'], 1) # invalid value for foo res = app.get('/service?foo=buh&paid=yup', status=400) # check that json is returned errors = Errors.from_json(res.body) self.assertEqual(len(errors), 1)
def test_validation(self): app = TestApp(main({})) app.get("/service", status=400) response = app.post("/service", params="buh", status=400) self.assertTrue(b"Not a json body" in response.body) response = app.post("/service", params=json.dumps("buh")) expected = json.dumps({"body": '"buh"'}).encode("ascii") self.assertEqual(response.body, expected) app.get("/service?paid=yup") # valid = foo is one response = app.get("/service?foo=1&paid=yup") self.assertEqual(response.json["foo"], 1) # invalid value for foo response = app.get("/service?foo=buh&paid=yup", status=400) # check that json is returned errors = Errors.from_json(response.body) self.assertEqual(len(errors), 1)