diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 9433b116..39b5f9a2 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -6,6 +6,20 @@ import getpass import locale import logging from argparse import SUPPRESS +from collections import OrderedDict +from datetime import date, datetime + +import argcomplete + +from moulinette import msignals, m18n +from moulinette.actionsmap import ActionsMap +from moulinette.core import MoulinetteError +from moulinette.interfaces import ( + BaseActionsMapParser, + BaseInterface, + ExtendedArgumentParser, +) +from moulinette.utils import log # Monkeypatch _get_action_name function because there is an annoying bug # Explained here: https://bugs.python.org/issue29298 @@ -39,22 +53,6 @@ def monkey_get_action_name(argument): argparse._get_action_name = monkey_get_action_name -from collections import OrderedDict -from datetime import date, datetime - -import argcomplete - -from moulinette import msignals, m18n -from moulinette.actionsmap import ActionsMap -from moulinette.core import MoulinetteError -from moulinette.interfaces import ( - BaseActionsMapParser, - BaseInterface, - ExtendedArgumentParser, -) -from moulinette.utils import log - - logger = log.getLogger("moulinette.cli") diff --git a/test/test_auth.py b/test/test_auth.py index 624ebccd..b3237089 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -207,6 +207,10 @@ class TestAuthAPI: mocker.patch("moulinette.Moulinette18n.g", return_value=error) moulinette_webapi.get("/test-auth/with_type_int/yoloswag", status=400) + def test_request_arg_without_action(self, moulinette_webapi, caplog, mocker): + self.login(moulinette_webapi) + moulinette_webapi.get("/test-auth", status=404) + class TestAuthCLI: def test_login(self, moulinette_cli, capsys, mocker): @@ -336,3 +340,11 @@ class TestAuthCLI: message = capsys.readouterr() assert "invalid int value" in message.err + + def test_request_arg_without_action(self, moulinette_cli, capsys, mocker): + with pytest.raises(SystemExit): + moulinette_cli.run(["testauth"], output_as="plain") + + message = capsys.readouterr() + + assert "error: the following arguments are required:" in message.err