def _assert_bad_request(self, data, schema, as_json=False): if as_json: data = json.dumps(data) with self.app.test_request_context(method="POST", data=data, content_type="application/json" if as_json else None): with self.assertRaises(HTTPException) as caught: weber_utils.get_request_input(schema) self.assertEquals(caught.exception.code, httplib.BAD_REQUEST)
def _assert_bad_request(self, data, schema, as_json=False): if as_json: data = json.dumps(data) with self.app.test_request_context( method="POST", data=data, content_type="application/json" if as_json else None): with self.assertRaises(HTTPException) as caught: weber_utils.get_request_input(schema) self.assertEquals(caught.exception.code, httplib.BAD_REQUEST)
def test_request_input_json(self): data = {"a": 2, "b": "c"} with self.app.test_request_context(method="POST", data=json.dumps(data), content_type="application/json"): self.assertEquals( weber_utils.get_request_input({ "a": int, "b": string_types }), data)
def test_request_input_form(self): data = {"a": "2", "b": "c"} with self.app.test_request_context(method="POST", data=data): self.assertEquals( weber_utils.get_request_input({ "a": int, "b": string_types }), { "a": 2, "b": "c" })
def test_request_input_form(self): data = {"a": "2", "b": "c"} with self.app.test_request_context(method="POST", data=data): self.assertEquals(weber_utils.get_request_input({"a": int, "b": string_types}), {"a": 2, "b": "c"})
def test_request_input_json(self): data = {"a": 2, "b": "c"} with self.app.test_request_context(method="POST", data=json.dumps(data), content_type="application/json"): self.assertEquals(weber_utils.get_request_input({"a": int, "b": string_types}), data)