Remove unused imports and fix too long lines in soc.views.models.site module.
[Melange.git] / tests / run.py
blob9c7eff632b0b6d89e5980c3bbefde2f20a73d665
1 #!/usr/bin/env python
2 import sys
3 import os
5 HERE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
6 '..'))
7 appengine_location = os.path.join(HERE, 'thirdparty', 'google_appengine')
8 extra_paths = [HERE,
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'),
12 appengine_location,
13 os.path.join(HERE, 'app'),
14 os.path.join(HERE, 'thirdparty', 'coverage'),
17 import nose
18 from nose import plugins
20 class AppEngineDatastoreClearPlugin(plugins.Plugin):
21 """Nose plugin to clear the AppEngine datastore between tests.
22 """
23 name = 'AppEngineDatastoreClearPlugin'
24 enabled = True
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)
30 self.enabled = True
32 def afterTest(self, test):
33 from google.appengine.api import apiproxy_stub_map
34 datastore = apiproxy_stub_map.apiproxy.GetStub('datastore')
35 datastore.Clear()
38 def main():
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__':
68 main()