コード例 #1
0
    def test_parse_log(self):
        self.log_get = '1.169.137.128 -  - [29/jun/2017:07:10:50 +0300] \
                        "GET /api/v2/banner/1717161 http/1.1" 200 2116 "-" "Slotovod" \
                        "-" "1498709450-2118016444-4709-10027411" "712e90144abee9" 0.199'

        self.log_post = '1.126.153.80 -  - [29/Jun/2017:07:10:50 +0300] \
                        "POST /api/v2/banner/22532881/statistic/outgoings/?date_from=2017-06-29 HTTP/1.1" \
                        200 40 "-" "-" "-" "1498709450-48424485-4708-9845489" "1835ae0f17f" 0.126'

        self.log_wrong_url = '1.169.137.128 -  - [29/jun/2017:07:10:50 +0300] \
                            "/api/v2/banner/1717161 HTTP/1.1" 200 2116 "-" "Slotovod" "-" \
                            "1498709450-2118016444-4709-10027411" "712e90144abee9" 0.198'

        self.log_wrong_time = '1.169.137.128 -  - [29/jun/2017:07:10:50 +0300] \
                                    "/api/v2/banner/1717161 HTTP/1.1" 200 2116 "-" "Slotovod" \
                                    "-" "1498709450-2118016444-4709-10027411" 0.199 "712e90144abe9e"'

        self.expected_log_get_parsed_req_time = 0.199
        self.expected_log_post_parsed_req_time = 0.126
        self.expected_log_wrong_url_parser_req_time = 0.198
        self.expected_log_wrong_time_parsed_req_time = None
        self.expected_log_get_parsed_url = '/api/v2/banner/1717161'
        self.expected_log_post_parsed_url = '/api/v2/banner/22532881/statistic/outgoings/?date_from=2017-06-29'
        self.expected_log_wrong_url_parsed_url = None
        self.expected_log_wrong_time_parsed_url = '/api/v2/banner/1717161'

        self.get_req_time, self.get_url = parse_log(self.log_get)
        self.post_req_time, self.post_url = parse_log(self.log_post)
        self.wrong_url_req_time, self.wrong_url_url = parse_log(
            self.log_wrong_url)
        self.wrong_time_req_time, self.wrong_time_url = parse_log(
            self.log_wrong_time)

        self.assertEqual(self.expected_log_get_parsed_req_time,
                         float(self.get_req_time))
        self.assertEqual(self.expected_log_get_parsed_url, self.get_url)
        self.assertEqual(self.expected_log_post_parsed_req_time,
                         float(self.post_req_time))
        self.assertEqual(self.expected_log_post_parsed_url, self.post_url)
        self.assertEqual(self.expected_log_wrong_url_parser_req_time,
                         float(self.wrong_url_req_time))
        self.assertEqual(self.expected_log_wrong_url_parsed_url,
                         self.wrong_url_url)
        self.assertEqual(self.expected_log_wrong_time_parsed_req_time,
                         self.wrong_time_req_time)
コード例 #2
0
 def test_parse_if_log_plain(self):
     for parsed in log_analyzer.parse_log(self.plain_temp_file,
                                          re.compile(self.sample),
                                          compressed=False):
         self.assertTrue(parsed in self.data, (self.sample, self.data))
コード例 #3
0
 def test_parse_if_log_gzip(self):
     for parsed in log_analyzer.parse_log(self.gzip_temp_file,
                                          re.compile(self.sample),
                                          compressed=True):
         self.assertTrue(parsed in self.data, (self.sample, self.data))
コード例 #4
0
 def test_treshold(self):
     with self.assertRaises(Exception):
         res = list(parse_log(self.lines, self.pattern, treshold=0.7))
コード例 #5
0
 def test_multiple_lines(self):
     res = list(parse_log(self.lines, self.pattern))
     self.assertEqual(len(res), 2)