def test_build_file_name(): with patch.object(Downloader, "__init__", lambda x, y, z: None): downloader = Downloader('', '') downloader.system_item_type = 'Playbook' file_name = downloader.build_file_name({'name': 'name 1', 'id': 'id'}) assert file_name == 'name_1.yml' downloader.system_item_type = 'Field' file_name = downloader.build_file_name({'name': 'name 1', 'id': 'id'}) assert file_name == 'name_1.json' downloader.system_item_type = 'Field' file_name = downloader.build_file_name({'id': 'id 1'}) assert file_name == 'id_1.json'
def test_arrange_response(): with patch.object(Downloader, "__init__", lambda x, y, z: None): downloader = Downloader('', '') downloader.system_item_type = 'Playbook' system_items_list = downloader.arrange_response({'playbooks': []}) assert system_items_list == [] downloader.system_item_type = 'Classifier' system_items_list = downloader.arrange_response({'classifiers': []}) assert system_items_list == [] downloader.system_item_type = 'Automation' system_items_list = downloader.arrange_response([]) assert system_items_list == []
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_verify_flags(self, system, it, lf, a, o, i, r, res, err, capsys): with patch.object(Downloader, "__init__", lambda x, y, z: None): downloader = Downloader('', '') downloader.list_files = lf downloader.all_custom_content = a downloader.output_pack_path = o downloader.input_files = i downloader.regex = r downloader.download_system_item = system downloader.system_item_type = it answer = downloader.verify_flags() stdout, _ = capsys.readouterr() if err: assert err in stdout assert answer is res