Skip to content

Commit 3ca97f0

Browse files
committed
Merge branch 'main' into dev
2 parents 6542730 + 834b5ac commit 3ca97f0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

linodecli/configuration/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def plugin_get_value(self, key):
211211
# TODO: this is more of an argparsing function than it is a config function
212212
# might be better to move this to argparsing during refactor and just have
213213
# configuration return defaults or keys or something
214-
def update(self, namespace, allowed_defaults):
214+
def update(self, namespace, allowed_defaults): #pylint: disable=too-many-branches
215215
"""
216216
This updates a Namespace (as returned by ArgumentParser) with config values
217217
if they aren't present in the Namespace already.
@@ -241,7 +241,9 @@ def update(self, namespace, allowed_defaults):
241241
if self.config.has_option(username, key):
242242
value = self.config.get(username, key)
243243
else:
244-
value = allowed_defaults[key]
244+
value = ns_dict[key]
245+
if not value:
246+
continue
245247
if key == "authorized_users":
246248
ns_dict[key] = [value]
247249
warn_dict[key] = [value]

tests/unit/configuration.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,17 @@ def test_update(self):
181181
parser.add_argument("--plugin-testplugin-testkey")
182182
ns = parser.parse_args(["--testkey", "testvalue"])
183183

184-
update_dict = {
185-
"newkey": "newvalue",
186-
"authorized_users": ["user1"],
187-
"plugin-testplugin-testkey": "plugin-value",
188-
}
184+
conf.username = 'tester'
185+
conf.config.add_section('tester')
186+
conf.config.set('tester', 'token', 'testtoken')
187+
conf.config.set('tester', 'newkey', 'newvalue')
188+
conf.config.set('tester', 'authorized_users', 'tester')
189+
conf.config.set('tester', 'plugin-testplugin-testkey', 'plugin-value')
190+
allowed_defaults = {'newkey', 'authorized_users', 'plugin-testplugin-testkey'}
189191

190192
f = io.StringIO()
191193
with contextlib.redirect_stdout(f):
192-
result = vars(conf.update(ns, update_dict))
194+
result = vars(conf.update(ns, allowed_defaults))
193195

194196
self.assertTrue("--no-defaults" in f.getvalue())
195197
self.assertEqual(result.get("newkey"), "newvalue")

0 commit comments

Comments
 (0)