Merge pull request #286 from YunoHost/actions/black

Format Python code with Black
This commit is contained in:
Alexandre Aubin 2021-08-27 18:47:01 +02:00 committed by GitHub
commit 5c982db4b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 21 deletions

View file

@ -26,32 +26,27 @@ __credits__ = """
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses
"""
__all__ = [
"init",
"api",
"cli",
"m18n",
"MoulinetteError",
"Moulinette"
]
__all__ = ["init", "api", "cli", "m18n", "MoulinetteError", "Moulinette"]
m18n = Moulinette18n()
class classproperty(object):
def __init__(self, f):
self.f = f
def __get__(self, obj, owner):
return self.f(owner)
class Moulinette():
class Moulinette:
_interface = None
def prompt(*args, **kwargs):
return Moulinette.interface.prompt(*args, **kwargs)
def display(*args, **kwargs):
return Moulinette.interface.display(*args, **kwargs)
@ -133,7 +128,9 @@ def cli(args, top_parser, output_as=None, timeout=None):
try:
load_only_category = args[0] if args and not args[0].startswith("-") else None
Cli(top_parser=top_parser, load_only_category=load_only_category).run(args, output_as=output_as, timeout=timeout)
Cli(top_parser=top_parser, load_only_category=load_only_category).run(
args, output_as=output_as, timeout=timeout
)
except MoulinetteError as e:
import logging

View file

@ -230,7 +230,7 @@ class _HTTPArgumentParser(object):
raise MoulinetteValidationError(message, raw_msg=True)
class Session():
class Session:
secret = random_ascii()
actionsmap_name = None # This is later set to the actionsmap name
@ -239,12 +239,19 @@ class Session():
assert isinstance(infos, dict)
response.set_cookie(f"session.{Session.actionsmap_name}", infos, secure=True, secret=Session.secret)
response.set_cookie(
f"session.{Session.actionsmap_name}",
infos,
secure=True,
secret=Session.secret,
)
def get_infos():
try:
infos = request.get_cookie(f"session.{Session.actionsmap_name}", secret=Session.secret, default={})
infos = request.get_cookie(
f"session.{Session.actionsmap_name}", secret=Session.secret, default={}
)
except Exception:
infos = {}
@ -388,7 +395,9 @@ class _ActionsMapPlugin(object):
authenticator = self.actionsmap.get_authenticator(profile)
try:
auth_info = authenticator.authenticate_credentials(credentials, store_session=True)
auth_info = authenticator.authenticate_credentials(
credentials, store_session=True
)
session_infos = Session.get_infos()
session_infos[profile] = auth_info
except MoulinetteError as e:
@ -523,6 +532,7 @@ class _ActionsMapPlugin(object):
def prompt(self, *args, **kwargs):
raise NotImplementedError("Prompt is not implemented for this interface")
# HTTP Responses -------------------------------------------------------

View file

@ -537,7 +537,9 @@ class Interface:
"""
if not os.isatty(1):
raise MoulinetteError("Not a tty, can't do interactive prompts", raw_msg=True)
raise MoulinetteError(
"Not a tty, can't do interactive prompts", raw_msg=True
)
if is_password:
prompt = lambda m: getpass.getpass(colorize(m18n.g("colon", m), color))
@ -553,9 +555,7 @@ class Interface:
return value
def display(self, message, style="info"):
"""Display a message
"""
"""Display a message"""
if style == "success":
print("{} {}".format(colorize(m18n.g("success"), "green"), message))
elif style == "warning":

View file

@ -17,7 +17,6 @@ from moulinette import m18n, Moulinette
@pytest.fixture
def iface():
class DummyInterface:
def prompt():
pass
@ -164,6 +163,7 @@ def test_required_paremeter_missing_value(iface, caplog):
def test_actions_map_unknown_authenticator(monkeypatch, tmp_path):
from moulinette.interfaces.api import ActionsMapParser
amap = ActionsMap(ActionsMapParser())
with pytest.raises(MoulinetteError) as exception:

View file

@ -87,7 +87,9 @@ class TestAuthAPI:
"CSRF protection"
in self.login(moulinette_webapi, csrf=True, status=403).text
)
assert not any(c.name == "session.moulitest" for c in moulinette_webapi.cookiejar)
assert not any(
c.name == "session.moulitest" for c in moulinette_webapi.cookiejar
)
def test_login_then_legit_request_without_cookies(self, moulinette_webapi):
self.login(moulinette_webapi)