Example #1
0
    def test_shouldTurnEachCheckErrorFromTheUsedSchedulersIntoAString(
            self, fix):
        sched1, sched2 = mockSched("first"), mockSched("second")
        rule1, rule2 = mockRule(scheduler=sched1), mockRule(scheduler=sched2)
        validator = self.construct()

        sched1.expectCalls(
            schedCallWithRules("check", rule1, ret=["foo", "bar"]))
        sched2.expectCalls(schedCallWithRules("check", rule2, ret=["quux"]))

        iterToTest(validator.validate(ruleSet(rule1, rule2))).\
            shouldContainMatchingInAnyOrder(
                stringThat.shouldInclude("first", "reported error", "foo"),
                stringThat.shouldInclude("first", "bar"),
                stringThat.shouldInclude("second", "quux"))
Example #2
0
    def test_shouldCheckIfAllSharedOptionValuesOfAllRulesOfASchedulerAreEqual(
            self, fix):
        schedName = "sched-with-shared-opts"
        sched = mockSched(schedName,
                          sharedOptions=[
                              optInfo("ConfDir"),
                              optInfo("DestFile"),
                              optInfo("Version")
                          ])

        def rule(**schedOpts):
            return mockRule(scheduler=sched, schedOpts=schedOpts)

        rules = [
            rule(Version="1", ConfDir="/home", DestFile="/etc/foo"),
            rule(Version="1", ConfDir="/etc", DestFile="/etc/foo"),
            rule(Version="1", ConfDir="/usr/share")
        ]

        validator = self.construct()

        iterToTest(validator.validate(ruleSet(*rules))).\
            shouldContainMatchingInAnyOrder(
                stringThat.shouldInclude("ConfDir", "/home", "/etc", "/usr/share"),
                stringThat.shouldInclude("DestFile", "‘/etc/foo’", "‘’"))
Example #3
0
def test_shouldBeAbleToPredictItsNextExecutionWithHelpOfTheScheduler(fixture):
    lastEndTime, nextTime = orderedDateTimes(2)
    sched = mockSched()

    def rule():
        return fixture.ruleWith(scheduler=sched)

    fixture.log.executions = [execution(endTime=lastEndTime)]

    sched.expectCalls(
        mock.callMatching(
            "nextExecutionTime",
            lambda scheduling: scheduling.lastExecutionTime == lastEndTime,
            ret=nextTime))
    nextExecution = rule().nextExecution
    assert not nextExecution.finished
    assert nextExecution.startTime == nextTime

    sched.expectCalls(
        mock.callMatching("nextExecutionTime", mock.AnyArgs, ret=None))
    assert rule().nextExecution is None

    fixture.log.executions = []
    sched.expectCalls(
        mock.callMatching(
            "nextExecutionTime",
            lambda scheduling: scheduling.lastExecutionTime is None,
            ret=nextTime))
    assert rule().nextExecution.startTime == nextTime

    fixture.log.executions = [execution(unfinished=True)]
    assert rule().nextExecution is None
Example #4
0
 def mockRule(self, loc1, loc2, name=None, **kwargs):
     sched = mockSched()
     sched.check = lambda *args: []
     self.nameCounter += 1
     return mockRule(loc1=loc1,
                     loc2=loc2,
                     name=name or "rule-" + str(self.nameCounter),
                     scheduler=sched,
                     **kwargs)
Example #5
0
    def test_shouldReturnTheErrorsOfTheFirstSchedulerThatHasSome(self, fix):
        sched = mockSched(sharedOptions=[optInfo("UseVarDir")])
        rule1, rule2 = mockRule(scheduler=sched, schedOpts=dict(UseVarDir=True)), \
            mockRule(scheduler=sched, schedOpts=dict(UseVarDir=False))

        def visitSchedulers(visitFunc):
            assert visitFunc(sched, [rule1]) == None
            ret = visitFunc(sched, [rule1, rule2])
            assert len(ret) == 1
            return ret

        ruleSet = lambda x: x
        ruleSet.visitSchedulers = visitSchedulers
        validator = self.construct()
        validator.validate(ruleSet)
Example #6
0
 def makeSched(self, subCheckErrors=[], subExecute=lambda *_: None):
     wrappedSched = mockSched()
     wrappedSched.execute = subExecute
     wrappedSched.check = lambda *args: subCheckErrors
     return self.construct(wrappedSched)