tests/run.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 13 Aug 2009 10:23:31 -0700
changeset 2767 4011d44ba0b6
parent 2662 833785d10ecf
child 2917 b9f600436e89
permissions -rwxr-xr-x
Changed to_dict to call all callable values when their key is in field_names. This is useful for instance when exporting role instances and you want to export document_name.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2402
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     1
#!/usr/bin/python2.5
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     2
#
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     3
# Copyright 2009 the Melange authors.
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     4
#
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     6
# you may not use this file except in compliance with the License.
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     7
# You may obtain a copy of the License at
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     8
#
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    10
#
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    14
# See the License for the specific language governing permissions and
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    15
# limitations under the License.
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    16
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    17
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    18
__authors__ = [
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    19
  '"Augie Fackler" <durin42@gmail.com>',
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    20
  ]
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    21
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    22
import sys
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    23
import os
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    24
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    25
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
    26
                                     '..'))
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    27
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
    28
extra_paths = [HERE,
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    29
               os.path.join(appengine_location, 'lib', 'django'),
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    30
               os.path.join(appengine_location, 'lib', 'webob'),
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    31
               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
    32
               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
    33
               appengine_location,
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    34
               os.path.join(HERE, 'app'),
780
042aafcd7dce Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents: 421
diff changeset
    35
               os.path.join(HERE, 'thirdparty', 'coverage'),
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    36
              ]
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
import nose
781
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    39
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
    40
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    41
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
    42
  """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
    43
  """
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    44
  name = 'AppEngineDatastoreClearPlugin'
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    45
  enabled = True
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    46
  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
    47
    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
    48
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    49
  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
    50
    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
    51
    self.enabled = True
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    52
35a2d07e04e8 Fix the setup of the test environment, including clearing the datastore
Augie Fackler <durin42@gmail.com>
parents: 780
diff changeset
    53
  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
    54
    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
    55
    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
    56
    # 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
    57
    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
    58
      datastore.Clear()
780
042aafcd7dce Add support for coverage to our testing system.
Augie Fackler <durin42@gmail.com>
parents: 421
diff changeset
    59
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    60
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    61
def main():
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    62
  sys.path = extra_paths + sys.path
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    63
  os.environ['SERVER_SOFTWARE'] = 'Development via nose'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    64
  os.environ['SERVER_NAME'] = 'Foo'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    65
  os.environ['SERVER_PORT'] = '8080'
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    66
  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
    67
  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
    68
  os.environ['CURRENT_VERSION_ID'] = 'testing-version'
2402
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    69
  os.environ['HTTP_HOST'] = 'some.testing.host.tld'
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    70
  import main as app_main
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    71
  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
    72
  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
    73
  from google.appengine.api import mail_stub
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    74
  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
    75
  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
    76
  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
    77
  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
    78
  apiproxy_stub_map.apiproxy.RegisterStub('urlfetch',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    79
                                          urlfetch_stub.URLFetchServiceStub())
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    80
  apiproxy_stub_map.apiproxy.RegisterStub('user',
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    81
                                          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
    82
  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
    83
    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
    84
  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
    85
    memcache_stub.MemcacheServiceStub())
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    86
  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
    87
  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
    88
  django.test.utils.setup_test_environment()
2402
c4958af14634 Add HTTP_HOST to environ variables mocked. Also add license headers to run.py.
Augie Fackler <durin42@gmail.com>
parents: 2314
diff changeset
    89
2662
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    90
  # register a core for the test modules to use
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    91
  from soc.modules import callback
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    92
  from soc.modules import core
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    93
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    94
  callback.registerCore(core.Core())
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    95
  callback.getCore().registerModuleCallbacks()
833785d10ecf register a core for the test modules to use
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2402
diff changeset
    96
2298
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    97
  from nose.plugins import cover
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    98
  plugin = cover.Coverage()
c7c331ed9a49 Add coverage support to the test suite
Marcelo de Sena Lacerda <marceloslacerda@gmail.com>
parents: 2294
diff changeset
    99
  nose.main(plugins=[AppEngineDatastoreClearPlugin(), plugin])
419
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   100
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   101
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   102
if __name__ == '__main__':
e9280ea935e4 Start a test system for the webapp itself.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   103
  main()