|
| 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.ext import ndb |
| 16 | +import snippets |
| 17 | + |
| 18 | + |
| 19 | +def test_set_in_process_cache_policy(testbed): |
| 20 | + context = ndb.get_context() |
| 21 | + |
| 22 | + def policy(key): |
| 23 | + return 1 == 1 |
| 24 | + |
| 25 | + snippets.set_in_process_cache_policy(context, policy) |
| 26 | + assert policy == context.get_cache_policy() |
| 27 | + |
| 28 | + |
| 29 | +def test_set_memcache_policy(testbed): |
| 30 | + context = ndb.get_context() |
| 31 | + |
| 32 | + def policy(key): |
| 33 | + return 1 == 2 |
| 34 | + |
| 35 | + snippets.set_memcache_policy(context, policy) |
| 36 | + assert policy == context.get_memcache_policy() |
| 37 | + |
| 38 | + |
| 39 | +def test_bypass_in_process_cache_for_account_entities(testbed): |
| 40 | + context = ndb.get_context() |
| 41 | + assert context.get_cache_policy() == context.default_cache_policy |
| 42 | + snippets.bypass_in_process_cache_for_account_entities(context) |
| 43 | + assert context.get_cache_policy() != context.default_cache_policy |
| 44 | + |
| 45 | + |
| 46 | +def test_set_datastore_policy(testbed): |
| 47 | + context = ndb.get_context() |
| 48 | + |
| 49 | + def policy(key): |
| 50 | + return key is None |
| 51 | + |
| 52 | + snippets.set_datastore_policy(context, policy) |
| 53 | + assert context.get_datastore_policy() == policy |
| 54 | + |
| 55 | + |
| 56 | +def test_set_memcache_timeout_policy(testbed): |
| 57 | + context = ndb.get_context() |
| 58 | + |
| 59 | + def policy(key): |
| 60 | + return 1 |
| 61 | + |
| 62 | + snippets.set_memcache_timeout_policy(context, policy) |
| 63 | + assert context.get_memcache_timeout_policy() == policy |
| 64 | + |
| 65 | + |
| 66 | +def test_clear_cache(testbed): |
| 67 | + context = ndb.get_context() |
| 68 | + snippets.clear_cache(context) |
0 commit comments