def test_view_gets_decoded_instance(self): person = self.person_cls("Bob", "Smith") with self.test_client as c: res = c.post("/person", data=encode.dumper(person), content_type="application/json") self.assertIsInstance(request._get_current_object(), JsonWebRequest) self.assertIsInstance(request.json, self.person_cls) self.assertEqual(res.status_code, 200)
def get_request(obj): builder = EnvironBuilder("/", data=encode.dumper(obj)) builder.headers["content-type"] = "application/json" return JsonWebRequest(builder.get_environ())
def test_wrong_content_type_returns_error(self): res = self.test_client.post("/person", data=encode.dumper(self.person_cls(1, "smith"))) self.assertEqual(res.status_code, 400)
def post(self, url, data): return self.test_client.post(url, data=encode.dumper(data), content_type="application/json")
def test_wrong_content_type_returns_error(self): res = self.test_client.post("/person", data=encode.dumper( self.person_cls(1, "smith"))) self.assertEqual(res.status_code, 400)