def test_json_favored(self): data = Person() data.id = 1 data.name = "tester" data.email = "*****@*****.**" response_data = { "id": data.id, "name": data.name, "email": data.email } app = flask.Flask(__name__) with app.test_request_context( data=data.SerializeToString(), method='POST', content_type="application/x-protobuf", headers={ "Accept": "*/*" } ): @api(json, protobuf(receives=Person)) def view_method(): return flask.request.data_dict response, status_code, headers = view_method() self.assertEquals(response.status_code, 200) self.assertEquals(loads(response.data), response_data) self.assertEquals(response.mimetype, "application/json")
def test_simple_pb_response(self): person = Person() person.id = 1 person.name = "tester" person.email = "*****@*****.**" data = { "id": person.id, "name": person.name, "email": person.email } app = flask.Flask(__name__) with app.test_request_context( method='GET', content_type="application/x-protobuf", headers={ "Accept": "application/x-protobuf" } ): @api(protobuf(sends=Person)) def view_method(): return data response, status_code, headers = view_method() response_data = Person() response_data.ParseFromString(response.data) self.assertEquals(response_data, person) self.assertEquals(response.mimetype, 'application/x-protobuf') self.assertEquals(status_code, 200)
def test_simple_pb_response(self): person = Person() person.id = 1 person.name = "tester" person.email = "*****@*****.**" data = {"id": person.id, "name": person.name, "email": person.email} app = flask.Flask(__name__) with app.test_request_context( method='GET', content_type="application/x-protobuf", headers={"Accept": "application/x-protobuf"}): @api(protobuf(sends=Person)) def view_method(): return data response, status_code, headers = view_method() response_data = Person() response_data.ParseFromString(response.data) self.assertEquals(response_data, person) self.assertEquals(response.mimetype, 'application/x-protobuf') self.assertEquals(status_code, 200)
def test_simple_pb_request(self): data = Person() data.id = 1 data.name = "tester" data.email = "*****@*****.**" app = flask.Flask(__name__) with app.test_request_context( data=data.SerializeToString(), method='POST', content_type="application/x-protobuf", headers={ "Accept": "application/x-protobuf" } ): @api(protobuf(receives=Person)) def view_method(): self.assertEqual(flask.request.data_dict, {'id': 1, 'name': 'tester', 'email': '*****@*****.**'}) return 200 view_method()
def test_json_favored(self): data = Person() data.id = 1 data.name = "tester" data.email = "*****@*****.**" response_data = {"id": data.id, "name": data.name, "email": data.email} app = flask.Flask(__name__) with app.test_request_context(data=data.SerializeToString(), method='POST', content_type="application/x-protobuf", headers={"Accept": "*/*"}): @api(json, protobuf(receives=Person)) def view_method(): return flask.request.data_dict response, status_code, headers = view_method() self.assertEquals(response.status_code, 200) self.assertEquals(loads(response.data), response_data) self.assertEquals(response.mimetype, "application/json")
def test_simple_pb_request(self): data = Person() data.id = 1 data.name = "tester" data.email = "*****@*****.**" app = flask.Flask(__name__) with app.test_request_context( data=data.SerializeToString(), method='POST', content_type="application/x-protobuf", headers={"Accept": "application/x-protobuf"}): @api(protobuf(receives=Person)) def view_method(): self.assertEqual(flask.request.data_dict, { 'id': 1, 'name': 'tester', 'email': '*****@*****.**' }) return 200 view_method()