OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This will attempt to import the actual App Engine modules, and if it fails, | 5 # This will attempt to import the actual App Engine modules, and if it fails, |
6 # they will be replaced with fake modules. This is useful during testing. | 6 # they will be replaced with fake modules. This is useful during testing. |
7 try: | 7 try: |
| 8 import google.appengine.ext.blobstore as blobstore |
8 import google.appengine.ext.webapp as webapp | 9 import google.appengine.ext.webapp as webapp |
| 10 import google.appengine.api.files as files |
9 import google.appengine.api.memcache as memcache | 11 import google.appengine.api.memcache as memcache |
10 import google.appengine.api.urlfetch as urlfetch | 12 import google.appengine.api.urlfetch as urlfetch |
11 except ImportError: | 13 except ImportError: |
12 class FakeUrlFetch(object): | 14 class NotImplemented(object): |
13 """A fake urlfetch module that errors for all method calls. | 15 def __getattr__(self, attr): |
14 """ | |
15 def fetch(self, url): | |
16 raise NotImplementedError() | 16 raise NotImplementedError() |
17 | 17 |
18 def create_rpc(self): | 18 blobstore = NotImplemented() |
19 raise NotImplementedError() | 19 files = NotImplemented() |
20 | 20 urlfetch = NotImplemented() |
21 def make_fetch_call(self): | |
22 raise NotImplementedError() | |
23 urlfetch = FakeUrlFetch() | |
24 | 21 |
25 class InMemoryMemcache(object): | 22 class InMemoryMemcache(object): |
26 """A memcache that stores items in memory instead of using the memcache | 23 """A memcache that stores items in memory instead of using the memcache |
27 module. | 24 module. |
28 """ | 25 """ |
29 def __init__(self): | 26 def __init__(self): |
30 self._cache = {} | 27 self._cache = {} |
31 | 28 |
32 def set(self, key, value, namespace, time=60): | 29 def set(self, key, value, namespace, time=60): |
33 if namespace not in self._cache: | 30 if namespace not in self._cache: |
(...skipping 12 matching lines...) Expand all Loading... |
46 | 43 |
47 # A fake webapp.RequestHandler class for Handler to extend. | 44 # A fake webapp.RequestHandler class for Handler to extend. |
48 class webapp(object): | 45 class webapp(object): |
49 class RequestHandler(object): | 46 class RequestHandler(object): |
50 def __init__(self, request, response): | 47 def __init__(self, request, response): |
51 self.request = request | 48 self.request = request |
52 self.response = response | 49 self.response = response |
53 | 50 |
54 def redirect(self, path): | 51 def redirect(self, path): |
55 self.request.path = path | 52 self.request.path = path |
OLD | NEW |