Merge pull request #284 from YunoHost/actions/black

Format Python code with Black
This commit is contained in:
Alexandre Aubin 2021-08-25 21:04:49 +02:00 committed by GitHub
commit e1f9fe1fcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 158 additions and 98 deletions

View file

@ -18,18 +18,21 @@
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
import sys
from mock import Mock as MagicMock
class Mock(MagicMock):
@classmethod
def __getattr__(cls, name):
return MagicMock()
return MagicMock()
MOCK_MODULES = ['ldap', 'ldap.modlist', 'ldap.sasl']
MOCK_MODULES = ["ldap", "ldap.modlist", "ldap.sasl"]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
@ -42,36 +45,38 @@ sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# General information about the project.
project = u'Moulinette'
copyright = u'2017, YunoHost Collective'
author = u'YunoHost Collective'
project = u"Moulinette"
copyright = u"2017, YunoHost Collective"
author = u"YunoHost Collective"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'2.6.1'
version = u"2.6.1"
# The full version, including alpha/beta/rc tags.
release = u'2.6.1'
release = u"2.6.1"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -83,10 +88,10 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
@ -97,7 +102,7 @@ todo_include_todos = True
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'classic'
html_theme = "classic"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -108,7 +113,7 @@ html_theme = 'classic'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
@ -116,11 +121,11 @@ html_static_path = ['_static']
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
"**": [
# 'about.html',
# 'navigation.html',
# 'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
"searchbox.html",
# 'donate.html',
]
}
@ -129,7 +134,7 @@ html_sidebars = {
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'Moulinettedoc'
htmlhelp_basename = "Moulinettedoc"
# -- Options for LaTeX output ---------------------------------------------
@ -138,15 +143,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
@ -156,8 +158,13 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Moulinette.tex', u'Moulinette Documentation',
u'YunoHost Collective', 'manual'),
(
master_doc,
"Moulinette.tex",
u"Moulinette Documentation",
u"YunoHost Collective",
"manual",
),
]
@ -165,10 +172,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'moulinette', u'Moulinette Documentation',
[author], 1)
]
man_pages = [(master_doc, "moulinette", u"Moulinette Documentation", [author], 1)]
# -- Options for Texinfo output -------------------------------------------
@ -177,13 +181,17 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Moulinette', u'Moulinette Documentation',
author, 'Moulinette', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Moulinette",
u"Moulinette Documentation",
author,
"Moulinette",
"One line description of project.",
"Miscellaneous",
),
]
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}

View file

@ -344,7 +344,7 @@ class _ActionsMapPlugin(object):
# Append other request params
req_params = list(request.params.decode().dict.items())
# TODO test special chars in filename
req_params+=list(request.files.dict.items())
req_params += list(request.files.dict.items())
for k, v in req_params:
v = _format(v)
if k not in params.keys():

View file

@ -6,54 +6,55 @@ from setuptools import setup, find_packages
from moulinette.globals import init_moulinette_env
LOCALES_DIR = init_moulinette_env()['LOCALES_DIR']
LOCALES_DIR = init_moulinette_env()["LOCALES_DIR"]
# Extend installation
locale_files = []
if "install" in sys.argv:
# Evaluate locale files
for f in os.listdir('locales'):
if f.endswith('.json'):
locale_files.append('locales/%s' % f)
for f in os.listdir("locales"):
if f.endswith(".json"):
locale_files.append("locales/%s" % f)
install_deps = [
'argcomplete',
'psutil',
'pytz',
'pyyaml',
'toml',
'python-ldap',
'gevent-websocket',
'bottle',
"argcomplete",
"psutil",
"pytz",
"pyyaml",
"toml",
"python-ldap",
"gevent-websocket",
"bottle",
]
test_deps = [
'pytest',
'pytest-cov',
'pytest-env',
'pytest-mock',
'requests',
'requests-mock',
'webtest'
"pytest",
"pytest-cov",
"pytest-env",
"pytest-mock",
"requests",
"requests-mock",
"webtest",
]
extras = {
'install': install_deps,
'tests': test_deps,
"install": install_deps,
"tests": test_deps,
}
setup(name='Moulinette',
version='2.0.0',
description='Prototype interfaces quickly and easily',
author='Yunohost Team',
author_email='yunohost@yunohost.org',
url='http://yunohost.org',
license='AGPL',
packages=find_packages(exclude=['test']),
data_files=[(LOCALES_DIR, locale_files)],
python_requires='>=3.7.*, <3.8',
install_requires=install_deps,
tests_require=test_deps,
extras_require=extras,
)
setup(
name="Moulinette",
version="2.0.0",
description="Prototype interfaces quickly and easily",
author="Yunohost Team",
author_email="yunohost@yunohost.org",
url="http://yunohost.org",
license="AGPL",
packages=find_packages(exclude=["test"]),
data_files=[(LOCALES_DIR, locale_files)],
python_requires=">=3.7.*, <3.8",
install_requires=install_deps,
tests_require=test_deps,
extras_require=extras,
)

