Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apiurl_aliases handling in OscOptions.__getitem__ #1440

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3870,7 +3870,7 @@

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)

Check warning on line 3873 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L3873

Added line #L3873 was not covered by tests
else:
tgt_apiurl = src_apiurl

Expand Down
8 changes: 5 additions & 3 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@
def __getitem__(self, name):
field_name = self._get_field_name(name)

if field_name is None:
if field_name is None and not hasattr(self, name):
return self.extra_fields[name]

field_name = field_name or name
try:
return getattr(self, field_name)
except AttributeError:
Expand All @@ -156,10 +157,11 @@
def __setitem__(self, name, value):
field_name = self._get_field_name(name)

if field_name is None:
if field_name is None and not hasattr(self, name):
self.extra_fields[name] = value
return

field_name = field_name or name
setattr(self, field_name, value)

# compat function with the config dict
Expand Down Expand Up @@ -1617,7 +1619,7 @@
cp = get_configParser(config['conffile'])

if section != 'general':
section = config['apiurl_aliases'].get(section, section)
section = config.apiurl_aliases.get(section, section)

Check warning on line 1622 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L1622

Added line #L1622 was not covered by tests
scheme, host, path = \
parse_apisrv_url(config.get('scheme', 'https'), section)
section = urljoin(scheme, host, path)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
import os
import shutil
import tempfile
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -407,6 +409,13 @@ def test_extra_fields(self):
self.assertEqual(self.config["plugin-option"], "plugin-general-option")
self.assertEqual(self.config.extra_fields, {"plugin-option": "plugin-general-option"})

# write to an existing attribute instead of extra_fields
self.config.attrib = 123
self.assertEqual(self.config["attrib"], 123)
self.config["attrib"] = 456
self.assertEqual(self.config["attrib"], 456)
self.assertEqual(self.config.extra_fields, {"plugin-option": "plugin-general-option"})

self.config["new-option"] = "value"
self.assertEqual(self.config["new-option"], "value")
self.assertEqual(self.config.extra_fields, {"plugin-option": "plugin-general-option", "new-option": "value"})
Expand All @@ -419,6 +428,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):
Expand Down
Loading