author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Mon, 02 Mar 2009 18:30:00 +0000 | |
changeset 1590 | 8fe571a8538f |
parent 1009 | 7abbbfc79f3a |
child 1690 | 376e75215f35 |
permissions | -rwxr-xr-x |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
2 |
import sys |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
3 |
import os |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 |
|
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 |
HERE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
6 |
'..')) |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 |
appengine_location = os.path.join(HERE, 'thirdparty', 'google_appengine') |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
8 |
extra_paths = [HERE, |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
9 |
os.path.join(appengine_location, 'lib', 'django'), |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
10 |
os.path.join(appengine_location, 'lib', 'webob'), |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
11 |
os.path.join(appengine_location, 'lib', 'yaml', 'lib'), |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
12 |
appengine_location, |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
13 |
os.path.join(HERE, 'app'), |
780
042aafcd7dce
Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents:
421
diff
changeset
|
14 |
os.path.join(HERE, 'thirdparty', 'coverage'), |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
15 |
] |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
16 |
|
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
17 |
import nose |
781
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
18 |
from nose import plugins |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
19 |
|
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
20 |
class AppEngineDatastoreClearPlugin(plugins.Plugin): |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
21 |
"""Nose plugin to clear the AppEngine datastore between tests. |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
22 |
""" |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
23 |
name = 'AppEngineDatastoreClearPlugin' |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
24 |
enabled = True |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
25 |
def options(self, parser, env): |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
26 |
return plugins.Plugin.options(self, parser, env) |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
27 |
|
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
28 |
def configure(self, parser, env): |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
29 |
plugins.Plugin.configure(self, parser, env) |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
30 |
self.enabled = True |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
31 |
|
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
32 |
def afterTest(self, test): |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
33 |
from google.appengine.api import apiproxy_stub_map |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
34 |
datastore = apiproxy_stub_map.apiproxy.GetStub('datastore') |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
35 |
datastore.Clear() |
780
042aafcd7dce
Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents:
421
diff
changeset
|
36 |
|
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
37 |
|
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
38 |
def main(): |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
39 |
sys.path = extra_paths + sys.path |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
40 |
os.environ['SERVER_SOFTWARE'] = 'Development via nose' |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
41 |
os.environ['SERVER_NAME'] = 'Foo' |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
42 |
os.environ['SERVER_PORT'] = '8080' |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
43 |
os.environ['APPLICATION_ID'] = 'test-app-run' |
1009
7abbbfc79f3a
Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1008
diff
changeset
|
44 |
os.environ['USER_EMAIL'] = 'test@example.com' |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
45 |
import main as app_main |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
46 |
from google.appengine.api import apiproxy_stub_map |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
47 |
from google.appengine.api import datastore_file_stub |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
48 |
from google.appengine.api import mail_stub |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
49 |
from google.appengine.api import user_service_stub |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
50 |
from google.appengine.api import urlfetch_stub |
1008
ae1a36ef7cff
Fix testing views, which broke because now we need to register a proxy for the
Augie Fackler <durin42@gmail.com>
parents:
781
diff
changeset
|
51 |
from google.appengine.api.memcache import memcache_stub |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
52 |
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
53 |
apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
54 |
urlfetch_stub.URLFetchServiceStub()) |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
55 |
apiproxy_stub_map.apiproxy.RegisterStub('user', |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
56 |
user_service_stub.UserServiceStub()) |
781
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
57 |
apiproxy_stub_map.apiproxy.RegisterStub('datastore', |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
58 |
datastore_file_stub.DatastoreFileStub('your_app_id', None, None)) |
1008
ae1a36ef7cff
Fix testing views, which broke because now we need to register a proxy for the
Augie Fackler <durin42@gmail.com>
parents:
781
diff
changeset
|
59 |
apiproxy_stub_map.apiproxy.RegisterStub('memcache', |
ae1a36ef7cff
Fix testing views, which broke because now we need to register a proxy for the
Augie Fackler <durin42@gmail.com>
parents:
781
diff
changeset
|
60 |
memcache_stub.MemcacheServiceStub()) |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
61 |
apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) |
781
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
62 |
import django.test.utils |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
63 |
django.test.utils.setup_test_environment() |
35a2d07e04e8
Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents:
780
diff
changeset
|
64 |
nose.main(plugins=[AppEngineDatastoreClearPlugin(), ]) |
419
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
65 |
|
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
66 |
|
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
67 |
if __name__ == '__main__': |
e9280ea935e4
Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
68 |
main() |