def test_etag_set_etag_in_response(self, app, schemas, paginate): blp = Blueprint("test", __name__) etag_schema = schemas.DocEtagSchema item = {"item_id": 1, "db_field": 0} if paginate: extra_data = (("X-Pagination", "Dummy pagination header"), ) else: extra_data = tuple() etag = blp._generate_etag(item, extra_data=extra_data) etag_with_schema = blp._generate_etag(item, etag_schema, extra_data=extra_data) with app.test_request_context("/"): resp = Response() if extra_data: resp.headers["X-Pagination"] = "Dummy pagination header" get_appcontext()["result_dump"] = item blp._set_etag_in_response(resp, None) assert resp.get_etag() == (etag, False) with app.test_request_context("/"): resp = Response() if extra_data: resp.headers["X-Pagination"] = "Dummy pagination header" get_appcontext()["result_raw"] = item blp._set_etag_in_response(resp, etag_schema) assert resp.get_etag() == (etag_with_schema, False)
def test_etag_set_etag_in_response(self, app, schemas, paginate): blp = Blueprint('test', __name__) etag_schema = schemas.DocEtagSchema item = {'item_id': 1, 'db_field': 0} if paginate: extra_data = (('X-Pagination', 'Dummy pagination header'),) else: extra_data = tuple() etag = blp._generate_etag(item, extra_data=extra_data) etag_with_schema = blp._generate_etag( item, etag_schema, extra_data=extra_data) with app.test_request_context('/'): resp = Response() if extra_data: resp.headers['X-Pagination'] = 'Dummy pagination header' get_appcontext()['result_dump'] = item blp._set_etag_in_response(resp, None) assert resp.get_etag() == (etag, False) with app.test_request_context('/'): resp = Response() if extra_data: resp.headers['X-Pagination'] = 'Dummy pagination header' get_appcontext()['result_raw'] = item blp._set_etag_in_response(resp, etag_schema) assert resp.get_etag() == (etag_with_schema, False)