"Fossies" - the Fresh Open Source Software Archive 
Member "buildbot-2.5.1/buildbot/test/unit/test_scripts_sendchange.py" (24 Nov 2019, 5303 Bytes) of package /linux/misc/buildbot-2.5.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 # This file is part of Buildbot. Buildbot is free software: you can
2 # redistribute it and/or modify it under the terms of the GNU General Public
3 # License as published by the Free Software Foundation, version 2.
4 #
5 # This program is distributed in the hope that it will be useful, but WITHOUT
6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
8 # details.
9 #
10 # You should have received a copy of the GNU General Public License along with
11 # this program; if not, write to the Free Software Foundation, Inc., 51
12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
13 #
14 # Copyright Buildbot Team Members
15
16 from twisted.internet import defer
17 from twisted.internet import reactor
18 from twisted.trial import unittest
19
20 from buildbot.clients import sendchange as sendchange_client
21 from buildbot.scripts import sendchange
22 from buildbot.test.util import misc
23
24
25 class TestSendChange(misc.StdoutAssertionsMixin, unittest.TestCase):
26
27 class FakeSender:
28
29 def __init__(self, testcase, master, auth, encoding=None):
30 self.master = master
31 self.auth = auth
32 self.encoding = encoding
33 self.testcase = testcase
34
35 def send(self, branch, revision, comments, files, **kwargs):
36 kwargs['branch'] = branch
37 kwargs['revision'] = revision
38 kwargs['comments'] = comments
39 kwargs['files'] = files
40 self.send_kwargs = kwargs
41 d = defer.Deferred()
42 if self.testcase.fail:
43 reactor.callLater(0, d.errback, RuntimeError("oh noes"))
44 else:
45 reactor.callLater(0, d.callback, None)
46 return d
47
48 def setUp(self):
49 self.fail = False # set to true to get Sender.send to fail
50
51 def Sender_constr(*args, **kwargs):
52 self.sender = self.FakeSender(self, *args, **kwargs)
53 return self.sender
54 self.patch(sendchange_client, 'Sender', Sender_constr)
55
56 # undo the effects of @in_reactor
57 self.patch(sendchange, 'sendchange', sendchange.sendchange._orig)
58
59 self.setUpStdoutAssertions()
60
61 @defer.inlineCallbacks
62 def test_sendchange_config(self):
63 rc = yield sendchange.sendchange(dict(encoding='utf16', who='me',
64 auth=['a', 'b'], master='m', branch='br', category='cat',
65 revision='rr', properties={'a': 'b'}, repository='rep',
66 project='prj', vc='git', revlink='rl', when=1234.0,
67 comments='comm', files=('a', 'b'), codebase='cb'))
68
69 self.assertEqual((self.sender.master, self.sender.auth,
70 self.sender.encoding, self.sender.send_kwargs,
71 self.getStdout(), rc),
72 ('m', ['a', 'b'], 'utf16', {
73 'branch': 'br',
74 'category': 'cat',
75 'codebase': 'cb',
76 'comments': 'comm',
77 'files': ('a', 'b'),
78 'project': 'prj',
79 'properties': {'a': 'b'},
80 'repository': 'rep',
81 'revision': 'rr',
82 'revlink': 'rl',
83 'when': 1234.0,
84 'who': 'me',
85 'vc': 'git'},
86 'change sent successfully', 0))
87
88 @defer.inlineCallbacks
89 def test_sendchange_config_no_codebase(self):
90 rc = yield sendchange.sendchange(dict(encoding='utf16', who='me',
91 auth=['a', 'b'], master='m', branch='br', category='cat',
92 revision='rr', properties={'a': 'b'}, repository='rep',
93 project='prj', vc='git', revlink='rl', when=1234.0,
94 comments='comm', files=('a', 'b')))
95
96 self.assertEqual((self.sender.master, self.sender.auth,
97 self.sender.encoding, self.sender.send_kwargs,
98 self.getStdout(), rc),
99 ('m', ['a', 'b'], 'utf16', {
100 'branch': 'br',
101 'category': 'cat',
102 'codebase': None,
103 'comments': 'comm',
104 'files': ('a', 'b'),
105 'project': 'prj',
106 'properties': {'a': 'b'},
107 'repository': 'rep',
108 'revision': 'rr',
109 'revlink': 'rl',
110 'when': 1234.0,
111 'who': 'me',
112 'vc': 'git'},
113 'change sent successfully', 0))
114
115 @defer.inlineCallbacks
116 def test_sendchange_fail(self):
117 self.fail = True
118 rc = yield sendchange.sendchange({})
119
120 self.assertEqual((self.getStdout().split('\n')[0], rc),
121 ('change not sent:', 1))