def test_etag_verify_check_etag_warning(self, app, method): blp = Blueprint('test', __name__) old_item = {'item_id': 1, 'db_field': 0} old_etag = blp._generate_etag(old_item) with pytest.warns(None) as record: with app.test_request_context( '/', method=method, headers={'If-Match': old_etag}, ): blp._verify_check_etag() if method in ['PUT', 'PATCH', 'DELETE']: assert len(record) == 1 assert record[0].category == UserWarning assert str(record[0].message) == ( 'ETag not checked in endpoint {} on {} request.' .format(f_request.endpoint, method) ) else: assert not record blp.check_etag(old_item) record.clear() blp._verify_check_etag() assert not record
def test_etag_verify_check_etag_exception(self, app, method, debug, testing): app.config['DEBUG'] = debug app.config['TESTING'] = testing blp = Blueprint('test', __name__) with app.test_request_context('/', method=method): if (debug or testing) and method in ['PUT', 'PATCH', 'DELETE']: with pytest.raises(CheckEtagNotCalledError, match='ETag not checked in endpoint'): blp._verify_check_etag() else: blp._verify_check_etag()
def test_etag_verify_check_etag_warning(self, app, method): blp = Blueprint('test', __name__) old_item = {'item_id': 1, 'db_field': 0} old_etag = blp._generate_etag(old_item) with mock.patch.object(app.logger, 'warning') as mock_warning: with app.test_request_context('/', method=method, headers={'If-Match': old_etag}): blp._verify_check_etag() if method in ['PUT', 'PATCH', 'DELETE']: assert mock_warning.called mock_warning.reset_mock() else: assert not mock_warning.called blp.check_etag(old_item) blp._verify_check_etag() assert not mock_warning.called
def test_etag_verify_check_etag_warning(self, app, method): blp = Blueprint("test", __name__) old_item = {"item_id": 1, "db_field": 0} old_etag = blp._generate_etag(old_item) with pytest.warns(None) as record: with app.test_request_context( "/", method=method, headers={"If-Match": old_etag}, ): blp._verify_check_etag() if method in ["PUT", "PATCH", "DELETE"]: assert len(record) == 1 assert record[0].category == UserWarning assert str(record[0].message) == ( "ETag not checked in endpoint {} on {} request.". format(f_request.endpoint, method)) else: assert not record blp.check_etag(old_item) record.clear() blp._verify_check_etag() assert not record