def test_process_line(self): line = utils.log_line('127.0.0.1', '-', 'foo', '01/Jul/2000:00:00:00 +0000', utils.request_line('GET', '/foo', 'HTTP/1.0'), '200', '100') expected = collections.Counter(['foo']) self.collector.process_line(line) self.assertEqual(expected, self.collector.hist)
def test_parse_line_ok(self): line = ('127.0.0.1 - foo [01/Jul/2000:00:00:00 +0000] ' '"GET /foo HTTP/1.0" 200 100') expected = utils.log_line( '127.0.0.1', '-', 'foo', '01/Jul/2000:00:00:00 +0000', utils.request_line('GET', '/foo', 'HTTP/1.0'), '200', '100') actual = utils.parse_line(line) self.assertEqual(expected, actual)
def test_get_stats_normal(self): line = utils.log_line('127.0.0.1', '-', 'foo', '01/Jul/2000:00:00:00 +0000', utils.request_line('GET', '/foo', 'HTTP/1.0'), '200', '100') expected = "1 most hit sections are: foo 1" self.collector.process_line(line) actual = self.collector.get_stats() self.assertEqual(expected, actual)
def test_get_stats_data_ok(self): line = utils.log_line( '127.0.0.1', '-', 'foo', '01/Jul/2000:00:00:00 +0000', utils.request_line('GET', '/foo', 'HTTP/1.0'), '200', '100') expected = self.collector.message % 'foo' self.collector.process_line(line) actual = self.collector.get_stats() self.assertEqual(expected, actual)