@@ -0,0 +1,1659 @@
+# This file is part of Indico.%0A# Copyright (C) 2002 - 2016 European Organization for Nuclear Research (CERN).%0A#%0A# Indico is free software; you can redistribute it and/or%0A# modify it under the terms of the GNU General Public License as%0A# published by the Free Software Foundation; either version 3 of the%0A# License, or (at your option) any later version.%0A#%0A# Indico is distributed in the hope that it will be useful, but%0A# WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A# General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with Indico; if not, see %3Chttp://www.gnu.org/licenses/%3E.%0Aimport pytest%0A%0Afrom indico.util.caching import memoize_request%0A%0A%0A@pytest.yield_fixture%0Adef not_testing(app_context):%0A    app_context.config%5B'TESTING'%5D = False%0A    try:%0A        yield%0A    finally:%0A        app_context.config%5B'TESTING'%5D = True%0A%0A%0A@pytest.mark.usefixtures('request_context', 'not_testing')%0Adef test_memoize_request_args():%0A    calls = %5B0%5D%0A%0A    @memoize_request%0A    def fn(a, b, c='default', **kw):%0A        calls%5B0%5D += 1%0A%0A    assert calls%5B0%5D == 0%0A    fn(1, 2)%0A    assert calls%5B0%5D == 1%0A    fn(1, 2)  # normal memoized call%0A    assert calls%5B0%5D == 1%0A    # default value explicitly provided (both as arg and kwarg)%0A    fn(1, 2, 'default')%0A    fn(1, 2, c='default')%0A    fn(1, b=2)%0A    fn(a=1, b=2, c='default')%0A    assert calls%5B0%5D == 1%0A    fn(2, 2, c='default')%0A    assert calls%5B0%5D == 2%0A    fn(2, 2)%0A    assert calls%5B0%5D == 2%0A    fn(2, 2, foo='bar')%0A    assert calls%5B0%5D == 3%0A    fn(a=2, b=2, foo='bar')%0A    assert calls%5B0%5D == 3%0A

Add unit test for memoize_request