5 HERE
= os
.path
.normpath(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)),
7 appengine_location
= os
.path
.join(HERE
, 'thirdparty', 'google_appengine')
9 os
.path
.join(appengine_location
, 'lib', 'django'),
10 os
.path
.join(appengine_location
, 'lib', 'webob'),
11 os
.path
.join(appengine_location
, 'lib', 'yaml', 'lib'),
13 os
.path
.join(HERE
, 'app'),
14 os
.path
.join(HERE
, 'thirdparty', 'coverage'),
18 from nose
import plugins
20 class AppEngineDatastoreClearPlugin(plugins
.Plugin
):
21 """Nose plugin to clear the AppEngine datastore between tests.
23 name
= 'AppEngineDatastoreClearPlugin'
25 def options(self
, parser
, env
):
26 return plugins
.Plugin
.options(self
, parser
, env
)
28 def configure(self
, parser
, env
):
29 plugins
.Plugin
.configure(self
, parser
, env
)
32 def afterTest(self
, test
):
33 from google
.appengine
.api
import apiproxy_stub_map
34 datastore
= apiproxy_stub_map
.apiproxy
.GetStub('datastore')
39 sys
.path
= extra_paths
+ sys
.path
40 os
.environ
['SERVER_SOFTWARE'] = 'Development via nose'
41 os
.environ
['SERVER_NAME'] = 'Foo'
42 os
.environ
['SERVER_PORT'] = '8080'
43 os
.environ
['APPLICATION_ID'] = 'test-app-run'
44 os
.environ
['USER_EMAIL'] = 'test@example.com'
45 import main
as app_main
46 from google
.appengine
.api
import apiproxy_stub_map
47 from google
.appengine
.api
import datastore_file_stub
48 from google
.appengine
.api
import mail_stub
49 from google
.appengine
.api
import user_service_stub
50 from google
.appengine
.api
import urlfetch_stub
51 from google
.appengine
.api
.memcache
import memcache_stub
52 apiproxy_stub_map
.apiproxy
= apiproxy_stub_map
.APIProxyStubMap()
53 apiproxy_stub_map
.apiproxy
.RegisterStub('urlfetch',
54 urlfetch_stub
.URLFetchServiceStub())
55 apiproxy_stub_map
.apiproxy
.RegisterStub('user',
56 user_service_stub
.UserServiceStub())
57 apiproxy_stub_map
.apiproxy
.RegisterStub('datastore',
58 datastore_file_stub
.DatastoreFileStub('your_app_id', None, None))
59 apiproxy_stub_map
.apiproxy
.RegisterStub('memcache',
60 memcache_stub
.MemcacheServiceStub())
61 apiproxy_stub_map
.apiproxy
.RegisterStub('mail', mail_stub
.MailServiceStub())
62 import django
.test
.utils
63 django
.test
.utils
.setup_test_environment()
64 nose
.main(plugins
=[AppEngineDatastoreClearPlugin(), ])
67 if __name__
== '__main__':