tests/run.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 23 Jan 2009 12:00:48 +0000
changeset 920 39badbfb80be
parent 781 35a2d07e04e8
child 1008 ae1a36ef7cff
permissions -rw-r--r--
Added the new way to process invites for club_admin only. This patch contains the separability needed to ensure that we can successfully do the access checks we need. Host invites can for the time being only be completed by developers due to the reorganization. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
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'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    44
  import main as app_main
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    45
  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
    46
  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
    47
  from google.appengine.api import mail_stub
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    48
  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
    49
  from google.appengine.api import urlfetch_stub
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    50
  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
    51
  apiproxy_stub_map.apiproxy.RegisterStub('urlfetch',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    52
                                          urlfetch_stub.URLFetchServiceStub())
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    53
  apiproxy_stub_map.apiproxy.RegisterStub('user',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    54
                                          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
    55
  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
    56
    datastore_file_stub.DatastoreFileStub('your_app_id', None, None))
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    57
  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
    58
  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
    59
  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
    60
  nose.main(plugins=[AppEngineDatastoreClearPlugin(), ])
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    61
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    62
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    63
if __name__ == '__main__':
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    64
  main()