def ping(request): ''' Endpoint for API ping GET requests. Returns either: 1. Protobuf-serialized response if "accept" header is "application/x-protobuf" 2. JSON response otherwise ''' version = MAJOR_VERSION + MINOR_VERSION api_info = Model_pb2.ApiInformation() api_info.Version = version return format_and_send_response(request, api_info)
def test_api_ping_protobuf(self): ''' Test for endpoint: /api/ping With accept-type "application/x-protobuf" ''' response = self.client.get('/api/ping', \ **{'HTTP_ACCEPT':'application/x-protobuf'}) self.assertEqual(response.status_code, 200, \ msg='/api/ping endpoint did not return 200 status code.') response_pb = Model_pb2.ApiInformation() response_pb.ParseFromString(response.content) self.assertNotEqual(response_pb.Version, None, \ msg='/api/ping endpoint did not return proper Protobuf message.')