Commit | Line | Data |
---|---|---|
284ebca0 | 1 | # GNU MediaGoblin -- federated, autonomous media hosting |
7f4ebeed | 2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
284ebca0 CAW |
3 | # |
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. | |
8 | # | |
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. | |
13 | # | |
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/>. | |
16 | ||
17 | ||
18 | from mediagoblin.tests.tools import setup_fresh_app | |
19 | from mediagoblin import mg_globals | |
20 | ||
21 | ||
22 | DATA_TO_CACHE = { | |
23 | 'herp': 'derp', | |
24 | 'lol': 'cats'} | |
25 | ||
26 | ||
27 | def _get_some_data(key): | |
28 | """ | |
29 | Stuid function that makes use of some caching. | |
30 | """ | |
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) | |
34 | ||
35 | value = DATA_TO_CACHE.get(key) | |
36 | some_data_cache.put(key, value) | |
37 | return value | |
38 | ||
39 | ||
40 | @setup_fresh_app | |
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' | |
48 | ||
49 | # now we force-change it, but the function should use the cached | |
50 | # version | |
51 | some_data_cache.put('herp', 'pred') | |
52 | assert _get_some_data('herp') == 'pred' |