예제 #1
0
class TestLogService(unittest.TestCase):

    MSG = "Random message"
    SERVICE_NAME = "RandomService"
    SERVICE_SHARD = 0
    OPERATION = "Random operation"
    CREATED = 1234567890.123
    EXC_TEXT = "Random exception"

    def setUp(self):
        self.service = LogService(0)

    def test_last_messages(self):
        for severity in ["CRITICAL",
                         "ERROR",
                         "WARNING"]:
            self.helper_test_last_messages(severity)
        for severity in ["INFO",
                         "DEBUG"]:
            self.helper_test_last_messages(severity, saved=False)

    def helper_test_last_messages(self, severity, saved=True):
        self.service.Log(
            msg=TestLogService.MSG + severity,
            levelname=severity,
            levelno=getattr(logging, severity),
            created=TestLogService.CREATED,
            service_name=TestLogService.SERVICE_NAME + severity,
            service_shard=TestLogService.SERVICE_SHARD,
            operation=TestLogService.OPERATION + severity,
            exc_text=TestLogService.EXC_TEXT + severity)
        last_message = self.service.last_messages()[-1]
        if saved:
            self.assertEquals(last_message["message"],
                              TestLogService.MSG + severity)
            self.assertEquals(last_message["coord"],
                              TestLogService.SERVICE_NAME + severity +
                              "," + ("%d" % TestLogService.SERVICE_SHARD))
            self.assertEquals(last_message["operation"],
                              TestLogService.OPERATION + severity)
            self.assertEquals(last_message["severity"],
                              severity)
            self.assertEquals(last_message["timestamp"],
                              TestLogService.CREATED)
            self.assertEquals(last_message["exc_text"],
                              TestLogService.EXC_TEXT + severity)
            pass
        else:
            self.assertNotEquals(last_message["severity"], severity)
예제 #2
0
파일: LogServiceTest.py 프로젝트: Mloc/cms
class TestLogService(unittest.TestCase):

    MESSAGE = "Random message"
    COORD = "Random coordinates"
    OPERATION = "Random operation"
    TIMESTAMP = 1234567890

    def setUp(self):
        self.service = LogService(0)

    def test_last_messages(self):
        for severity in [SEV_CRITICAL,
                         SEV_ERROR,
                         SEV_WARNING]:
            self.helper_test_last_messages(severity)

    def helper_test_last_messages(self, severity):
        self.service.Log(TestLogService.MESSAGE,
                         TestLogService.COORD,
                         TestLogService.OPERATION,
                         severity,
                         TestLogService.TIMESTAMP)
        last_message = self.service.last_messages()[-1]
        self.assertEquals(last_message["message"], TestLogService.MESSAGE)
        self.assertEquals(last_message["coord"], TestLogService.COORD)
        self.assertEquals(last_message["operation"], TestLogService.OPERATION)
        self.assertEquals(last_message["severity"], severity)
        self.assertEquals(last_message["timestamp"], TestLogService.TIMESTAMP)
        pass
예제 #3
0
class TestLogService(unittest.TestCase):

    MSG = "Random message"
    SERVICE_NAME = "RandomService"
    SERVICE_SHARD = 0
    OPERATION = "Random operation"
    CREATED = 1234567890.123
    EXC_TEXT = "Random exception"

    def setUp(self):
        self.service = LogService(0)

    def test_last_messages(self):
        for severity in ["CRITICAL",
                         "ERROR",
                         "WARNING"]:
            self.helper_test_last_messages(severity)
        for severity in ["INFO",
                         "DEBUG"]:
            self.helper_test_last_messages(severity, saved=False)

    def helper_test_last_messages(self, severity, saved=True):
        self.service.Log(
            msg=TestLogService.MSG + severity,
            levelname=severity,
            levelno=getattr(logging, severity),
            created=TestLogService.CREATED,
            service_name=TestLogService.SERVICE_NAME + severity,
            service_shard=TestLogService.SERVICE_SHARD,
            operation=TestLogService.OPERATION + severity,
            exc_text=TestLogService.EXC_TEXT + severity)
        last_message = self.service.last_messages()[-1]
        if saved:
            self.assertEquals(last_message["message"],
                              TestLogService.MSG + severity)
            self.assertEquals(last_message["coord"],
                              TestLogService.SERVICE_NAME + severity +
                              "," + str(TestLogService.SERVICE_SHARD))
            self.assertEquals(last_message["operation"],
                              TestLogService.OPERATION + severity)
            self.assertEquals(last_message["severity"],
                              severity)
            self.assertEquals(last_message["timestamp"],
                              TestLogService.CREATED)
            self.assertEquals(last_message["exc_text"],
                              TestLogService.EXC_TEXT + severity)
            pass
        else:
            self.assertNotEquals(last_message["severity"], severity)
예제 #4
0
class TestLogService(unittest.TestCase):

    MESSAGE = "Random message"
    COORD = "Random coordinates"
    OPERATION = "Random operation"
    TIMESTAMP = 1234567890
    EXC_TEXT = "Random exception"

    def setUp(self):
        self.service = LogService(0)

    def test_last_messages(self):
        for severity in [SEV_CRITICAL,
                         SEV_ERROR,
                         SEV_WARNING]:
            self.helper_test_last_messages(severity)
        for severity in [SEV_INFO,
                         SEV_DEBUG]:
            self.helper_test_last_messages(severity, saved=False)

    def helper_test_last_messages(self, severity, saved=True):
        self.service.Log(TestLogService.MESSAGE + severity,
                         TestLogService.COORD + severity,
                         TestLogService.OPERATION + severity,
                         severity,
                         TestLogService.TIMESTAMP,
                         TestLogService.EXC_TEXT + severity)
        last_message = self.service.last_messages()[-1]
        if saved:
            self.assertEquals(last_message["message"],
                              TestLogService.MESSAGE + severity)
            self.assertEquals(last_message["coord"],
                              TestLogService.COORD + severity)
            self.assertEquals(last_message["operation"],
                              TestLogService.OPERATION + severity)
            self.assertEquals(last_message["severity"],
                              severity)
            self.assertEquals(last_message["timestamp"],
                              TestLogService.TIMESTAMP)
            self.assertEquals(last_message["exc_text"],
                              TestLogService.EXC_TEXT + severity)
            pass
        else:
            self.assertNotEquals(last_message["severity"], severity)
예제 #5
0
 def setUp(self):
     self.service = LogService(0)
예제 #6
0
파일: LogServiceTest.py 프로젝트: Corea/cms
 def setUp(self):
     self.service = LogService(0)