aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_steps_source_oldsource_ComputeRepositoryURL.py
blob: 65c8739d6342b35c8ee744ef2809f2791636428c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from twisted.trial import unittest

from twisted.internet import defer

from buildbot.interfaces import IRenderable
from buildbot.process.properties import Properties, WithProperties
from buildbot.steps.source.oldsource import _ComputeRepositoryURL


class SourceStamp(object):
    repository = "test"

class Build(object):
    s = SourceStamp()
    props = Properties(foo = "bar")
    def getSourceStamp(self, codebase):
        assert codebase == ''
        return self.s
    def getProperties(self):
        return self.props
    def render(self, value):
        self.props.build = self
        return defer.maybeDeferred(IRenderable(value).getRenderingFor, self.props)

class FakeStep(object):
    codebase = ''

class RepoURL(unittest.TestCase):
    def setUp(self):
        self.build = Build()

    def test_backward_compatibility(self):
        url = _ComputeRepositoryURL(FakeStep(), "repourl")
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "repourl")
        return d

    def test_format_string(self):
        url = _ComputeRepositoryURL(FakeStep(), "http://server/%s")
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "http://server/test")
        return d

    def test_dict(self):
        dict = {}
        dict['test'] = "ssh://server/testrepository"
        url = _ComputeRepositoryURL(FakeStep(), dict)
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "ssh://server/testrepository")
        return d

    def test_callable(self):
        func = lambda x: x[::-1]
        url = _ComputeRepositoryURL(FakeStep(), func)
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "tset")
        return d

    def test_backward_compatibility_render(self):
        url = _ComputeRepositoryURL(FakeStep(), WithProperties("repourl%(foo)s"))
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "repourlbar")
        return d

    def test_dict_render(self):
        d = dict(test=WithProperties("repourl%(foo)s"))
        url = _ComputeRepositoryURL(FakeStep(), d)
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "repourlbar")
        return d

    def test_callable_render(self):
        func = lambda x: WithProperties(x+"%(foo)s")
        url = _ComputeRepositoryURL(FakeStep(), func)
        d = self.build.render(url)
        @d.addCallback
        def callback(res):
            self.assertEquals(res, "testbar")
        return d