"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/test/unit/test_janitor_configurator.py" (24 Nov 2019, 3115 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 import datetime
   18 from datetime import timedelta
   19 
   20 import mock
   21 
   22 from twisted.internet import defer
   23 from twisted.trial import unittest
   24 
   25 from buildbot.configurators import janitor
   26 from buildbot.configurators.janitor import JANITOR_NAME
   27 from buildbot.configurators.janitor import JanitorConfigurator
   28 from buildbot.configurators.janitor import LogChunksJanitor
   29 from buildbot.process.results import SUCCESS
   30 from buildbot.schedulers.forcesched import ForceScheduler
   31 from buildbot.schedulers.timed import Nightly
   32 from buildbot.test.util import config as configmixin
   33 from buildbot.test.util import configurators
   34 from buildbot.test.util import steps
   35 from buildbot.test.util.misc import TestReactorMixin
   36 from buildbot.util import datetime2epoch
   37 from buildbot.worker.local import LocalWorker
   38 
   39 
   40 class JanitorConfiguratorTests(configurators.ConfiguratorMixin, unittest.SynchronousTestCase):
   41     ConfiguratorClass = JanitorConfigurator
   42 
   43     def test_nothing(self):
   44         self.setupConfigurator()
   45         self.assertEqual(self.config_dict, {
   46         })
   47 
   48     def test_basic(self):
   49         self.setupConfigurator(logHorizon=timedelta(weeks=1))
   50         self.expectWorker(JANITOR_NAME, LocalWorker)
   51         self.expectScheduler(JANITOR_NAME, Nightly)
   52         self.expectScheduler(JANITOR_NAME + "_force", ForceScheduler)
   53         self.expectBuilderHasSteps(JANITOR_NAME, [LogChunksJanitor])
   54         self.expectNoConfigError()
   55 
   56 
   57 class LogChunksJanitorTests(steps.BuildStepMixin,
   58                             configmixin.ConfigErrorsMixin,
   59                             TestReactorMixin,
   60                             unittest.TestCase):
   61 
   62     @defer.inlineCallbacks
   63     def setUp(self):
   64         self.setUpTestReactor()
   65         yield self.setUpBuildStep()
   66         self.patch(janitor, "now", lambda: datetime.datetime(year=2017, month=1, day=1))
   67 
   68     def tearDown(self):
   69         return self.tearDownBuildStep()
   70 
   71     @defer.inlineCallbacks
   72     def test_basic(self):
   73         self.setupStep(
   74             LogChunksJanitor(logHorizon=timedelta(weeks=1)))
   75         self.master.db.logs.deleteOldLogChunks = mock.Mock(return_value=3)
   76         self.expectOutcome(result=SUCCESS,
   77                            state_string="deleted 3 logchunks")
   78         yield self.runStep()
   79         expected_timestamp = datetime2epoch(datetime.datetime(year=2016, month=12, day=25))
   80         self.master.db.logs.deleteOldLogChunks.assert_called_with(expected_timestamp)