PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/master/buildbot/test/unit/test_reporters_message.py

https://gitlab.com/murder187ss/buildbot
Python | 112 lines | 88 code | 10 blank | 14 comment | 1 complexity | 75133b652f54c557ae3aaca9d2ba78ff MD5 | raw 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. import textwrap
  16. from twisted.internet import defer
  17. from twisted.trial import unittest
  18. from buildbot.process.results import FAILURE
  19. from buildbot.process.results import SUCCESS
  20. from buildbot.reporters import message
  21. from buildbot.reporters import utils
  22. from buildbot.test.fake import fakedb
  23. from buildbot.test.fake import fakemaster
  24. class TestMessage(unittest.TestCase):
  25. def setUp(self):
  26. self.master = fakemaster.make_master(testcase=self,
  27. wantData=True, wantDb=True, wantMq=True)
  28. self.message = message.MessageFormatter()
  29. def setupDb(self, results1, results2):
  30. self.db = self.master.db
  31. self.db.insertTestData([
  32. fakedb.Master(id=92),
  33. fakedb.Worker(id=13, name='wrkr'),
  34. fakedb.Buildset(id=98, results=results1, reason="testReason1"),
  35. fakedb.Buildset(id=99, results=results2, reason="testReason2"),
  36. fakedb.Builder(id=80, name='Builder1'),
  37. fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
  38. fakedb.BuildRequest(id=12, buildsetid=99, builderid=80),
  39. fakedb.Build(id=20, number=0, builderid=80, buildrequestid=11, workerid=13,
  40. masterid=92, results=results1),
  41. fakedb.Build(id=21, number=1, builderid=80, buildrequestid=12, workerid=13,
  42. masterid=92, results=results1),
  43. ])
  44. for _id in (20, 21):
  45. self.db.insertTestData([
  46. fakedb.BuildProperty(buildid=_id, name="workername", value="wrkr"),
  47. fakedb.BuildProperty(buildid=_id, name="reason", value="because"),
  48. ])
  49. @defer.inlineCallbacks
  50. def doOneTest(self, lastresults, results, mode="all"):
  51. self.setupDb(results, lastresults)
  52. res = yield utils.getDetailsForBuildset(self.master, 99, wantProperties=True)
  53. build = res['builds'][0]
  54. buildset = res['buildset']
  55. res = self.message(mode, "Builder1", buildset, build, self.master,
  56. lastresults, ["him@bar", "me@foo"])
  57. defer.returnValue(res)
  58. @defer.inlineCallbacks
  59. def test_message_success(self):
  60. res = yield self.doOneTest(SUCCESS, SUCCESS)
  61. self.assertEqual(res['type'], "plain")
  62. self.assertEqual(res['body'], textwrap.dedent(u'''\
  63. The Buildbot has detected a passing build on builder Builder1 while building Buildbot.
  64. Full details are available at:
  65. http://localhost:8080/#builders/80/builds/1
  66. Buildbot URL: http://localhost:8080/
  67. Worker for this Build: wrkr
  68. Build Reason: because
  69. Blamelist: him@bar, me@foo
  70. Build succeeded!
  71. Sincerely,
  72. -The Buildbot'''))
  73. @defer.inlineCallbacks
  74. def test_message_failure(self):
  75. res = yield self.doOneTest(SUCCESS, FAILURE)
  76. self.assertIn("The Buildbot has detected a failed build on builder", res['body'])
  77. @defer.inlineCallbacks
  78. def test_message_failure_change(self):
  79. res = yield self.doOneTest(SUCCESS, FAILURE, "change")
  80. self.assertIn("The Buildbot has detected a new failure on builder", res['body'])
  81. @defer.inlineCallbacks
  82. def test_message_success_change(self):
  83. res = yield self.doOneTest(FAILURE, SUCCESS, "change")
  84. self.assertIn("The Buildbot has detected a restored build on builder", res['body'])
  85. @defer.inlineCallbacks
  86. def test_message_success_nochange(self):
  87. res = yield self.doOneTest(SUCCESS, SUCCESS, "change")
  88. self.assertIn("The Buildbot has detected a passing build on builder", res['body'])
  89. @defer.inlineCallbacks
  90. def test_message_failure_nochange(self):
  91. res = yield self.doOneTest(FAILURE, FAILURE, "change")
  92. self.assertIn("The Buildbot has detected a failed build on builder", res['body'])