def test_deis_version_header_good(self): """ Test that when the version header is sent, the request is accepted. """ response = self.client.get( '/v2/apps', HTTP_DEIS_VERSION=__version__.rsplit('.', 2)[0] ) self.assertEqual(response.status_code, 200, response.data) self.assertEqual(response.has_header('DEIS_API_VERSION'), True) self.assertEqual(response['DEIS_API_VERSION'], __version__.rsplit('.', 1)[0])
def test_deis_version_header_good(self): """ Test that when the version header is sent, the request is accepted. """ response = self.client.get( '/v2/apps', HTTP_DEIS_VERSION=__version__.rsplit('.', 2)[0], HTTP_AUTHORIZATION='token {}'.format(self.token), ) self.assertEqual(response.status_code, 200) self.assertEqual(response.has_header('DEIS_API_VERSION'), True) self.assertEqual(response['DEIS_API_VERSION'], __version__.rsplit('.', 1)[0])
def test_x_deis_version_header_good(self): """ Test that when the version header is sent, the request is accepted. """ response = self.client.get( '/v1/apps', HTTP_X_DEIS_VERSION=__version__.rsplit('.', 2)[0], HTTP_AUTHORIZATION='token {}'.format(self.token), ) self.assertEqual(response.status_code, 200) self.assertEqual(response.has_header('X_DEIS_API_VERSION'), True) self.assertEqual(response['X_DEIS_API_VERSION'], __version__.rsplit('.', 1)[0])
def process_response(self, request, response): """ Include the controller's REST API major and minor version in a response header. """ # clients shouldn't care about the patch release response['DEIS_API_VERSION'] = __version__.rsplit('.', 1)[0] return response
def test_deis_version_header_good(self): """ Test that when the version header is sent. """ response = self.client.get('/v2/apps') self.assertEqual(response.status_code, 200) self.assertEqual(response.has_header('DEIS_API_VERSION'), True) self.assertEqual(response['DEIS_API_VERSION'], __version__.rsplit('.', 1)[0])
def __call__(self, request): """ Include the controller's REST API major and minor version in a response header. """ response = self.get_response(request) # clients shouldn't care about the patch release version = __version__.rsplit('.', 1)[0] response['DEIS_API_VERSION'] = version response['DEIS_PLATFORM_VERSION'] = __version__ return response
def process_request(self, request): try: # server and client version must match the major release point client_version = request.META['HTTP_X_DEIS_VERSION'] server_version = __version__.rsplit('.', 2)[0] if client_version != server_version: message = { 'error': 'Client and server versions do not match. ' + 'Client version: {} '.format(client_version) + 'Server version: {}'.format(server_version) } return HttpResponse(json.dumps(message), content_type='application/json', status=status.HTTP_405_METHOD_NOT_ALLOWED) except KeyError: pass
def process_request(self, request): try: # server and client version must match the major release point client_version = request.META['HTTP_X_DEIS_VERSION'] server_version = __version__.rsplit('.', 2)[0] if client_version != server_version: message = { 'error': 'Client and server versions do not match. ' + 'Client version: {} '.format(client_version) + 'Server version: {}'.format(server_version) } return HttpResponse( json.dumps(message), content_type='application/json', status=status.HTTP_405_METHOD_NOT_ALLOWED ) except KeyError: pass
def process_request(self, request): """ Return a 405 "Not Allowed" if the request's client major version doesn't match this controller's REST API major version (currently "1"). """ try: client_version = request.META['HTTP_DEIS_VERSION'] server_version = __version__.rsplit('.', 2)[0] if client_version != server_version: message = { 'error': 'Client and server versions do not match. ' + 'Client version: {} '.format(client_version) + 'Server version: {}'.format(server_version) } return HttpResponse(json.dumps(message), content_type='application/json', status=status.HTTP_405_METHOD_NOT_ALLOWED) except KeyError: pass
def process_request(self, request): """ Return a 405 "Not Allowed" if the request's client major version doesn't match this controller's REST API major version (currently "1"). """ try: client_version = request.META['HTTP_DEIS_VERSION'] server_version = __version__.rsplit('.', 2)[0] if client_version != server_version: message = { 'error': 'Client and server versions do not match. ' + 'Client version: {} '.format(client_version) + 'Server version: {}'.format(server_version) } return HttpResponse( json.dumps(message), content_type='application/json', status=status.HTTP_405_METHOD_NOT_ALLOWED ) except KeyError: pass
def process_response(self, request, response): # clients shouldn't care about the patch release response['X_DEIS_API_VERSION'] = __version__.rsplit('.', 1)[0] return response