From 69a68b06b31fc445c2ce277a7ae90fcff1175578 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Wed, 15 Nov 2023 09:14:52 +0100 Subject: [PATCH] Fix conf.write_initial_config() to use read_file() instead of deprecated readfp() --- osc/conf.py | 2 +- tests/test_conf.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/osc/conf.py b/osc/conf.py index bf414f9d..49d30d28 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -1716,7 +1716,7 @@ def write_initial_config(conffile, entries, custom_template='', creds_mgr_descri config.update(entries) sio = StringIO(conf_template.strip() % config) cp = OscConfigParser.OscConfigParser() - cp.readfp(sio) + cp.read_file(sio) cp.set(config['apiurl'], 'user', config['user']) if creds_mgr_descriptor: creds_mgr = creds_mgr_descriptor.create(cp) diff --git a/tests/test_conf.py b/tests/test_conf.py index c4fcd3c8..5d6a41d2 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -469,5 +469,22 @@ class TestFromParent(unittest.TestCase): self.assertEqual(self.host_options.email, "another-user@example.com") +class TestConf(unittest.TestCase): + def setUp(self): + self.tmpdir = tempfile.mkdtemp(prefix="osc_test_") + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + def test_write_initial_config(self): + conffile = os.path.join(self.tmpdir, "oscrc") + entries = { + "user": "Admin", + "pass": "opensuse", + "apiurl": "https://example.com", + } + osc.conf.write_initial_config(conffile, entries) + + if __name__ == "__main__": unittest.main()