|
| 1 | +# Copyright 2016 Google Inc. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from google.appengine.api import memcache |
| 16 | +from mock import patch |
| 17 | +import snippets |
| 18 | + |
| 19 | +SNIPPET_VALUES = { |
| 20 | + "weather_USA_98105": "raining", |
| 21 | + "weather_USA_98115": "cloudy", |
| 22 | + "weather_USA_94105": "foggy", |
| 23 | + "weather_USA_94043": "sunny", |
| 24 | + "counter": 3, |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +@patch('snippets.query_for_data', return_value='data') |
| 29 | +def test_get_data_not_present(query_fn, testbed): |
| 30 | + data = snippets.get_data() |
| 31 | + query_fn.assert_called_once_with() |
| 32 | + assert data == 'data' |
| 33 | + memcache.delete('key') |
| 34 | + |
| 35 | + |
| 36 | +@patch('snippets.query_for_data', return_value='data') |
| 37 | +def test_get_data_present(query_fn, testbed): |
| 38 | + memcache.add('key', 'data', 9000) |
| 39 | + data = snippets.get_data() |
| 40 | + query_fn.assert_not_called() |
| 41 | + assert data == 'data' |
| 42 | + memcache.delete('key') |
| 43 | + |
| 44 | + |
| 45 | +def test_add_values(testbed): |
| 46 | + snippets.add_values() |
| 47 | + for key, value in SNIPPET_VALUES.iteritems(): |
| 48 | + assert memcache.get(key) == value |
0 commit comments