Exemple #1
0
    def test_update_pack_hierarchy(self, tmp_path):
        env = Environment(tmp_path)
        script_dir_path = os.path.dirname(env.SCRIPT_INSTANCE_PATH)
        shutil.rmtree(env.INTEGRATION_INSTANCE_PATH)
        shutil.rmtree(script_dir_path)

        with patch.object(Downloader, "__init__", lambda a, b, c: None):
            downloader = Downloader('', '')
            downloader.output_pack_path = env.PACK_INSTANCE_PATH
            downloader.custom_content = env.CUSTOM_CONTENT
            downloader.update_pack_hierarchy()
            assert os.path.isdir(env.INTEGRATION_INSTANCE_PATH)
            assert os.path.isdir(env.SCRIPT_INSTANCE_PATH)
Exemple #2
0
def test_build_req_params(input, system, it, insecure, endpoint, req_type,
                          req_body, monkeypatch):
    with patch.object(Downloader, "__init__", lambda x, y, z: None):
        monkeypatch.setenv('DEMISTO_BASE_URL',
                           'http://demisto.instance.com:8080/')
        monkeypatch.setenv('DEMISTO_API_KEY', 'API_KEY')
        downloader = Downloader('', '')
        downloader.system_item_type = it
        downloader.insecure = insecure
        downloader.input_files = input
        res_endpoint, res_req_type, res_req_body = downloader.build_req_params(
        )
        assert endpoint == res_endpoint
        assert req_type == res_req_type
        assert req_body == res_req_body
    def test_update_pack_hierarchy(self):
        env_guard = EnvironmentGuardian()
        integration_instance_temp_path, script_dir_temp_path, script_dir_path = \
            env_guard.prepare_environment('test_update_pack_hierarchy')
        test_answer = True

        with patch.object(Downloader, "__init__", lambda a, b, c: None):
            downloader = Downloader('', '')
            downloader.output_pack_path = PACK_INSTANCE_PATH
            downloader.custom_content = CUSTOM_CONTENT
            downloader.update_pack_hierarchy()
            test_answer = test_answer and os.path.isdir(INTEGRATION_INSTANCE_PATH)
            test_answer = test_answer and os.path.isdir(SCRIPT_INSTANCE_PATH)

        env_guard.restore_environment('test_update_pack_hierarchy', integration_instance_temp_path,
                                      script_dir_temp_path, script_dir_path)
        assert test_answer
Exemple #4
0
    def test_merge_and_extract_existing_file_corrupted_dir(
            self, tmp_path, mocker, capsys):
        """
        Given
            - The integration exist in output pack, the directory is corrupted
            (i.e. a file is missing, for example: the image file)

        When
            - An integration about to be downloaded

        Then
            - Ensure integration is downloaded successfully
        """
        env = Environment(tmp_path)
        mocker.patch.object(Downloader,
                            'get_corresponding_pack_file_object',
                            return_value={})
        with patch.object(Downloader, "__init__", lambda a, b, c: None):
            downloader = Downloader('', '')
            downloader.output_pack_path = env.PACK_INSTANCE_PATH
            downloader.log_verbose = False
            downloader.pack_content = env.PACK_CONTENT
            downloader.run_format = False
            downloader.num_merged_files = 0
            downloader.num_added_files = 0
            downloader.log_verbose = False
            downloader.merge_and_extract_existing_file(
                env.INTEGRATION_CUSTOM_CONTENT_OBJECT)
            stdout, _ = capsys.readouterr()
            assert 'Merged' in stdout
Exemple #5
0
 def test_create_dir_name(self, name):
     downloader = Downloader(output='', input='', regex='')
     assert downloader.create_dir_name(name) == 'GSM'
 def test_verify_output_path_is_pack(self, tmp_path, output_path,
                                     valid_ans):
     env = Environment(tmp_path)
     downloader = Downloader(
         output=f'{env.CONTENT_BASE_PATH}/{output_path}', input='')
     assert downloader.verify_output_pack_is_pack() is valid_ans
Exemple #7
0
 def test_get_extracted_file_detail(self, ending, output):
     downloader = Downloader(output='', input='', regex='')
     assert downloader.get_extracted_file_detail(ending) == output
Exemple #8
0
 def test_update_file_prefix(self, name, output):
     downloader = Downloader(output='', input='', regex='')
     assert downloader.update_file_prefix(name) == output
     assert not downloader.update_file_prefix(name).startswith("playbook-")
 def test_update_file_prefix(self, name, output):
     downloader = Downloader(output='', input='')
     assert downloader.update_file_prefix(name) == output
