def test_file_result(get_branch_info, try_disk, raw_config_parser, data_collector): """ Configuration from file is loaded from the "uploader.json" key. """ if six.PY3: open_name = 'builtins.open' else: open_name = '__builtin__.open' with patch(open_name, create=True) as mock_open: mock_open.side_effect = [ mock.mock_open( read_data='[remove]\nfiles=/etc/some_file,/tmp/another_file'). return_value ] config, pconn = collect_args() collect(config, pconn) name, args, kwargs = try_disk.mock_calls[0] collection_rules = try_disk.return_value.copy() collection_rules.update({"file": args[0]}) rm_conf = {"files": removed_files} branch_info = get_branch_info.return_value data_collector.return_value.run_collection.assert_called_once_with( collection_rules, rm_conf, branch_info) data_collector.return_value.done.assert_called_once_with( collection_rules, rm_conf)
def test_get_conf_file(get_branch_info, get_conf_file, data_collector): """ If there is no config passed via stdin, it is loaded from a file instead. """ config, pconn = collect_args() collect(config, pconn) get_conf_file.assert_called_once_with()
def test_get_conf_called_core_collection(get_branch_info, get_conf_file, core_collector): """ Verify that uploader.json IS loaded when using core collection (from get_rm_conf function) """ config, pconn = collect_args(core_collect=True) collect(config, pconn) get_conf_file.assert_called_once()
def test_get_rm_conf_file(get_branch_info, get_conf_file, get_rm_conf, data_collector): """ Load configuration of files removed from collection when collection rules are loaded from a file. """ config, pconn = collect_args() collect(config, pconn) get_rm_conf.assert_called_once_with()
def test_stdin_signature_valid(get_branch_info, stdin, validate_gpg_sig, data_collector): """ Correct signature of configuration from stdin is recognized. """ config, pconn = collect_args(from_stdin=True) collect(config, pconn) validate_gpg_sig.assert_called_once()
def test_stdin_signature_ignored(get_branch_info, stdin, validate_gpg_sig, data_collector): """ Signature of configuration from stdin is not validated if validation is disabled. """ config, pconn = collect_args(from_stdin=True, gpg=False) collect(config, pconn) validate_gpg_sig.assert_not_called()
def test_get_rm_conf_stdin(get_branch_info, stdin, get_conf_stdin, get_rm_conf, data_collector): """ Load configuration of files removed from collection when collection rules are loaded from stdin. """ config, pconn = collect_args(from_stdin=True) collect(config, pconn) get_rm_conf.assert_called_once_with()
def test_get_conf_not_called_core_collection(get_branch_info, get_conf_file, core_collector): """ Verify that uploader.json is not loaded when using core collection """ config, pconn = collect_args(core_collect=True) collect(config, pconn) get_conf_file.assert_not_called()
def test_file_signature_valid(get_branch_info, validate_gpg_sig, data_collector): """ Correct signature of configuration from a file is recognized. """ config, pconn = collect_args() with patch_temp_conf_file(): collect(config, pconn) validate_gpg_sig.assert_called_once()
def test_file_no_data(get_branch_info, try_disk, data_collector): """ Configuration from file is loaded from the "uploader.json" key. """ config, pconn = collect_args() with raises(ValueError): collect(config, pconn) data_collector.return_value.run_collection.assert_not_called() data_collector.return_value.done.assert_not_called()
def test_stdin_signature_invalid(get_branch_info, stdin, validate_gpg_sig, data_collector): """ Incorrect signature of configuration from stdin causes failure. """ config, pconn = collect_args(from_stdin=True) with raises(Exception): collect(config, pconn) validate_gpg_sig.assert_called_once()
def test_file_signature_invalid(get_branch_info, validate_gpg_sig, data_collector): """ Incorrect signature of configuration from a file skips that file. """ config, pconn = collect_args() with patch_temp_conf_file(): with raises(RuntimeError): collect(config, pconn) validate_gpg_sig.assert_called()
def test_get_conf_stdin(get_branch_info, stdin, get_conf_stdin, get_conf_file, data_collector): """ If there is config passed via stdin, use it and do not look for it in files. """ config, pconn = collect_args(from_stdin=True) collect(config, pconn) get_conf_stdin.assert_called_once_with(stdin_payload) get_conf_file.assert_not_called()
def test_file_signature_ignored(get_branch_info, validate_gpg_sig, data_collector): """ Signature of configuration from a file is not validated if validation is disabled. """ config, pconn = collect_args(gpg=False) with patch_temp_conf_file(): collect(config, pconn) validate_gpg_sig.assert_not_called()
def test_core_collector_file(get_branch_info, get_conf_file, get_rm_conf, core_collector, create_report): """ CoreCollector is loaded with rm_conf and a None value for collection_rules """ config, pconn = collect_args(core_collect=True) collect(config, pconn) collection_rules = None rm_conf = get_rm_conf.return_value branch_info = get_branch_info.return_value blacklist_report = create_report.return_value core_collector.return_value.run_collection.assert_called_once_with(collection_rules, rm_conf, branch_info, blacklist_report) core_collector.return_value.done.assert_called_once_with(collection_rules, rm_conf)
def test_data_collector_file(get_branch_info, get_conf_file, get_rm_conf, data_collector, create_report): """ Configuration from a file is passed to the DataCollector along with removed files configuration. """ config, pconn = collect_args() collect(config, pconn) collection_rules = get_conf_file.return_value rm_conf = get_rm_conf.return_value branch_info = get_branch_info.return_value blacklist_report = create_report.return_value data_collector.return_value.run_collection.assert_called_once_with(collection_rules, rm_conf, branch_info, blacklist_report) data_collector.return_value.done.assert_called_once_with(collection_rules, rm_conf)
def test_data_collector_stdin(get_branch_info, stdin, get_conf_stdin, get_rm_conf, data_collector): """ Configuration from stdin is passed to the DataCollector along with removed files configuration. """ config, pconn = collect_args(from_stdin=True) collect(config, pconn) collection_rules = get_conf_stdin.return_value rm_conf = get_rm_conf.return_value branch_info = get_branch_info.return_value data_collector.return_value.run_collection.assert_called_once_with( collection_rules, rm_conf, branch_info) data_collector.return_value.done.assert_called_once_with( collection_rules, rm_conf)
def test_stdin_result(get_branch_info, stdin, raw_config_parser, validate_gpg_sig, data_collector): """ Configuration from stdin is loaded from the "uploader.json" key. """ config, pconn = collect_args(from_stdin=True) collect(config, pconn) collection_rules = stdin_uploader_json rm_conf = {"files": removed_files} branch_info = get_branch_info.return_value data_collector.return_value.run_collection.assert_called_once_with( collection_rules, rm_conf, branch_info) data_collector.return_value.done.assert_called_once_with( collection_rules, rm_conf)
def test_file_result(get_branch_info, try_disk, raw_config_parser, data_collector): """ Configuration from file is loaded from the "uploader.json" key. """ config, pconn = collect_args(from_stdin=False) collect(config, pconn) name, args, kwargs = try_disk.mock_calls[0] collection_rules = try_disk.return_value.copy() collection_rules.update({"file": args[0]}) rm_conf = {"files": removed_files} branch_info = get_branch_info.return_value data_collector.return_value.run_collection.assert_called_once_with( collection_rules, rm_conf, branch_info) data_collector.return_value.done.assert_called_once_with( collection_rules, rm_conf)
def test_correct_collector_loaded(get_branch_info, get_conf_file, get_rm_conf, create_report, data_collector, core_collector): ''' Verify that core collection is loaded for core_collect=True, and that classic collection is loaded for core_collect=False ''' config, pconn = collect_args(core_collect=False) collect(config, pconn) data_collector.return_value.run_collection.assert_called() core_collector.return_value.run_collection.assert_not_called() # clear calls to test opposite condition data_collector.return_value.run_collection.reset_mock() core_collector.return_value.run_collection.reset_mock() config.core_collect = True collect(config, pconn) data_collector.return_value.run_collection.assert_not_called() core_collector.return_value.run_collection.assert_called()