Example #1
0
    def test_all_report(self):
        test_data_base = DataBase()
        log_file_data = test_data_base.read_log_file(log_file)
        test_apache_analysis = ApacheAnalysis(server_ip)

        detailed_data_list = test_apache_analysis.get_detailed_data(
            log_file_data)
        data_set = test_apache_analysis.get_ip_url_set_data(detailed_data_list)
        test_apache_analysis.get_all_url_title_data(data_set)

        object_all = test_apache_analysis.get_all_report(
            detailed_data_list, data_set)

        # 测试文章报表
        object_title = object_all['object_title']
        title_report_rows = object_title._rows
        self.assertEquals(len(title_report_rows), 6)
        for url_info in title_report_rows:
            self.assertIn(url_info[0], mock_title_urls)
            #self.assertIn(url_info[1], mock_title_arttitle)
            self.assertIn(url_info[2], mock_title_visit_count)
            self.assertIn(url_info[3], mock_title_ip_count)
        # 测试完整报表
        object_full = object_all['object_full']
        full_report_rows = object_full._rows
        self.assertEquals(len(full_report_rows), 6)
        for url_info in full_report_rows:
            self.assertIn(url_info[0], mock_full_ips)
            self.assertIn(url_info[1], mock_full_urls)
            self.assertIn(url_info[2], mock_title_visit_count)

        # 测试ip报表的正确性
        object_ip = object_all['object_ip']
        ip_report_rows = object_ip._rows
        self.assertEquals(len(ip_report_rows), 2)
        for url_info in ip_report_rows:
            self.assertIn(url_info[0], mock_ip_ips)
            self.assertIn(url_info[1], mock_ip_visit_count)
            self.assertIn(url_info[2], mock_ip_article_count)
Example #2
0
from common.data_analysis import ApacheAnalysis
from common.data_load import DataBase
from tool.param_analysis import apache_param_analysis

if __name__ == '__main__':
    # 参数检查
    param = apache_param_analysis()
    # 加载数据类
    data_base = DataBase()
    # 获取log文件中的数据
    log_file_data = data_base.read_log_file(param['log_file_path'])
    # 生成日志分析类,设定服务器ip
    apache_analysis = ApacheAnalysis(param['server_ip'])
    
    detailed_data_list = apache_analysis.get_detailed_data(log_file_data)
    data_set = apache_analysis.get_ip_url_set_data(detailed_data_list)
    apache_analysis.get_all_url_title_data(data_set)
    
    if param['report_type'] == 'ip' :
        apache_analysis.get_ip_report(detailed_data_list,data_set)

    if param['report_type'] == 'title' :
        apache_analysis.get_title_report(detailed_data_list,data_set)

    if param['report_type'] == 'full' :
        apache_analysis.get_full_report(detailed_data_list,data_set)

    if param['report_type'] == 'all' :
        apache_analysis.get_all_report(detailed_data_list,data_set)