1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from mediagoblin
.tests
.tools
import setup_fresh_app
19 from mediagoblin
import mg_globals
27 def _get_some_data(key
):
29 Stuid function that makes use of some caching.
31 some_data_cache
= mg_globals
.cache
.get_cache('sum_data')
32 if some_data_cache
.has_key(key
):
33 return some_data_cache
.get(key
)
35 value
= DATA_TO_CACHE
.get(key
)
36 some_data_cache
.put(key
, value
)
41 def test_cache_working(test_app
):
42 some_data_cache
= mg_globals
.cache
.get_cache('sum_data')
43 assert not some_data_cache
.has_key('herp')
44 assert _get_some_data('herp') == 'derp'
45 assert some_data_cache
.get('herp') == 'derp'
46 # should get the same value again
47 assert _get_some_data('herp') == 'derp'
49 # now we force-change it, but the function should use the cached
51 some_data_cache
.put('herp', 'pred')
52 assert _get_some_data('herp') == 'pred'