def get_user_stream(self, request): """ Streamed user response. """ def generate(): yield '\t'.join(f.name for f in field_iter(User)) + '\n' for user in USERS: yield '\t'.join(str(v) for _, v in field_iter_items(user)) + '\n' return HttpResponse(generate(), headers={'Content-Type': 'text/plain'})
def test_post_request(self, origins, method, expected): api_interface = ApiInterfaceBase(mock_endpoint) cors.CORS(api_interface, origins=origins) target = api_interface.middleware[0] http_request = MockRequest(headers={'Origin': 'http://my-domain.org'}, method=method, current_operation=mock_endpoint) http_response = HttpResponse('') actual = target.post_request(http_request, http_response) assert actual is http_response assert expected == actual.headers.get('Access-Control-Allow-Origin')
def test_set(self): target = HttpResponse.from_status(HTTPStatus.OK, {'foo': 1}) target['foo'] = 2 assert target.headers == {'foo': 2}
def test_get(self): target = HttpResponse.from_status(HTTPStatus.OK, {'foo': 1}) assert target['foo'] == 1
def test_init(self, args, body, status, headers): target = HttpResponse(*args) assert target.body == body assert target.status == status assert target.headers == headers
def test_set_content_type(self): target = HttpResponse.from_status(HTTPStatus.OK) target.set_content_type('text/html') assert target.headers == {'Content-Type': 'text/html'}
def callback(request): return HttpResponse("eek")
def pre_request(self, request, path_args): return HttpResponse('eek!', status=HTTPStatus.FORBIDDEN)