Ejemplo n.º 1
0
 def test_valid_line(self):
     valid_string = '1.196.116.32 -  - [29/Jun/2017:03:50:22 +0300] ' \
                    '"GET /api/v2/banner/25019354 HTTP/1.1" 200 927 "-" "Lynx/2.8.8dev.9 ' \
                    'libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.10.5" "-" ' \
                    '"1498697422-2190034393-4708-9752759" "dc7161be3" 0.390'
     res = la.process_line(valid_string)
     self.assertIsNotNone(res)
Ejemplo n.º 2
0
    def test_process_line(self):
        """Тестирование парсинга строк"""

        request = "GET /api/v2/banner/25023278 HTTP/1.1"
        request_time = "0.841"
        log = la.process_line("1.196.116.32 -  - [29/Jun/2017:03:50:23 +0300] \"GET /api/v2/banner/25023278 HTTP/1.1\" 200 924 \"-\" \"Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.10.5\" \"-\" \"1498697422-2190034393-4708-9752762\" \"dc7161be3\" 0.841")

        self.assertEqual(log['request'], request)
        self.assertEqual(log['request_time'], request_time)
Ejemplo n.º 3
0
 def test_process_line(self):
     test_line = '1.169.137.128 -  - [29/Jun/2017:03:50:23 +0300]' \
                 ' "GET /api/v2/group/1823183/banners HTTP/1.1" 200 1002' \
                 ' "-" "Configovod" "-" "1498697423-2118016444-4708-9752777"' \
                 ' "712e90144abee9" 0.680'
     test_generator = (line for line in (test_line, ))
     result_line = lg.process_line(test_generator)
     true_result_line = {
         'status': '200',
         'body_bytes_sent': '1002',
         'remote_user': '******',
         'request_time': 0.68,
         'http_referer': '-',
         'remote_addr': '1.169.137.128',
         'http_x_forwarded_for': '-',
         'http_X_REQUEST_ID': '1498697423-2118016444-4708-9752777',
         'request': '/api/v2/group/1823183/banners',
         'http_user_agent': 'Configovod',
         'time_local': '29/Jun/2017:03:50:23 +0300',
         'http_X_RB_USER': '******',
         'http_x_real_ip': '-'
     }
     self.assertEqual(true_result_line, result_line.next())
Ejemplo n.º 4
0
 def test__process_line_bad_url(self):
     self.assertFalse(la.process_line('0 1 2 3 4 5 6 7 8 9 10 11', 42))
Ejemplo n.º 5
0
 def test__process_line_nok(self):
     line = ''
     self.assertFalse(la.process_line(line, 123))
Ejemplo n.º 6
0
 def test__process_line_ok(self):
     out = la.process_line(LogAnalyzerTests.line, 42)
     self.assertEqual(out, {'url': "/api/v2/slot/4705/groups",
                            'request_time': 0.704
                            }
                      )
Ejemplo n.º 7
0
 def test_very_bad_line(self):
     text_1 = """123123123123"""
     self.assertEqual(log_analyzer.process_line(text_1), None)
Ejemplo n.º 8
0
    def test_bad_line(self):
        text_1 = """1.196.116.32 -  - [29/Jun/2017:03:50:23 +0300] "GET /api/v2/banner/25047606 HTTP/1.1" 200 959 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.10.5" "-" "1498697422-2190034393-4708-9752766" "dc7161be3" 2.490"""
        text_2 = """1.196.116.32 -  - [29/Jun/2017:03:50:23 +0300]  200 959 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.10.5" "-" "1498697422-2190034393-4708-9752766" "dc7161be3" 2.490"""

        self.assertEqual(log_analyzer.process_line(text_1), ['/api/v2/banner/25047606', '2.490'])
        self.assertIsNone(log_analyzer.process_line(text_2))