diff --git a/data/actionsmap/test.yml b/data/actionsmap/test.yml deleted file mode 100644 index 36d1a270..00000000 --- a/data/actionsmap/test.yml +++ /dev/null @@ -1,72 +0,0 @@ - -############################# -# Global parameters # -############################# -_global: - configuration: - authenticate: - - api - authenticator: - default: - vendor: ldap - help: Admin Password - parameters: - uri: ldap://localhost:389 - base_dn: dc=yunohost,dc=org - user_rdn: cn=admin,dc=yunohost,dc=org - ldap-anonymous: - vendor: ldap - parameters: - uri: ldap://localhost:389 - base_dn: dc=yunohost,dc=org - test-profile: - vendor: ldap - help: Admin Password (profile) - parameters: - uri: ldap://localhost:389 - base_dn: dc=yunohost,dc=org - user_rdn: cn=admin,dc=yunohost,dc=org - as-root: - vendor: ldap - parameters: - # We can get this uri by (urllib.quote_plus('/var/run/slapd/ldapi') - uri: ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi - base_dn: dc=yunohost,dc=org - user_rdn: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth - argument_auth: true - lock: false - -############################# -# Test Actions # -############################# -test: - actions: - non-auth: - api: GET /test/non-auth - configuration: - authenticate: false - auth: - api: GET /test/auth - configuration: - authenticate: all - auth-profile: - api: GET /test/auth-profile - configuration: - authenticate: all - authenticator: test-profile - auth-cli: - api: GET /test/auth-cli - configuration: - authenticate: - - cli - root-auth: - api: GET /test/root-auth - configuration: - authenticate: all - authenticator: as-root - anonymous: - api: GET /test/anon - configuration: - authenticate: all - authenticator: ldap-anonymous - argument_auth: false diff --git a/data/moulinette_cli b/data/moulinette_cli deleted file mode 100644 index 15ac21f2..00000000 --- a/data/moulinette_cli +++ /dev/null @@ -1,33 +0,0 @@ -# yunohost(1) completion - -_yunohost_cli() -{ -local argc cur prev opts -COMPREPLY=() - -argc=${COMP_CWORD} -cur="${COMP_WORDS[argc]}" -prev="${COMP_WORDS[argc-1]}" -opts=$(yunohost -h | sed -n "/usage/,/}/p" | awk -F"{" '{print $2}' | awk -F"}" '{print $1}' | tr ',' ' ') - -if [[ $argc = 1 ]]; -then - COMPREPLY=( $(compgen -W "$opts --help" -- $cur ) ) -fi - -if [[ "$prev" != "--help" ]]; -then - if [[ $argc = 2 ]]; - then - opts2=$(yunohost $prev -h | sed -n "/usage/,/}/p" | awk -F"{" '{print $2}' | awk -F"}" '{print $1}' | tr ',' ' ') - COMPREPLY=( $(compgen -W "$opts2 --help" -- $cur ) ) - elif [[ $argc = 3 ]]; - then - COMPREPLY=( $(compgen -W "--help" $cur ) ) - fi -else - COMPREPLY=() -fi - -} -complete -F _yunohost_cli yunohost diff --git a/test/conftest.py b/test/conftest.py index d7f7700c..4cf10815 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -40,13 +40,13 @@ def patch_translate(moulinette): def patch_logging(moulinette): """Configure logging to use the custom logger.""" - handlers = set(['tty']) + handlers = set(['tty', 'api']) root_handlers = set(handlers) level = 'INFO' tty_level = 'INFO' - logging = { + return { 'version': 1, 'disable_existing_loggers': True, 'formatters': { @@ -91,32 +91,39 @@ def patch_logging(moulinette): }, } + + +@pytest.fixture(scope='session', autouse=True) +def moulinette(tmp_path_factory): + import moulinette + + # Can't call the namespace just 'test' because + # that would lead to some "import test" not importing the right stuff + namespace = "moulitest" + tmp_data = str(tmp_path_factory.mktemp("data")) + tmp_lib = str(tmp_path_factory.mktemp("lib")) + os.environ['MOULINETTE_DATA_DIR'] = tmp_data + os.environ['MOULINETTE_LIB_DIR'] = tmp_lib + shutil.copytree("./test/actionsmap", "%s/actionsmap" % tmp_data) + shutil.copytree("./test/src", "%s/%s" % (tmp_lib, namespace)) + shutil.copytree("./test/locales", "%s/%s/locales" % (tmp_lib, namespace)) + + patch_init(moulinette) + patch_translate(moulinette) + logging = patch_logging(moulinette) + moulinette.init( logging_config=logging, _from_source=False ) - -@pytest.fixture(scope='session', autouse=True) -def moulinette(): - import moulinette - - patch_init(moulinette) - patch_translate(moulinette) - patch_logging(moulinette) - return moulinette @pytest.fixture(scope='session') -def moulinette_webapi(moulinette, tmp_path_factory): - namespace = "test" - tmp_data = str(tmp_path_factory.mktemp("data")) - tmp_locales = str(tmp_path_factory.mktemp("data")) - os.environ['MOULINETTE_DATA_DIR'] = tmp_data - os.environ['MOULINETTE_LIB_DIR'] = tmp_locales - shutil.copytree("./data/actionsmap", "%s/actionsmap" % tmp_data) - shutil.copytree("./locales", "%s/%s/locales" % (tmp_locales, namespace)) +def moulinette_webapi(moulinette): + + namespace = "moulitest" api_thread = Process(target=moulinette.api, args=([namespace],),