View file

@ -158,7 +158,9 @@ class TestAuthAPI:
== "Authentication required"
)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_login_ldap(self, moulinette_webapi, ldap_server, mocker):
mocker.patch(
"moulinette.authenticators.ldap.Authenticator._get_uri",

View file

@ -38,6 +38,7 @@ def find_expected_string_keys():
continue
yield m
###############################################################################
# Load en locale json keys #
###############################################################################

View file

@ -15,7 +15,9 @@ class TestLDAP:
"extra": {},
}
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_simple_bind_with_admin(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org"
@ -24,7 +26,9 @@ class TestLDAP:
assert ldap_interface.con
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_simple_bind_with_wrong_user(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = "cn=yoloswag,dc=yunohost,dc=org"
@ -37,7 +41,9 @@ class TestLDAP:
assert expected_msg in str(exception)
assert ldap_interface.con is None
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_simple_bind_with_rdn_wrong_password(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org"
@ -51,7 +57,9 @@ class TestLDAP:
assert ldap_interface.con is None
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_simple_bind_anonymous(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = ""
@ -60,7 +68,9 @@ class TestLDAP:
assert ldap_interface.con
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_sasl_non_interactive_bind(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"][
@ -73,7 +83,9 @@ class TestLDAP:
assert ldap_interface.con
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_authenticate_server_down(self, ldap_server, mocker):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org"
@ -99,7 +111,9 @@ class TestLDAP:
ldap_interface.authenticate(password=password)
return ldap_interface
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_admin_read(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -120,7 +134,9 @@ class TestLDAP:
assert list(admin_info.keys()) == ["userPassword"]
assert admin_info["userPassword"][0].startswith("{CRYPT}$6$")
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_sasl_read(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -142,7 +158,9 @@ class TestLDAP:
assert list(admin_info.keys()) == ["userPassword"]
assert admin_info["userPassword"][0].startswith("{CRYPT}$6$")
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_anonymous_read(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface("")
@ -181,7 +199,9 @@ class TestLDAP:
"uid=%s,ou=users,dc=yunohost,dc=org" % new_user, attrs=None
)[0]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_admin_add(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -199,7 +219,9 @@ class TestLDAP:
assert "inetOrgPerson" in new_user_info["objectClass"]
assert "posixAccount" in new_user_info["objectClass"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_sasl_add(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -218,7 +240,9 @@ class TestLDAP:
assert "inetOrgPerson" in new_user_info["objectClass"]
assert "posixAccount" in new_user_info["objectClass"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_anonymous_add(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface("")
@ -253,7 +277,9 @@ class TestLDAP:
assert expected_error in str(exception)
assert expected_message in str(exception)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_admin_remove(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -262,7 +288,9 @@ class TestLDAP:
self.remove_new_user(ldap_interface)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_sasl_remove(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -272,7 +300,9 @@ class TestLDAP:
self.remove_new_user(ldap_interface)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_anonymous_remove(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface("")
@ -308,7 +338,9 @@ class TestLDAP:
"uid=%s,ou=users,dc=yunohost,dc=org" % uid, attrs=None
)[0]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_admin_update(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -320,7 +352,9 @@ class TestLDAP:
assert new_user_info["uidNumber"] == ["555"]
assert new_user_info["gidNumber"] == ["555"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_admin_update_new_rdn(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -332,7 +366,9 @@ class TestLDAP:
assert new_user_info["uidNumber"] == ["555"]
assert new_user_info["gidNumber"] == ["555"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_sasl_update(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -345,7 +381,9 @@ class TestLDAP:
assert new_user_info["uidNumber"] == ["555"]
assert new_user_info["gidNumber"] == ["555"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_sasl_update_new_rdn(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -357,7 +395,9 @@ class TestLDAP:
assert new_user_info["uidNumber"] == ["555"]
assert new_user_info["gidNumber"] == ["555"]
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_anonymous_update(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface("")
@ -370,7 +410,9 @@ class TestLDAP:
assert expected_error in str(exception)
assert expected_message in str(exception)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_anonymous_update_new_rdn(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface("")
@ -383,7 +425,9 @@ class TestLDAP:
assert expected_error in str(exception)
assert expected_message in str(exception)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_empty_update(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -399,7 +443,9 @@ class TestLDAP:
assert ldap_interface.update("uid=%s,ou=users" % uid, new_user_info)
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_get_conflict(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(
@ -418,7 +464,9 @@ class TestLDAP:
conflict = ldap_interface.get_conflict({"uid": "not_a_user"})
assert not conflict
@pytest.mark.skip(reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway...")
@pytest.mark.skip(
reason="Not passing because setup issue idk, to be removed or moved to Yunohost soon anyway..."
)
def test_validate_uniqueness(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
ldap_interface = self.create_ldap_interface(