Exemple #10
0
 def test_get_searched_basename(self, name, ending, detail, output):
     downloader = Downloader(output='', input='', regex='')
     assert downloader.get_searched_basename(name, ending, detail) == output
 def test_build_pack_content(self, tmp_path):
     env = Environment(tmp_path)
     downloader = Downloader(output=env.PACK_INSTANCE_PATH, input='')
     downloader.build_pack_content()
     assert ordered(downloader.pack_content) == ordered(env.PACK_CONTENT)
 def test_verify_output_path_is_pack(self, output_path, valid_ans):
     assert EnvironmentGuardian.verify_environment()
     downloader = Downloader(output=f'{CONTENT_BASE_PATH}/{output_path}', input='')
     assert downloader.verify_output_pack_is_pack() is valid_ans
 def test_exist_in_pack_content(self, custom_content_object, exist_in_pack):
     assert EnvironmentGuardian.verify_environment()
     with patch.object(Downloader, "__init__", lambda a, b, c: None):
         downloader = Downloader('', '')
         downloader.pack_content = PACK_CONTENT
         assert downloader.exist_in_pack_content(custom_content_object) is exist_in_pack
 def test_build_custom_content_object(self, path, output_custom_content_object):
     downloader = Downloader(output='', input='')
     assert downloader.build_custom_content_object(path) == output_custom_content_object
 def test_get_main_file_details(self, entity, path, main_id, main_name):
     assert EnvironmentGuardian.verify_environment()
     downloader = Downloader(output='', input='')
     op_id, op_name = downloader.get_main_file_details(entity, os.path.abspath(path))
     assert op_id == main_id
     assert op_name == main_name
 def test_build_pack_content_object(self, entity, path, output_pack_content_object):
     assert EnvironmentGuardian.verify_environment()
     downloader = Downloader(output='', input='')
     pack_content_object = downloader.build_pack_content_object(entity, path)
     assert ordered(pack_content_object) == ordered(output_pack_content_object)
 def test_build_pack_content(self):
     assert EnvironmentGuardian.verify_environment()
     downloader = Downloader(output=PACK_INSTANCE_PATH, input='')
     downloader.build_pack_content()
     assert ordered(downloader.pack_content) == ordered(PACK_CONTENT)
Exemple #18
0
 def test_get_corresponding_pack_file_object(self, tmp_path):
     env = Environment(tmp_path)
     parameters = [{
         'file_name':
         'Test Integration',
         'ex_file_ending':
         'yml',
         'ex_file_detail':
         'yaml',
         'corr_pack_object':
         env.INTEGRATION_PACK_OBJECT,
         'pack_file_object':
         env.INTEGRATION_PACK_OBJECT['Test Integration'][2]
     }, {
         'file_name':
         'Test Integration',
         'ex_file_ending':
         'py',
         'ex_file_detail':
         'python',
         'corr_pack_object':
         env.INTEGRATION_PACK_OBJECT,
         'pack_file_object':
         env.INTEGRATION_PACK_OBJECT['Test Integration'][0]
     }, {
         'file_name':
         'Test Integration',
         'ex_file_ending':
         'png',
         'ex_file_detail':
         'image',
         'corr_pack_object':
         env.INTEGRATION_PACK_OBJECT,
         'pack_file_object':
         env.INTEGRATION_PACK_OBJECT['Test Integration'][3]
     }, {
         'file_name':
         'Test Integration',
         'ex_file_ending':
         'md',
         'ex_file_detail':
         'description',
         'corr_pack_object':
         env.INTEGRATION_PACK_OBJECT,
         'pack_file_object':
         env.INTEGRATION_PACK_OBJECT['Test Integration'][5]
     }, {
         'file_name':
         'TestScript',
         'ex_file_ending':
         'yml',
         'ex_file_detail':
         'yaml',
         'corr_pack_object':
         env.SCRIPT_PACK_OBJECT,
         'pack_file_object':
         env.SCRIPT_PACK_OBJECT['TestScript'][1]
     }, {
         'file_name':
         'TestScript',
         'ex_file_ending':
         'py',
         'ex_file_detail':
         'python',
         'corr_pack_object':
         env.SCRIPT_PACK_OBJECT,
         'pack_file_object':
         env.SCRIPT_PACK_OBJECT['TestScript'][0]
     }, {
         'file_name': 'Fake Name',
         'ex_file_ending': 'py',
         'ex_file_detail': 'python',
         'corr_pack_object': env.SCRIPT_PACK_OBJECT,
         'pack_file_object': {}
     }]
     with patch.object(Downloader, "__init__", lambda a, b, c: None):
         downloader = Downloader('', '')
         downloader.pack_content = env.PACK_CONTENT
         for param in parameters:
             file_name = param['file_name']
             ex_file_ending = param['ex_file_ending']
             ex_file_detail = param['ex_file_detail']
             corr_pack_object = param['corr_pack_object']
             pack_file_object = param['pack_file_object']
             searched_basename = downloader.get_searched_basename(
                 file_name, ex_file_ending, ex_file_detail)
             corr_file = downloader.get_corresponding_pack_file_object(
                 searched_basename, corr_pack_object)
             assert ordered(corr_file) == ordered(pack_file_object)
Exemple #19
0
 def test_file_type_to_entity(self, data, file_type, entity):
     with patch.object(Downloader, "__init__", lambda a, b, c: None):
         downloader = Downloader('', '')
         assert downloader.file_type_to_entity(data, file_type) == entity
Exemple #20
0
def download(**kwargs):
    downloader: Downloader = Downloader(**kwargs)
    return downloader.download()
 def test_get_custom_content_objects(self):
     with patch.object(Downloader, "__init__", lambda a, b, c: None):
         downloader = Downloader('', '')
         downloader.custom_content_temp_dir = CUSTOM_CONTENT_BASE_PATH
         custom_content_objects = downloader.get_custom_content_objects()
         assert ordered(custom_content_objects) == ordered(CUSTOM_CONTENT)