Ejemplo n.º 1
0
    def testLogs2JSON_Mixed(self):
        print '\ntestLogs2JSON_Missing'
        testData = gen_mixed_data()
        f = tempfile.NamedTemporaryFile(delete=True)
        f.write(testData)
        f.flush()

        # Filter out to WARNING and above.
        log_filters = logFilter.LogFilters.copy()
        log_filters['level'] = 'WARNING'
        try:
            lf = logFilter.LogFilterJSON(log_filters)
        except Exception as err:
            sys.stderr.write('Invalid configuration file:%s\n' % err)
            return 1
        json_data = lf.log_file_2_JSON(f.name)
        f.close()

        # Pretty print json
        json_internal = json.loads(json_data)
        """
        print json.dumps(json_internal, sort_keys=True, indent=4,
                separators=(',', ':'))
        """

        self.failUnless(json_internal[0]['level'] == 'ERROR')
        self.failUnless(json_internal[0]['device'] == 'water01')
        self.failUnless(json_internal[0]['state'] == 'LOW')
Ejemplo n.º 2
0
    def testLogs2JSON_HappyPath(self):
        print '\ntestLogs2JSON_HappyPath'
        testData = gen_happy_path()

        #print 'testData:\n' + testData

        f = tempfile.NamedTemporaryFile(delete=True)
        f.write(testData)
        f.flush()

        try:
            lf = logFilter.LogFilterJSON({})
        except Exception as err:
            sys.stderr.write('Invalid configuration file:%s\n' % err)
            return 1

        json_data = lf.log_file_2_JSON(f.name)
        f.close()

        # Pretty print json
        py_internal = json.loads(json_data)

        #print json.dumps(py_internal, sort_keys=True, indent=4,
        #        separators=(',', ':'))

        self.failUnless(py_internal[0]['level'] == 'DEBUG')
        self.failUnless(py_internal[0]['temp'] == '34.5')

        self.failUnless(py_internal[1]['level'] == 'CMD')
        self.failUnless(py_internal[1]['temp'] == '34.5')
        self.failUnless(py_internal[1]['item'] == 'Good Stuff')
Ejemplo n.º 3
0
 def testLogs2JSON_Bogus_filename(self):
     print '\ntestLogs2JSON_Bogus_filename'
     log_filters = logFilter.LogFilters.copy()
     try:
         lf = logFilter.LogFilterJSON(log_filters)
     except Exception as err:
         sys.stderr.write('Invalid configuration file:%s\n' % err)
         return 1
     result = lf.log_file_2_JSON('/QQQ/ZZZ.bogus')
     self.failUnless(result is None)
Ejemplo n.º 4
0
    def testErrorLevelJSON_1(self):
        print '\ntestErrorLevelJSON - filter to >= ERROR'
        testData = gen_happy_path()
        testData += gen_missing_data()

        f = tempfile.NamedTemporaryFile(delete=True)
        f.write(testData)
        f.flush()

        log_filters = logFilter.LogFilters.copy()
        log_filters['level'] = 'ERROR'
        try:
            lf = logFilter.LogFilterJSON(log_filters)
        except Exception as err:
            sys.stderr.write('Invalid configuration file:%s\n' % err)
            return
        json_data = lf.log_file_2_JSON(f.name)
        f.close()

        json_internal = json.loads(json_data)
        """
        # Pretty print json
        print json.dumps(json_internal, sort_keys=True, indent=4,
                separators=(',', ':'))
        """

        num_debug = countKeyValueJSON(json_internal, 'level', 'DEBUG')
        self.failUnless(num_debug == 0)

        num_info = countKeyValueJSON(json_internal, 'level', 'INFO')
        self.failUnless(num_info == 0)

        num_warnings = countKeyValueJSON(json_internal, 'level', 'WARNING')
        self.failUnless(num_warnings == 0)

        num_error = countKeyValueJSON(json_internal, 'level', 'ERROR')
        self.failUnless(num_error > 0)

        num_critical = countKeyValueJSON(json_internal, 'level', 'CRITICAL')
        self.failUnless(num_critical > 0)

        self.failUnless(json_internal[0]['level'] == 'ERROR')
        self.failUnless(json_internal[0]['temp'] == '999')