diff --git a/osc/commandline.py b/osc/commandline.py index 5fb6f08d22..e7dd60c0b9 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -3870,7 +3870,7 @@ def do_copypac(self, subcmd, opts, *args): src_apiurl = conf.config['apiurl'] if opts.to_apiurl: - tgt_apiurl = conf.config['apiurl_aliases'].get(opts.to_apiurl, opts.to_apiurl) + tgt_apiurl = conf.config.apiurl_aliases.get(opts.to_apiurl, opts.to_apiurl) else: tgt_apiurl = src_apiurl diff --git a/osc/conf.py b/osc/conf.py index 87043c5c2c..dd2399382d 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -144,7 +144,9 @@ def _get_field_name(self, name): def __getitem__(self, name): field_name = self._get_field_name(name) - if field_name is None: + if name == "apiurl_aliases" and hasattr(self, "apiurl_aliases"): + return self.apiurl_aliases + elif field_name is None: return self.extra_fields[name] try: @@ -1617,7 +1619,7 @@ def config_set_option(section, opt, val=None, delete=False, update=True, creds_m cp = get_configParser(config['conffile']) if section != 'general': - section = config['apiurl_aliases'].get(section, section) + section = config.apiurl_aliases.get(section, section) scheme, host, path = \ parse_apisrv_url(config.get('scheme', 'https'), section) section = urljoin(scheme, host, path) diff --git a/tests/test_conf.py b/tests/test_conf.py index f7826eb867..1919e44661 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -1,3 +1,4 @@ +import importlib import os import shutil import tempfile @@ -104,6 +105,7 @@ class TestExampleConfig(unittest.TestCase): def setUp(self): + importlib.reload(osc.conf) self.tmpdir = tempfile.mkdtemp(prefix="osc_test_") self.oscrc = os.path.join(self.tmpdir, "oscrc") with open(self.oscrc, "w", encoding="utf-8") as f: @@ -419,6 +421,11 @@ def test_extra_fields(self): self.assertEqual(host_options["new-option"], "value") self.assertEqual(host_options.extra_fields, {"plugin-option": "plugin-host-option", "new-option": "value"}) + def test_apiurl_aliases(self): + expected = {"https://api.opensuse.org": "https://api.opensuse.org", "osc": "https://api.opensuse.org"} + self.assertEqual(self.config.apiurl_aliases, expected) + self.assertEqual(self.config["apiurl_aliases"], expected) + class TestFromParent(unittest.TestCase): def setUp(self):