~alexlauni/tarmac/jenkins-job-chaining

« back to all changes in this revision

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

  • Committer: Didier Roche
  • Date: 2011-11-30 14:36:26 UTC
  • Revision ID: didier.roche@canonical.com-20111130143626-uo2udlrq2bd43rsa
add the ignore merge mode capacity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 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 ignore merge mode plug-in."""
 
17
 
 
18
from tarmac.plugins.ignoremergemode import IgnoreMergeMode, IgnoreMerge, UNIGNORE_KEYWORD
 
19
from tarmac.tests import TarmacTestCase
 
20
from tarmac.tests.mock import Thing
 
21
 
 
22
import os
 
23
import tempfile
 
24
 
 
25
class IgnoreMergeModeTests(TarmacTestCase):
 
26
    """Test the ignore merge mode plugin."""
 
27
    
 
28
    
 
29
    def setUp(self):
 
30
        super(IgnoreMergeModeTests, self).setUp()
 
31
        self.ignoremergefile = tempfile.mkstemp()[1]
 
32
        self.plugin = IgnoreMergeMode()
 
33
        self.proposal = Thing(
 
34
            source_branch = Thing(display_name='lp:foo/bar'),
 
35
            description = 'foo %s bar' % UNIGNORE_KEYWORD)
 
36
        self.target = Thing(config=Thing(ignoremerge_on=self.ignoremergefile))
 
37
        
 
38
    def tearDown(self):
 
39
        super(IgnoreMergeModeTests, self).tearDown()
 
40
        try:
 
41
            os.remove(self.ignoremergefile)
 
42
        except OSError:
 
43
            pass
 
44
            
 
45
    def test_no_block(self):
 
46
        """Test that with no ignore mode file, we don't reject the branch"""
 
47
        self.target = Thing(config=Thing())
 
48
        # should not raise anything
 
49
        self.plugin.run(command=None, target=self.target, source=None,
 
50
                        proposal=self.proposal)
 
51
        
 
52
    def test_ignore_branch(self):
 
53
        """Ensure an ordinary branch raise an exception and so, ignored"""
 
54
        self.proposal.description = "foo"
 
55
        self.assertRaises(IgnoreMerge, self.plugin.run, command=None,
 
56
                          target=self.target, source=None,
 
57
                          proposal=self.proposal)
 
58
                          
 
59
    def test_unignored_branch(self):
 
60
        """Ensure the special branch that can pass the merge ignore check"""
 
61
        self.plugin.run(command=None, target=self.target, source=None,
 
62
                        proposal=self.proposal)
 
63
                        
 
64
    def test_in_ignore_mode(self):
 
65
        """Test that we are in ignored mode with one file"""
 
66
        self.assertTrue(self.plugin._in_ignore_mode([self.ignoremergefile]))
 
67
        
 
68
    def test_ignore_mode_with_two_files(self):
 
69
        """Test that we are in ignore mode with two files, one not existing"""
 
70
        self.assertTrue(self.plugin._in_ignore_mode(["abcd", self.ignoremergefile]))
 
71
        
 
72
    def test_not_ignore_mode(self):
 
73
        """Test that we are not in ignore mode with two unexisting files, one empty"""
 
74
        self.assertFalse(self.plugin._in_ignore_mode(["abcd", ""]))
 
75
        
 
76
    def test_ignored_branch(self):
 
77
        """Test that a ignored branch should be ignored"""
 
78
        self.assertTrue(self.plugin._branch_should_be_ignored("foo"))
 
79
        
 
80
    def test_unignored_branch(self):
 
81
        """Test that a branch with the right keyword should not be ignored"""
 
82
        self.assertFalse(self.plugin._branch_should_be_ignored("foo %s" % UNIGNORE_KEYWORD))