mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 22:56:15 +01:00
commandline: Fix regression in handling default apiurl from oscrc
The default apiurl (https://api.opensuse.org) was always used as default regardless the settings in oscrc.
This commit is contained in:
parent
a25ea8d175
commit
bc468b7710
@ -388,11 +388,9 @@ class OscMainCommand(MainCommand):
|
||||
# try reading the apiurl from the working copy
|
||||
args.apiurl = osc_store.Store(Path.cwd()).apiurl
|
||||
except oscerr.NoWorkingCopy:
|
||||
# use the default apiurl from conf (if it was configured already)
|
||||
args.apiurl = conf.config["apiurl"]
|
||||
|
||||
if not args.apiurl:
|
||||
self.parser.error("Could not determine apiurl, use -A/--apiurl to specify one")
|
||||
# we can't use conf.config["apiurl"] because it contains the default "https://api.opensuse.org"
|
||||
# let's leave setting the right value to conf.get_config()
|
||||
pass
|
||||
|
||||
conf.get_config(
|
||||
override_apiurl=args.apiurl,
|
||||
@ -415,6 +413,9 @@ class OscMainCommand(MainCommand):
|
||||
if conf.config["show_download_progress"]:
|
||||
self.download_progress = create_text_meter()
|
||||
|
||||
if not args.apiurl:
|
||||
self.parser.error("Could not determine apiurl, use -A/--apiurl to specify one")
|
||||
|
||||
# needed for LegacyOsc class
|
||||
self.args = args
|
||||
|
||||
|
@ -6,6 +6,7 @@ import unittest
|
||||
|
||||
from osc.commandline import Command
|
||||
from osc.commandline import MainCommand
|
||||
from osc.commandline import OscMainCommand
|
||||
from osc.commandline import pop_project_package_from_args
|
||||
from osc.commandline import pop_project_package_repository_arch_from_args
|
||||
from osc.commandline import pop_project_package_targetproject_targetpackage_from_args
|
||||
@ -28,7 +29,35 @@ class TestCommand(Command):
|
||||
name = "test-cmd"
|
||||
|
||||
|
||||
OSCRC_LOCALHOST = """
|
||||
[general]
|
||||
apiurl = https://localhost
|
||||
|
||||
[https://localhost]
|
||||
user=Admin
|
||||
pass=opensuse
|
||||
""".lstrip()
|
||||
|
||||
|
||||
class TestCommandClasses(unittest.TestCase):
|
||||
def setUp(self):
|
||||
os.environ.pop("OSC_CONFIG", None)
|
||||
self.tmpdir = tempfile.mkdtemp(prefix="osc_test")
|
||||
os.chdir(self.tmpdir)
|
||||
self.oscrc = None
|
||||
|
||||
def tearDown(self):
|
||||
os.environ.pop("OSC_CONFIG", None)
|
||||
try:
|
||||
shutil.rmtree(self.tmpdir)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def write_oscrc_localhost(self):
|
||||
self.oscrc = os.path.join(self.tmpdir, "oscrc")
|
||||
with open(self.oscrc, "w") as f:
|
||||
f.write(OSCRC_LOCALHOST)
|
||||
|
||||
def test_load_commands(self):
|
||||
main = TestMainCommand()
|
||||
main.load_commands()
|
||||
@ -97,6 +126,19 @@ class TestCommandClasses(unittest.TestCase):
|
||||
|
||||
self.assertRaises(SystemExit, main.parse_args, ["test-cmd", "--unknown-option"])
|
||||
|
||||
def test_default_apiurl(self):
|
||||
class TestMainCommand(OscMainCommand):
|
||||
name = "osc-test"
|
||||
|
||||
main = TestMainCommand()
|
||||
main.load_command(TestCommand, "test.osc.commands")
|
||||
|
||||
self.write_oscrc_localhost()
|
||||
os.environ["OSC_CONFIG"] = self.oscrc
|
||||
args = main.parse_args(["test-cmd"])
|
||||
main.post_parse_args(args)
|
||||
self.assertEqual(args.apiurl, "https://localhost")
|
||||
|
||||
|
||||
class TestPopProjectPackageFromArgs(unittest.TestCase):
|
||||
def _write_store(self, project=None, package=None):
|
||||
|
Loading…
Reference in New Issue
Block a user