def test_get_last_log_file(self, mock_listdir): mock_listdir.return_value = [ 'nginx-access-ui.log-20170630', 'nginx-access-ui.log-20170629', 'nginx-access-ui.log-20160730' ] last_file = log_analyzer.get_last_log_file(self.config['LOG_DIR']) self.assertEqual(last_file.date, datetime.datetime(2017, 6, 30))
def test_take_last_log_file_gz(self): template = "nginx-access-ui.log-201706" log_name_list = [f"{template}{str(day).zfill(2)}" for day in range(1, 4)] log_file_path_list = [self._generate_gz_sample(log_name, is_remove_plain=True) for log_name in log_name_list] path_to_last_log_file = get_last_log_file(self.path_to_temp) self.assertTrue(path_to_last_log_file in log_file_path_list) self.assertEqual(path_to_last_log_file, log_file_path_list[-1])
def test_process_data(self): """test log_analyzer.process_data""" last_log = la.get_last_log_file(config) data = la.parse_log(last_log.fullname, config) result = la.process_data(data, config) self.assertEqual(result[0]["count"], 2) self.assertEqual(result[0]["count_perc"], 40.000) self.assertEqual(result[0]["time_avg"], 0.450) self.assertEqual(result[0]["time_max"], 0.500) self.assertEqual(result[0]["time_sum"], 0.900) self.assertEqual(result[0]["time_perc"], 60.000)
def test_parse_log(self): """test log_analyzer.parce_log""" last_log = la.get_last_log_file(config) result = la.parse_log(last_log.fullname, config) self.assertEqual(result[0], 5) total_sum = 0 for el in result[2]: total_sum += sum(result[2][el]) self.assertEqual(result[1], total_sum) self.assertEqual(result[1], 1.5) self.assertEqual(len(result[2]), 4)
def test_finds_correct_file(self, mock_listdir): mock_listdir.return_value = [ 'something_wrong_20170630', 'nginx-access-ui.log-20170630.gz', 'nginx-access-ui.log-20160730.py', 'nginx-access-ui.log-20160730.something_wrong_again' ] last_file = log_analyzer.get_last_log_file(self.config['LOG_DIR']) self.assertEqual( last_file.name, os.path.join(self.config['LOG_DIR'], 'nginx-access-ui.log-20170630.gz'))
def test_take_last_log_wrong_format_date(self): self._generate_plain_sample("nginx-access-ui.log-01052017") with self.assertRaises(SystemExit) as exc: get_last_log_file(self.path_to_temp)
def test_get_last_log(self): self.assertEqual(get_last_log_file('./tests/fixtures/log').date.strftime('%Y.%m.%d'), '2017.08.26')
def test_get_log_make_report(self): """test log_analyzer.get_last_log and log_analyzer.make_report_name together""" last_log = la.get_last_log_file(config) report_name = la.make_report_name(last_log, config) self.assertEqual(report_name, "./test_reports/report-2017.08.30.html")
def test_get_last_log_file(self): """test log_analyzer.get_last_log""" self.assertEqual( la.get_last_log_file(config).fullname, "./test_log/nginx-access-ui.log-20170830")