Ejemplo n.º 1
0
def verify_csv_with_ui(ui):
    current_file = _get_current_csv_path()
    ignore = ['Generated', 'Received']
    equivalent_value = ['', 'N/A']
    ignore_index = []
    current = csv_handler.parse_csv(current_file, delimiter='\t')
    for row_idx in range(len(ui)):
        current[row_idx] = current[row_idx][1:]
        if row_idx == 0:
            for i in ignore:
                if i in ui[row_idx]:
                    ignore_index.append(ui[row_idx].index(i))
            continue
        for column_idx in range(len(ui[row_idx])):
            if column_idx in ignore_index:
                continue
            # An comparison exception
            if ui[row_idx][column_idx] in equivalent_value and current[
                    row_idx][column_idx] in equivalent_value:
                continue
            if ui[row_idx][column_idx] != current[row_idx][column_idx]:
                raise AssertionError(
                    'Content comparison failed, expected: %s, current: %s at %d, %d.'
                    % (ui[row_idx][column_idx], current[row_idx][column_idx],
                       row_idx, column_idx))
Ejemplo n.º 2
0
def downloaded_result_should_same_as_expected(test_case_name,
                                              expected_file_name):
    test_case_name = _get_test_case_id(test_case_name)
    expected_file = os.path.join(test_data_path, test_case_name,
                                 expected_file_name)
    current_file = _get_current_csv_path()
    ignore = ['Generated', 'Received']
    ignore_index = []
    expected = csv_handler.parse_csv(expected_file, delimiter='\t')
    current = csv_handler.parse_csv(current_file, delimiter='\t')
    for row_idx in range(len(expected)):
        if row_idx == 0:
            for i in ignore:
                if i in expected[row_idx]:
                    ignore_index.append(expected[row_idx].index(i))
        for column_idx in range(len(expected[row_idx])):
            if column_idx in ignore_index:
                continue
            if expected[row_idx][column_idx] != current[row_idx][column_idx]:
                raise AssertionError(
                    'Content comparison failed, expected: %s, current: %s at %d, %d.'
                    % (expected[row_idx][column_idx],
                       current[row_idx][column_idx], row_idx, column_idx))
Ejemplo n.º 3
0
def initialize_yara_test_data():
    yara_test_data = os.path.join(
        os.path.dirname(os.path.abspath(__file__)),
        r'..\..\tests\external_api\initial_data\yara.csv')
    test_data_list = csv_handler.parse_csv(yara_test_data)
    dict_list = []
    for sub_list in test_data_list[1:]:
        tmp_dict = {}
        for key, data in zip(test_data_list[0], sub_list):
            tmp_dict.update({key: data})
        dict_list.append(tmp_dict)
    time_offset = -1
    for yara in dict_list:
        TbIOCsYARAFileListFactory(
            FileHashID=yara['FileHashID'],
            FileName=yara['FileName'],
            UploadedFrom=int(yara['UploadedFrom']),
            UploadedBy=yara['UploadedBy'],
            UploadedTime=ExtendDateTime.get_date_by_offset(str(time_offset)))
        time_offset -= 1
Ejemplo n.º 4
0
def initialize_stix_test_data():
    stix_test_data = os.path.join(
        os.path.dirname(os.path.abspath(__file__)),
        r'..\..\tests\external_api\initial_data\stix.csv')
    test_data_list = csv_handler.parse_csv(stix_test_data)
    dict_list = []
    for sub_list in test_data_list[1:]:
        tmp_dict = {}
        for key, data in zip(test_data_list[0], sub_list):
            tmp_dict.update({key: data})
        dict_list.append(tmp_dict)
    time_offset = -1
    for stix in dict_list:
        TbIOCsSTIXFileListFactory(
            FileHashID=stix['FileHashID'],
            FileName=stix['FileName'],
            Title=stix['ShortDesc_Title'],
            UploadedFrom=int(stix['UploadedFrom']),
            UploadedBy=stix['UploadedBy'],
            ExtractingStatus=int(stix['ExtractingStatus']),
            UploadedTime=ExtendDateTime.get_date_by_offset(str(time_offset)))
        time_offset -= 1