~cr3/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to launchpadresults/management/commands/test.py

  • Committer: Marc Tardif
  • Date: 2010-09-23 23:40:07 UTC
  • Revision ID: marc.tardif@canonical.com-20100923234007-kxouzhvgv613957k
Added testing layers and factories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
import os
 
5
 
 
6
from openid.consumer.consumer import Consumer
 
7
 
 
8
from django.core.management.base import BaseCommand
 
9
 
 
10
from zope.testing import testrunner
 
11
 
 
12
 
 
13
class Command(BaseCommand):
 
14
    help = "Runs the test suite for the specified applications, or the entire site if no apps are specified."
 
15
    args = "[appname ...]"
 
16
 
 
17
    requires_model_validation = False
 
18
 
 
19
    def run_from_argv(self, argv):
 
20
        self.execute(*argv)
 
21
 
 
22
    def handle(self, *args, **kwargs):
 
23
        # Use the 'default' configuration if one isn't already defined.
 
24
        os.environ.setdefault("LAUNCHPAD_RESULTS_CONFIG", "default")
 
25
 
 
26
        # Prevent any accidental OpenID authentications during the test run.
 
27
        Consumer.begin = lambda *a, **kw: 1/0
 
28
 
 
29
        # Run tests to call manage.py for subprocesses.
 
30
        top_level = os.path.dirname(
 
31
            os.path.dirname(
 
32
                os.path.dirname(
 
33
                    os.path.dirname(__file__))))
 
34
        defaults = [
 
35
            "--tests-pattern",
 
36
            "^f?tests$",
 
37
            "--test-path",
 
38
            top_level,
 
39
            "--ignore_dir",
 
40
            "build",
 
41
            ]
 
42
        script_parts = [
 
43
            "-S",
 
44
            args[0],
 
45
            args[1],
 
46
            ]
 
47
        args = list(args[1:])
 
48
 
 
49
        testrunner.run(defaults, args, script_parts=script_parts)