~tarmac-control-tower/tarmac/main

« back to all changes in this revision

Viewing changes to tarmac/plugins/tests/test_command.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2010-09-22 19:26:20 UTC
  • mfrom: (359.1.1 command-tests)
  • Revision ID: paul@eventuallyanyway.com-20100922192620-2d5kyd7l8ejsjntb
Add tests for the Command plug-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical, Ltd.
 
2
#
 
3
# This file is part of Tarmac.
 
4
#
 
5
# Tarmac is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# Tarmac is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with Tarmac.  If not, see <http://www.gnu.org/licenses/>.
 
16
"""Tests for the Command plug-in."""
 
17
 
 
18
import os
 
19
 
 
20
from tarmac.bin.registry import CommandRegistry
 
21
from tarmac.plugins import command
 
22
from tarmac.tests import TarmacTestCase
 
23
from tarmac.tests.test_commands import FakeCommand
 
24
from tarmac.tests.mock import Thing
 
25
 
 
26
 
 
27
class TestCommand(TarmacTestCase):
 
28
    """Test the Command plug-in."""
 
29
 
 
30
    def setUp(self):
 
31
        """Set up additional data we need for all tests."""
 
32
        super(TestCommand, self).setUp()
 
33
        self.proposal = Thing(
 
34
            source_branch=Thing(
 
35
                display_name='lp:project/source'),
 
36
            target_branch=Thing(
 
37
                display_name='lp:project'))
 
38
        self.plugin = command.Command()
 
39
        registry = CommandRegistry(config=self.config)
 
40
        self.command = FakeCommand(registry)
 
41
 
 
42
    def test_run(self):
 
43
        """Test that the plug-in runs without errors."""
 
44
        target = Thing(config=Thing(
 
45
                verify_command="/bin/true"),
 
46
                       tree=Thing(abspath=os.path.abspath))
 
47
        self.plugin.run(
 
48
            command=self.command, target=target, source=None,
 
49
            proposal=self.proposal)
 
50
 
 
51
    def test_run_failure(self):
 
52
        """Test that a failure raises the correct exception."""
 
53
        target = Thing(config=Thing(
 
54
                verify_command="/bin/false"),
 
55
                       tree=Thing(abspath=os.path.abspath))
 
56
        self.assertRaises(command.VerifyCommandFailed,
 
57
                          self.plugin.run,
 
58
                          command=self.command, target=target, source=None,
 
59
                          proposal=self.proposal)