def test_no_connection_error(): """ Error is raised when connection couldn't be established. """ config, pconn = update_rules_args() with raises(ValueError): update_rules(config, None)
def test_try_disk_no_version_error(get_collection_rules, try_disk): """ An error is raised if collection rules retrieved from file don’t contain a version. """ config, pconn = update_rules_args() with raises(ValueError): update_rules(config, pconn)
def test_get_collection_rules_no_version_error(get_collection_rules): """ An error is raised if collection rules retrieved from online source don’t contain a version. """ config, pconn = update_rules_args() with raises(ValueError): update_rules(config, pconn)
def test_configuration(insights_upload_conf): """ Configuration is created with given options and retrieved connection. """ config, pconn = update_rules_args() update_rules(config, pconn) insights_upload_conf.assert_called_once_with(config, conn=pconn)
def test_try_disk_calls(get_collection_rules, try_disk): """ Collection rules are not retrieved from online source, loading from file. """ config, pconn = update_rules_args() update_rules(config, pconn) get_collection_rules.assert_called_once_with() try_disk.assert_called()
def test_no_connection_no_configuration(insights_upload_conf): """ Configuration is not loaded when connection couldn't be established. """ config, pconn = update_rules_args() try: update_rules(config, None) except ValueError: pass insights_upload_conf.assert_not_called()
def test_return_get_conf_update(insights_upload_conf): """ Updated configuration is loaded and returned. """ config, pconn = update_rules_args() result = update_rules(config, pconn) get_conf_update = insights_upload_conf.return_value.get_conf_update get_conf_update.assert_called_once_with() assert result == get_conf_update.return_value
def test_get_collection_rules_result(get_collection_rules): """ Collection rules file name is added to the retrieved result. """ config, pconn = update_rules_args() raw_result = update_rules(config, pconn) coerced_result = coerce_result(raw_result) expected = get_collection_rules.return_value.copy() expected.update({"file": collection_rules_file}) assert coerced_result[0] == expected
def test_try_disk_result(get_collection_rules, try_disk): """ Local file name is added to the stored result. """ config, pconn = update_rules_args() raw_result = update_rules(config, pconn) coerced_result = coerce_result(raw_result) name, args, kwargs = try_disk.mock_calls[0] expected = try_disk.return_value expected.update({"file": args[0]}) assert coerced_result[0] == expected