def test_printStateSummary(self):
        startTime = datetime(year=1995,
                             month=4,
                             day=15,
                             hour=12,
                             minute=2,
                             second=5)

        state = stateModel.State(currentState="up", startTime=startTime)
        actualSummary = state.getSummary()
        expectedSummary = "State: up; TimeInSeconds: 0; StartTime: 1995-04-15T12:02:05"
        self.assertEqual(actualSummary, expectedSummary)
    def test_constructorUpdates(self):
        startTime = datetime(year=1995,
                             month=4,
                             day=15,
                             hour=12,
                             minute=2,
                             second=5)

        state = stateModel.State(currentState="up", startTime=startTime)

        self.assertEqual(state.currentState, "up")
        self.assertEqual(state.startTime, startTime)
        self.assertEqual(state.totalTimeInSeconds, 0)
Exemple #3
0
def getRecordedStates(filePath):
    file = open(filePath, "r")
    lines = file.readlines()
    states = list()
    for line in lines:
        stateVar = re.match(
            r'State: (.*); TimeInSeconds: (.*); StartTime: (.*)$', line,
            re.M | re.I)
        startTime = datetime.fromisoformat(stateVar.group(3))
        states.append(
            stateModel.State(currentState=stateVar.group(1),
                             startTime=startTime,
                             durationInSeconds=int(stateVar.group(2))))
    return states
    def test_updateRunningTimeYearTest(self):
        startTime = datetime(year=1995,
                             month=4,
                             day=15,
                             hour=12,
                             minute=2,
                             second=5)

        state = stateModel.State(currentState="up", startTime=startTime)

        offsetTime = datetime(year=1996,
                              month=4,
                              day=15,
                              hour=12,
                              minute=2,
                              second=11)

        state.updateRunningTime(offsetTime)

        self.assertEqual(state.totalTimeInSeconds, 31622406)
def reinitializeDataInState(currentStatus):

    currentState = "up" if currentStatus else "down"
    return (currentStatus,
            stateModel.State(currentState=currentState,
                             startTime=datetime.now()))
def reinitializeDataInState(currentStatus):

    currentState = "up" if currentStatus else "down"
    return (currentStatus,
            stateModel.State(currentState=currentState,
                             startTime=datetime.now()))


def sendNotification(state):
    recordedStates = fileService.getRecordedStates("test.txt")
    state.updateRunningTime(datetime.now())
    recordedStates.append(state)
    uptimeInt = uptimeCalculator.uptime(recordedStates)
    uptimeNotification.sendEmail(str(uptimeInt))


if __name__ == "__main__":
    state = stateModel.State(currentState="up", startTime=datetime.now())
    oldStatus = True
    while True:
        currentStatus = checkSiteIsUp('https://google.com')
        if(checkForStateChange(currentStatus, oldStatus)):

            updateAndPersistState(state)

            if (currentStatus is False):
                sendNotification(state)

            (oldStatus, state) = reinitializeDataInState(currentStatus)
        time.sleep(1)