Self hosted FLOSS fitness/workout, nutrition and weight tracker
Don't read the user's invoke config in the CLI
Roland Geiderf0f45eb9d8f1
diff --git a/wger/core/tests/test_cli.py b/wger/core/tests/test_cli.pynew file mode 100644index 000000000..dbf59add0--- /dev/null+++ b/wger/core/tests/test_cli.py@@ -0,0 +1,45 @@+# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++# Standard Library+import os+import tempfile+from unittest import mock++# Django+from django.test import SimpleTestCase++# Third Party+from invoke import Config++# wger+from wger.tasks import WgerConfig++++class WgerConfigTestCase(SimpleTestCase):+ """+ Test the invoke configuration used by the CLI+ """++ def test_user_config_file_is_ignored(self):+ with tempfile.TemporaryDirectory() as home:+ with open(os.path.join(home, '.invoke.yaml'), 'w') as config_file:+ config_file.write('run:\n echo: true\n')++ with mock.patch.dict(os.environ, {'HOME': home}):+ # Sanity check, invoke's own config does read the file+ self.assertTrue(Config().run.echo)++ self.assertFalse(WgerConfig().run.echo)diff --git a/wger/tasks.py b/wger/tasks.pyindex f8b3afd7e..db08a9c78 100644--- a/wger/tasks.py+++ b/wger/tasks.py@@ -30,6 +30,7 @@ from django.core.management import (import requestsfrom invoke import (Collection,+ Config,Program,task,)@@ -234,8 +235,19 @@ def database_exists():except ImproperlyConfigured as e:print(style.ERROR('Your settings file seems broken: '), e)sys.exit(0)- else:- return True+++class WgerConfig(Config):+ """+ Invoke configuration that ignores the per-user config file++ The CLI has no user level configuration, and invoke reading ~/.invoke.yaml is a+ trap when HOME points to a folder the current process can't read (e.g. process+ supervisors that don't reset HOME when dropping privileges).+ """++ def load_user(self, merge: bool = True) -> None:+ self._set(_user_found=False)def make_program():@@ -246,5 +258,5 @@ def make_program():load_fixtures,load_online_fixtures,)- return Program(namespace=ns)+ return Program(namespace=ns, config_class=WgerConfig)# program.run()