tests/run.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Tue, 02 Jun 2009 19:20:14 +0200
changeset 2381 2449a52035ee
parent 2314 0a0e603215d7
child 2402 c4958af14634
permissions -rwxr-xr-x
Rename soc-090421.css and update base.html template.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2294
be2c150d1a1f Use python2.5 in our unit tests
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2276
diff changeset
     1
#!/usr/bin/env python2.5
419
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'),
2314
0a0e603215d7 Include required antl3 library and check if datastore is available
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 2298
diff changeset
    12
               os.path.join(appengine_location, 'lib', 'antlr3'),
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    13
               appengine_location,
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    14
               os.path.join(HERE, 'app'),
780
042aafcd7dce Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents: 421
diff changeset
    15
               os.path.join(HERE, 'thirdparty', 'coverage'),
419
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
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    18
import nose
781
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    19
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
    20
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    21
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
    22
  """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
    23
  """
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    24
  name = 'AppEngineDatastoreClearPlugin'
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    25
  enabled = True
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    26
  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
    27
    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
    28
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    29
  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
    30
    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
    31
    self.enabled = True
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    32
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    33
  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
    34
    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
    35
    datastore = apiproxy_stub_map.apiproxy.GetStub('datastore')
2314
0a0e603215d7 Include required antl3 library and check if datastore is available
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 2298
diff changeset
    36
    # clear datastore iff one is available
0a0e603215d7 Include required antl3 library and check if datastore is available
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 2298
diff changeset
    37
    if datastore is not None:
0a0e603215d7 Include required antl3 library and check if datastore is available
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 2298
diff changeset
    38
      datastore.Clear()
780
042aafcd7dce Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents: 421
diff changeset
    39
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    40
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    41
def main():
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    42
  sys.path = extra_paths + sys.path
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    43
  os.environ['SERVER_SOFTWARE'] = 'Development via nose'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    44
  os.environ['SERVER_NAME'] = 'Foo'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    45
  os.environ['SERVER_PORT'] = '8080'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    46
  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
    47
  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
    48
  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
    49
  import main as app_main
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    50
  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
    51
  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
    52
  from google.appengine.api import mail_stub
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    53
  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
    54
  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
    55
  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
    56
  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
    57
  apiproxy_stub_map.apiproxy.RegisterStub('urlfetch',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    58
                                          urlfetch_stub.URLFetchServiceStub())
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    59
  apiproxy_stub_map.apiproxy.RegisterStub('user',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    60
                                          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
    61
  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
    62
    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
    63
  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
    64
    memcache_stub.MemcacheServiceStub())
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    65
  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
    66
  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
    67
  django.test.utils.setup_test_environment()
2298
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    68
  
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    69
  from nose.plugins import cover
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    70
  plugin = cover.Coverage()
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    71
  nose.main(plugins=[AppEngineDatastoreClearPlugin(), plugin])
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    72
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    73
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    74
if __name__ == '__main__':
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    75
  main()