mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
format
This commit is contained in:
parent
4331cfa9d2
commit
b31e2b026e
6 changed files with 62 additions and 35 deletions
|
@ -121,6 +121,7 @@ def cli(args, top_parser, output_as=None, timeout=None):
|
|||
)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
|
||||
logging.getLogger(logging.main_logger).error(e.strerror)
|
||||
return 1
|
||||
return 0
|
||||
|
|
|
@ -11,8 +11,7 @@ logger = logging.getLogger("moulinette.authenticator.dummy")
|
|||
|
||||
class Authenticator(BaseAuthenticator):
|
||||
|
||||
"""Dummy authenticator used for tests
|
||||
"""
|
||||
"""Dummy authenticator used for tests"""
|
||||
|
||||
vendor = "dummy"
|
||||
|
||||
|
|
|
@ -288,7 +288,10 @@ class _ActionsMapPlugin(object):
|
|||
|
||||
# Append messages route
|
||||
app.route(
|
||||
"/messages", name="messages", callback=self.messages, skip=["actionsmap"],
|
||||
"/messages",
|
||||
name="messages",
|
||||
callback=self.messages,
|
||||
skip=["actionsmap"],
|
||||
)
|
||||
|
||||
# Append routes from the actions map
|
||||
|
@ -810,7 +813,9 @@ class Interface(BaseInterface):
|
|||
|
||||
"""
|
||||
logger.debug(
|
||||
"starting the server instance in %s:%d", host, port,
|
||||
"starting the server instance in %s:%d",
|
||||
host,
|
||||
port,
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -22,9 +22,11 @@ def read_file(file_path):
|
|||
Keyword argument:
|
||||
file_path -- Path to the text file
|
||||
"""
|
||||
assert isinstance(file_path, basestring), (
|
||||
"Error: file_path '%s' should be a string but is of type '%s' instead"
|
||||
% (file_path, type(file_path))
|
||||
assert isinstance(
|
||||
file_path, basestring
|
||||
), "Error: file_path '%s' should be a string but is of type '%s' instead" % (
|
||||
file_path,
|
||||
type(file_path),
|
||||
)
|
||||
|
||||
# Check file exists
|
||||
|
@ -151,24 +153,30 @@ def write_to_file(file_path, data, file_mode="w"):
|
|||
file_mode -- Mode used when writing the file. Option meant to be used
|
||||
by append_to_file to avoid duplicating the code of this function.
|
||||
"""
|
||||
assert isinstance(data, basestring) or isinstance(data, list), (
|
||||
"Error: data '%s' should be either a string or a list but is of type '%s'"
|
||||
% (data, type(data))
|
||||
assert isinstance(data, basestring) or isinstance(
|
||||
data, list
|
||||
), "Error: data '%s' should be either a string or a list but is of type '%s'" % (
|
||||
data,
|
||||
type(data),
|
||||
)
|
||||
assert not os.path.isdir(file_path), (
|
||||
"Error: file_path '%s' point to a dir, it should be a file" % file_path
|
||||
)
|
||||
assert os.path.isdir(os.path.dirname(file_path)), (
|
||||
"Error: the path ('%s') base dir ('%s') is not a dir"
|
||||
% (file_path, os.path.dirname(file_path))
|
||||
assert os.path.isdir(
|
||||
os.path.dirname(file_path)
|
||||
), "Error: the path ('%s') base dir ('%s') is not a dir" % (
|
||||
file_path,
|
||||
os.path.dirname(file_path),
|
||||
)
|
||||
|
||||
# If data is a list, check elements are strings and build a single string
|
||||
if not isinstance(data, basestring):
|
||||
for element in data:
|
||||
assert isinstance(element, basestring), (
|
||||
"Error: element '%s' should be a string but is of type '%s' instead"
|
||||
% (element, type(element))
|
||||
assert isinstance(
|
||||
element, basestring
|
||||
), "Error: element '%s' should be a string but is of type '%s' instead" % (
|
||||
element,
|
||||
type(element),
|
||||
)
|
||||
data = "\n".join(data)
|
||||
|
||||
|
@ -203,20 +211,26 @@ def write_to_json(file_path, data):
|
|||
"""
|
||||
|
||||
# Assumptions
|
||||
assert isinstance(file_path, basestring), (
|
||||
"Error: file_path '%s' should be a string but is of type '%s' instead"
|
||||
% (file_path, type(file_path))
|
||||
assert isinstance(
|
||||
file_path, basestring
|
||||
), "Error: file_path '%s' should be a string but is of type '%s' instead" % (
|
||||
file_path,
|
||||
type(file_path),
|
||||
)
|
||||
assert isinstance(data, dict) or isinstance(data, list), (
|
||||
"Error: data '%s' should be a dict or a list but is of type '%s' instead"
|
||||
% (data, type(data))
|
||||
assert isinstance(data, dict) or isinstance(
|
||||
data, list
|
||||
), "Error: data '%s' should be a dict or a list but is of type '%s' instead" % (
|
||||
data,
|
||||
type(data),
|
||||
)
|
||||
assert not os.path.isdir(file_path), (
|
||||
"Error: file_path '%s' point to a dir, it should be a file" % file_path
|
||||
)
|
||||
assert os.path.isdir(os.path.dirname(file_path)), (
|
||||
"Error: the path ('%s') base dir ('%s') is not a dir"
|
||||
% (file_path, os.path.dirname(file_path))
|
||||
assert os.path.isdir(
|
||||
os.path.dirname(file_path)
|
||||
), "Error: the path ('%s') base dir ('%s') is not a dir" % (
|
||||
file_path,
|
||||
os.path.dirname(file_path),
|
||||
)
|
||||
|
||||
# Write dict to file
|
||||
|
|
|
@ -127,14 +127,12 @@ else:
|
|||
|
||||
|
||||
def identity(test_item):
|
||||
"""Identity decorator
|
||||
"""
|
||||
"""Identity decorator"""
|
||||
return test_item
|
||||
|
||||
|
||||
def skip_unless_ci(reason, feature=None):
|
||||
"""Skip test unless test case is executed on CI like Travis CI
|
||||
"""
|
||||
"""Skip test unless test case is executed on CI like Travis CI"""
|
||||
if not os.environ.get("CI", False):
|
||||
return unittest.skip(reason)
|
||||
elif feature in CI_DISABLED:
|
||||
|
@ -201,7 +199,8 @@ def combined_logger(
|
|||
fmt=" ".join((log_name, sys_log_format))
|
||||
)
|
||||
my_syslog_handler = logging.handlers.SysLogHandler(
|
||||
address="/dev/log", facility=SysLogHandler.LOG_DAEMON,
|
||||
address="/dev/log",
|
||||
facility=SysLogHandler.LOG_DAEMON,
|
||||
)
|
||||
my_syslog_handler.setFormatter(my_syslog_formatter)
|
||||
new_logger.addHandler(my_syslog_handler)
|
||||
|
@ -373,7 +372,8 @@ class SlapdObject(object):
|
|||
"""
|
||||
include_directives = "\n".join(
|
||||
'include "{schema_prefix}/{schema_file}"'.format(
|
||||
schema_prefix=self._schema_prefix, schema_file=schema_file,
|
||||
schema_prefix=self._schema_prefix,
|
||||
schema_file=schema_file,
|
||||
)
|
||||
for schema_file in self.openldap_schema_files
|
||||
)
|
||||
|
@ -563,7 +563,13 @@ class SlapdObject(object):
|
|||
if ldap_uri is None:
|
||||
ldap_uri = self.default_ldap_uri
|
||||
args = (
|
||||
[ldapcommand, "-H", ldap_uri,] + self._cli_auth_args() + (extra_args or [])
|
||||
[
|
||||
ldapcommand,
|
||||
"-H",
|
||||
ldap_uri,
|
||||
]
|
||||
+ self._cli_auth_args()
|
||||
+ (extra_args or [])
|
||||
)
|
||||
self._log.debug("Run command: %r", " ".join(args))
|
||||
proc = subprocess.Popen(
|
||||
|
|
|
@ -58,9 +58,11 @@ class TestLDAP:
|
|||
|
||||
def test_authenticate_sasl_non_interactive_bind(self, ldap_server):
|
||||
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
|
||||
self.ldap_conf["parameters"]["user_rdn"] = (
|
||||
"gidNumber=%s+uidNumber=%s,cn=peercred,cn=external,cn=auth"
|
||||
% (os.getgid(), os.getuid())
|
||||
self.ldap_conf["parameters"][
|
||||
"user_rdn"
|
||||
] = "gidNumber=%s+uidNumber=%s,cn=peercred,cn=external,cn=auth" % (
|
||||
os.getgid(),
|
||||
os.getuid(),
|
||||
)
|
||||
ldap_interface = m_ldap.Authenticator(**self.ldap_conf)
|
||||
|
||||
|
|
Loading…
Reference in a new issue