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