tests/run.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 25 Apr 2009 10:13:06 +0200
changeset 2276 ec80019740ea
parent 1690 376e75215f35
child 2294 be2c150d1a1f
permissions -rwxr-xr-x
Fix broken tests by renaming default app id from "your_app_id" to "test-app-run". This fix is required due to changes in GAE 1.2.1. Patch by: Pawel Solyga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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'
1690
376e75215f35 Set CURRENT_VERSION_ID in run.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1009
diff changeset
    45
  os.environ['CURRENT_VERSION_ID'] = 'testing-version'
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    46
  import main as app_main
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    47
  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
    48
  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
    49
  from google.appengine.api import mail_stub
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    50
  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
    51
  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
    52
  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
    53
  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
    54
  apiproxy_stub_map.apiproxy.RegisterStub('urlfetch',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    55
                                          urlfetch_stub.URLFetchServiceStub())
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    56
  apiproxy_stub_map.apiproxy.RegisterStub('user',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    57
                                          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
    58
  apiproxy_stub_map.apiproxy.RegisterStub('datastore',
2276
ec80019740ea Fix broken tests by renaming default app id from "your_app_id" to "test-app-run".
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1690
diff changeset
    59
    datastore_file_stub.DatastoreFileStub('test-app-run', 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
    60
  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
    61
    memcache_stub.MemcacheServiceStub())
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    62
  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
    63
  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
    64
  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
    65
  nose.main(plugins=[AppEngineDatastoreClearPlugin(), ])
419
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
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    68
if __name__ == '__main__':
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    69
  main()