make flake8 happy

This commit is contained in:
Kay0u 2020-01-02 23:18:28 +08:00
parent 1cfec24ac2
commit 247411cb9f
No known key found for this signature in database
GPG key ID: 7FF262C033518333
7 changed files with 25 additions and 11 deletions

View file

@ -117,7 +117,7 @@ class Authenticator(BaseAuthenticator):
# we aren't using sha-512 but something else that is weaker, proceed to upgrade # we aren't using sha-512 but something else that is weaker, proceed to upgrade
if not hashed_password["userPassword"][0].startswith("{CRYPT}$6$"): if not hashed_password["userPassword"][0].startswith("{CRYPT}$6$"):
self.update("cn=admin", {"userPassword": _hash_user_password(password),}) self.update("cn=admin", {"userPassword": _hash_user_password(password)})
# Additional LDAP methods # Additional LDAP methods
# TODO: Review these methods # TODO: Review these methods

View file

@ -16,6 +16,16 @@ from logging import (
CRITICAL, CRITICAL,
) )
__all__ = [
"NOTSET", # noqa
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL",
"SUCCESS",
]
# Global configuration and functions ----------------------------------- # Global configuration and functions -----------------------------------
@ -35,7 +45,7 @@ DEFAULT_LOGGING = {
"stream": "ext://sys.stdout", "stream": "ext://sys.stdout",
}, },
}, },
"loggers": {"moulinette": {"level": "DEBUG", "handlers": ["console"],},}, "loggers": {"moulinette": {"level": "DEBUG", "handlers": ["console"]}},
} }

View file

@ -55,7 +55,7 @@ def patch_logging(moulinette):
"format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" # noqa "format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" # noqa
}, },
}, },
"filters": {"action": {"()": "moulinette.utils.log.ActionFilter",},}, "filters": {"action": {"()": "moulinette.utils.log.ActionFilter"}},
"handlers": { "handlers": {
"api": { "api": {
"level": level, "level": level,
@ -68,14 +68,14 @@ def patch_logging(moulinette):
}, },
}, },
"loggers": { "loggers": {
"moulinette": {"level": level, "handlers": [], "propagate": True,}, "moulinette": {"level": level, "handlers": [], "propagate": True},
"moulinette.interface": { "moulinette.interface": {
"level": level, "level": level,
"handlers": handlers, "handlers": handlers,
"propagate": False, "propagate": False,
}, },
}, },
"root": {"level": level, "handlers": root_handlers,}, "root": {"level": level, "handlers": root_handlers},
} }

View file

@ -284,4 +284,4 @@ def test_actions_map_cli():
assert 'testauth' in amap.parser._subparsers.choices assert 'testauth' in amap.parser._subparsers.choices
assert 'none' in amap.parser._subparsers.choices['testauth']._actions[1].choices assert 'none' in amap.parser._subparsers.choices['testauth']._actions[1].choices
assert 'subcat' in amap.parser._subparsers.choices['testauth']._actions[1].choices assert 'subcat' in amap.parser._subparsers.choices['testauth']._actions[1].choices
assert 'default' in amap.parser._subparsers.choices['testauth']._actions[1].choices['subcat']._actions[1].choices assert 'default' in amap.parser._subparsers.choices['testauth']._actions[1].choices['subcat']._actions[1].choices

View file

@ -1,6 +1,5 @@
import os import os
import pytest import pytest
import json
from moulinette import MoulinetteError from moulinette import MoulinetteError
from moulinette import m18n from moulinette import m18n
@ -79,7 +78,6 @@ class TestAuthAPI:
assert "session.id" not in moulinette_webapi.cookies assert "session.id" not in moulinette_webapi.cookies
assert "session.tokens" not in moulinette_webapi.cookies assert "session.tokens" not in moulinette_webapi.cookies
def test_login_csrf_attempt(self, moulinette_webapi): def test_login_csrf_attempt(self, moulinette_webapi):
# C.f. # C.f.
# https://security.stackexchange.com/a/58308 # https://security.stackexchange.com/a/58308

View file

@ -4,8 +4,6 @@ import pytest
import pwd import pwd
import grp import grp
from stat import *
from moulinette import m18n from moulinette import m18n
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils.filesystem import ( from moulinette.utils.filesystem import (
@ -158,6 +156,7 @@ def test_read_ldif_cannot_exception(test_ldif, mocker):
expected_msg = translation.format(file=str(test_ldif), error=error) expected_msg = translation.format(file=str(test_ldif), error=error)
assert expected_msg in str(exception) assert expected_msg in str(exception)
def test_write_to_existing_file(test_file): def test_write_to_existing_file(test_file):
write_to_file(str(test_file), "yolo\nswag") write_to_file(str(test_file), "yolo\nswag")
assert read_file(str(test_file)) == "yolo\nswag" assert read_file(str(test_file)) == "yolo\nswag"

View file

@ -25,6 +25,7 @@ def test_run_shell_bad_cmd_with_callback():
assert isinstance(b, str) assert isinstance(b, str)
assert isinstance(c, str) assert isinstance(c, str)
return True return True
assert run_commands(["yolo swag", "yolo swag", "yolo swag"], callback=callback) == 3 assert run_commands(["yolo swag", "yolo swag", "yolo swag"], callback=callback) == 3
def callback(a, b, c): def callback(a, b, c):
@ -32,6 +33,7 @@ def test_run_shell_bad_cmd_with_callback():
assert isinstance(b, str) assert isinstance(b, str)
assert isinstance(c, str) assert isinstance(c, str)
return False return False
assert run_commands(["yolo swag", "yolo swag"], callback=callback) == 1 assert run_commands(["yolo swag", "yolo swag"], callback=callback) == 1
def callback(a, b, c): def callback(a, b, c):
@ -39,6 +41,7 @@ def test_run_shell_bad_cmd_with_callback():
assert isinstance(b, str) assert isinstance(b, str)
assert isinstance(c, tuple) assert isinstance(c, tuple)
return True return True
run_commands(["yolo swag"], separate_stderr=True, callback=callback) run_commands(["yolo swag"], separate_stderr=True, callback=callback)
@ -62,9 +65,9 @@ def test_run_shell_kwargs():
def test_call_async_output(test_file): def test_call_async_output(test_file):
def callback(a): def callback(a):
assert a == "foo\n" or a == "bar\n" assert a == "foo\n" or a == "bar\n"
call_async_output(["cat", str(test_file)], callback) call_async_output(["cat", str(test_file)], callback)
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -72,8 +75,10 @@ def test_call_async_output(test_file):
def callbackA(a): def callbackA(a):
assert a == "foo\n" or a == "bar\n" assert a == "foo\n" or a == "bar\n"
def callbackB(a): def callbackB(a):
pass pass
callback = (callbackA, callbackB) callback = (callbackA, callbackB)
call_async_output(["cat", str(test_file)], callback) call_async_output(["cat", str(test_file)], callback)
@ -91,8 +96,10 @@ def test_call_async_output_kwargs(test_file, mocker):
def callbackA(a): def callbackA(a):
assert a == "foo\n" or a == "bar\n" assert a == "foo\n" or a == "bar\n"
def callbackB(a): def callbackB(a):
pass pass
def callbackC(a): def callbackC(a):
pass pass