"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/test/unit/test_data_steps.py" (24 Nov 2019, 14346 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 
   17 from twisted.internet import defer
   18 from twisted.trial import unittest
   19 
   20 from buildbot.data import steps
   21 from buildbot.test.fake import fakedb
   22 from buildbot.test.fake import fakemaster
   23 from buildbot.test.util import endpoint
   24 from buildbot.test.util import interfaces
   25 from buildbot.test.util.misc import TestReactorMixin
   26 from buildbot.util import epoch2datetime
   27 
   28 TIME1 = 2001111
   29 TIME2 = 2002222
   30 TIME3 = 2003333
   31 
   32 
   33 class StepEndpoint(endpoint.EndpointMixin, unittest.TestCase):
   34 
   35     endpointClass = steps.StepEndpoint
   36     resourceTypeClass = steps.Step
   37 
   38     def setUp(self):
   39         self.setUpEndpoint()
   40         self.db.insertTestData([
   41             fakedb.Worker(id=47, name='linux'),
   42             fakedb.Builder(id=77, name='builder77'),
   43             fakedb.Master(id=88),
   44             fakedb.Buildset(id=8822),
   45             fakedb.BuildRequest(id=82, buildsetid=8822),
   46             fakedb.Build(id=30, builderid=77, number=7, masterid=88,
   47                          buildrequestid=82, workerid=47),
   48             fakedb.Step(id=70, number=0, name='one', buildid=30,
   49                         started_at=TIME1, complete_at=TIME2, results=0),
   50             fakedb.Step(id=71, number=1, name='two', buildid=30,
   51                         started_at=TIME2, complete_at=TIME3, results=2,
   52                         urls_json='[{"name":"url","url":"http://url"}]'),
   53             fakedb.Step(id=72, number=2, name='three', buildid=30,
   54                         started_at=TIME3, hidden=True),
   55         ])
   56 
   57     def tearDown(self):
   58         self.tearDownEndpoint()
   59 
   60     @defer.inlineCallbacks
   61     def test_get_existing(self):
   62         step = yield self.callGet(('steps', 72))
   63         self.validateData(step)
   64         self.assertEqual(step, {
   65             'buildid': 30,
   66             'complete': False,
   67             'complete_at': None,
   68             'name': 'three',
   69             'number': 2,
   70             'results': None,
   71             'started_at': epoch2datetime(TIME3),
   72             'state_string': '',
   73             'stepid': 72,
   74             'urls': [],
   75             'hidden': True})
   76 
   77     @defer.inlineCallbacks
   78     def test_get_existing_buildid_name(self):
   79         step = yield self.callGet(('builds', 30, 'steps', 'two'))
   80         self.validateData(step)
   81         self.assertEqual(step['stepid'], 71)
   82 
   83     @defer.inlineCallbacks
   84     def test_get_existing_buildid_number(self):
   85         step = yield self.callGet(('builds', 30, 'steps', 1))
   86         self.validateData(step)
   87         self.assertEqual(step['stepid'], 71)
   88 
   89     @defer.inlineCallbacks
   90     def test_get_existing_builder_name(self):
   91         step = yield self.callGet(('builders', 77, 'builds', 7, 'steps', 'two'))
   92         self.validateData(step)
   93         self.assertEqual(step['stepid'], 71)
   94 
   95     @defer.inlineCallbacks
   96     def test_get_existing_buildername_name(self):
   97         step = yield self.callGet(('builders', 'builder77', 'builds', 7, 'steps', 'two'))
   98         self.validateData(step)
   99         self.assertEqual(step['stepid'], 71)
  100 
  101     @defer.inlineCallbacks
  102     def test_get_existing_builder_number(self):
  103         step = yield self.callGet(('builders', 77, 'builds', 7, 'steps', 1))
  104         self.validateData(step)
  105         self.assertEqual(step['stepid'], 71)
  106 
  107     @defer.inlineCallbacks
  108     def test_get_missing_buildername_builder_number(self):
  109         step = yield self.callGet(('builders', 'builder77_nope', 'builds', 7, 'steps', 1))
  110         self.assertEqual(step, None)
  111 
  112     @defer.inlineCallbacks
  113     def test_get_missing(self):
  114         step = yield self.callGet(('steps', 9999))
  115         self.assertEqual(step, None)
  116 
  117 
  118 class StepsEndpoint(endpoint.EndpointMixin, unittest.TestCase):
  119 
  120     endpointClass = steps.StepsEndpoint
  121     resourceTypeClass = steps.Step
  122 
  123     def setUp(self):
  124         self.setUpEndpoint()
  125         self.db.insertTestData([
  126             fakedb.Worker(id=47, name='linux'),
  127             fakedb.Builder(id=77, name='builder77'),
  128             fakedb.Master(id=88),
  129             fakedb.Buildset(id=8822),
  130             fakedb.BuildRequest(id=82, buildsetid=8822),
  131             fakedb.Build(id=30, builderid=77, number=7, masterid=88,
  132                          buildrequestid=82, workerid=47),
  133             fakedb.Build(id=31, builderid=77, number=8, masterid=88,
  134                          buildrequestid=82, workerid=47),
  135             fakedb.Step(id=70, number=0, name='one', buildid=30,
  136                         started_at=TIME1, complete_at=TIME2, results=0),
  137             fakedb.Step(id=71, number=1, name='two', buildid=30,
  138                         started_at=TIME2, complete_at=TIME3, results=2,
  139                         urls_json='[{"name":"url","url":"http://url"}]'),
  140             fakedb.Step(id=72, number=2, name='three', buildid=30,
  141                         started_at=TIME3),
  142             fakedb.Step(id=73, number=0, name='otherbuild', buildid=31,
  143                         started_at=TIME2),
  144         ])
  145 
  146     def tearDown(self):
  147         self.tearDownEndpoint()
  148 
  149     @defer.inlineCallbacks
  150     def test_get_buildid(self):
  151         steps = yield self.callGet(('builds', 30, 'steps'))
  152         [self.validateData(step) for step in steps]
  153         self.assertEqual([s['number'] for s in steps], [0, 1, 2])
  154 
  155     @defer.inlineCallbacks
  156     def test_get_builder(self):
  157         steps = yield self.callGet(('builders', 77, 'builds', 7, 'steps'))
  158         [self.validateData(step) for step in steps]
  159         self.assertEqual([s['number'] for s in steps], [0, 1, 2])
  160 
  161     @defer.inlineCallbacks
  162     def test_get_buildername(self):
  163         steps = yield self.callGet(('builders', 'builder77', 'builds', 7, 'steps'))
  164         [self.validateData(step) for step in steps]
  165         self.assertEqual([s['number'] for s in steps], [0, 1, 2])
  166 
  167 
  168 class Step(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase):
  169 
  170     def setUp(self):
  171         self.setUpTestReactor()
  172         self.master = fakemaster.make_master(self, wantMq=True, wantDb=True,
  173                                              wantData=True)
  174         self.rtype = steps.Step(self.master)
  175 
  176     def test_signature_newStep(self):
  177         @self.assertArgSpecMatches(
  178             self.master.data.updates.addStep,  # fake
  179             self.rtype.addStep)  # real
  180         def newStep(self, buildid, name):
  181             pass
  182 
  183     @defer.inlineCallbacks
  184     def test_newStep(self):
  185         stepid, number, name = yield self.rtype.addStep(buildid=10,
  186                                                         name='name')
  187         msgBody = {
  188             'buildid': 10,
  189             'complete': False,
  190             'complete_at': None,
  191             'name': name,
  192             'number': number,
  193             'results': None,
  194             'started_at': None,
  195             'state_string': 'pending',
  196             'stepid': stepid,
  197             'urls': [],
  198             'hidden': False,
  199         }
  200         self.master.mq.assertProductions([
  201             (('builds', '10', 'steps', str(stepid), 'new'), msgBody),
  202             (('steps', str(stepid), 'new'), msgBody),
  203         ])
  204         step = yield self.master.db.steps.getStep(stepid)
  205         self.assertEqual(step, {
  206             'buildid': 10,
  207             'complete_at': None,
  208             'id': stepid,
  209             'name': name,
  210             'number': number,
  211             'results': None,
  212             'started_at': None,
  213             'state_string': 'pending',
  214             'urls': [],
  215             'hidden': False,
  216         })
  217 
  218     @defer.inlineCallbacks
  219     def test_fake_newStep(self):
  220         self.assertEqual(
  221             len((yield self.master.data.updates.addStep(buildid=10,
  222                                                         name='ten'))),
  223             3)
  224 
  225     def test_signature_startStep(self):
  226         @self.assertArgSpecMatches(
  227             self.master.data.updates.startStep,  # fake
  228             self.rtype.startStep)  # real
  229         def newStep(self, stepid):
  230             pass
  231 
  232     @defer.inlineCallbacks
  233     def test_startStep(self):
  234         self.reactor.advance(TIME1)
  235         yield self.master.db.steps.addStep(buildid=10, name='ten',
  236                                            state_string='pending')
  237         yield self.rtype.startStep(stepid=100)
  238 
  239         msgBody = {
  240             'buildid': 10,
  241             'complete': False,
  242             'complete_at': None,
  243             'name': 'ten',
  244             'number': 0,
  245             'results': None,
  246             'started_at': epoch2datetime(TIME1),
  247             'state_string': 'pending',
  248             'stepid': 100,
  249             'urls': [],
  250             'hidden': False,
  251         }
  252         self.master.mq.assertProductions([
  253             (('builds', '10', 'steps', str(100), 'started'), msgBody),
  254             (('steps', str(100), 'started'), msgBody),
  255         ])
  256         step = yield self.master.db.steps.getStep(100)
  257         self.assertEqual(step, {
  258             'buildid': 10,
  259             'complete_at': None,
  260             'id': 100,
  261             'name': 'ten',
  262             'number': 0,
  263             'results': None,
  264             'started_at': epoch2datetime(TIME1),
  265             'state_string': 'pending',
  266             'urls': [],
  267             'hidden': False,
  268         })
  269 
  270     def test_signature_setStepStateString(self):
  271         @self.assertArgSpecMatches(
  272             self.master.data.updates.setStepStateString,  # fake
  273             self.rtype.setStepStateString)  # real
  274         def setStepStateString(self, stepid, state_string):
  275             pass
  276 
  277     @defer.inlineCallbacks
  278     def test_setStepStateString(self):
  279         yield self.master.db.steps.addStep(buildid=10, name='ten',
  280                                            state_string='pending')
  281         yield self.rtype.setStepStateString(stepid=100, state_string='hi')
  282 
  283         msgBody = {
  284             'buildid': 10,
  285             'complete': False,
  286             'complete_at': None,
  287             'name': 'ten',
  288             'number': 0,
  289             'results': None,
  290             'started_at': None,
  291             'state_string': 'hi',
  292             'stepid': 100,
  293             'urls': [],
  294             'hidden': False,
  295         }
  296         self.master.mq.assertProductions([
  297             (('builds', '10', 'steps', str(100), 'updated'), msgBody),
  298             (('steps', str(100), 'updated'), msgBody),
  299         ])
  300         step = yield self.master.db.steps.getStep(100)
  301         self.assertEqual(step, {
  302             'buildid': 10,
  303             'complete_at': None,
  304             'id': 100,
  305             'name': 'ten',
  306             'number': 0,
  307             'results': None,
  308             'started_at': None,
  309             'state_string': 'hi',
  310             'urls': [],
  311             'hidden': False,
  312         })
  313 
  314     def test_signature_finishStep(self):
  315         @self.assertArgSpecMatches(
  316             self.master.data.updates.finishStep,  # fake
  317             self.rtype.finishStep)  # real
  318         def finishStep(self, stepid, results, hidden):
  319             pass
  320 
  321     @defer.inlineCallbacks
  322     def test_finishStep(self):
  323         yield self.master.db.steps.addStep(buildid=10, name='ten',
  324                                            state_string='pending')
  325         self.reactor.advance(TIME1)
  326         yield self.rtype.startStep(stepid=100)
  327         self.reactor.advance(TIME2 - TIME1)
  328         self.master.mq.clearProductions()
  329         yield self.rtype.finishStep(stepid=100, results=9, hidden=False)
  330 
  331         msgBody = {
  332             'buildid': 10,
  333             'complete': True,
  334             'complete_at': epoch2datetime(TIME2),
  335             'name': 'ten',
  336             'number': 0,
  337             'results': 9,
  338             'started_at': epoch2datetime(TIME1),
  339             'state_string': 'pending',
  340             'stepid': 100,
  341             'urls': [],
  342             'hidden': False,
  343         }
  344         self.master.mq.assertProductions([
  345             (('builds', '10', 'steps', str(100), 'finished'), msgBody),
  346             (('steps', str(100), 'finished'), msgBody),
  347         ])
  348         step = yield self.master.db.steps.getStep(100)
  349         self.assertEqual(step, {
  350             'buildid': 10,
  351             'complete_at': epoch2datetime(TIME2),
  352             'id': 100,
  353             'name': 'ten',
  354             'number': 0,
  355             'results': 9,
  356             'started_at': epoch2datetime(TIME1),
  357             'state_string': 'pending',
  358             'urls': [],
  359             'hidden': False,
  360         })
  361 
  362     def test_signature_addStepURL(self):
  363         @self.assertArgSpecMatches(
  364             self.master.data.updates.addStepURL,  # fake
  365             self.rtype.addStepURL)  # real
  366         def addStepURL(self, stepid, name, url):
  367             pass
  368 
  369     @defer.inlineCallbacks
  370     def test_addStepURL(self):
  371         yield self.master.db.steps.addStep(buildid=10, name='ten',
  372                                            state_string='pending')
  373         yield self.rtype.addStepURL(stepid=100, name="foo", url="bar")
  374 
  375         msgBody = {
  376             'buildid': 10,
  377             'complete': False,
  378             'complete_at': None,
  379             'name': 'ten',
  380             'number': 0,
  381             'results': None,
  382             'started_at': None,
  383             'state_string': 'pending',
  384             'stepid': 100,
  385             'urls': [{'name': 'foo', 'url': 'bar'}],
  386             'hidden': False,
  387         }
  388         self.master.mq.assertProductions([
  389             (('builds', '10', 'steps', str(100), 'updated'), msgBody),
  390             (('steps', str(100), 'updated'), msgBody),
  391         ])
  392         step = yield self.master.db.steps.getStep(100)
  393         self.assertEqual(step, {
  394             'buildid': 10,
  395             'complete_at': None,
  396             'id': 100,
  397             'name': 'ten',
  398             'number': 0,
  399             'results': None,
  400             'started_at': None,
  401             'state_string': 'pending',
  402             'urls': [{'name': 'foo', 'url': 'bar'}],
  403             'hidden': False,
  404         })