diff --git a/Makefile b/Makefile index 301df6f..476b90e 100644 --- a/Makefile +++ b/Makefile @@ -17,13 +17,16 @@ check-poetry: fi install-poetry: ## install or update poetry + pip3 install -U pip pip3 install -U poetry install: check-poetry ## install project via poetry poetry install -update: install-poetry ## update the sources and installation +update: install-poetry ## update the sources and installation and generate "conf/requirements.txt" + poetry run pip install -U pip poetry update + poetry export -f requirements.txt --output conf/requirements.txt lint: ## Run code formatters and linter poetry run flynt --fail-on-change --line_length=${MAX_LINE_LENGTH} . diff --git a/README.md b/README.md index 5143946..1c0a23c 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,29 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Pull requests welcome ;) + ## Overview Glue code to package django projects as yunohost apps. +This project is: + +* The Python package [django-ynh](https://pypi.org/project/django-ynh/) with helpers for integrate a Django project as YunoHost package +* A example YunoHost Application that can be installed +* Run Django development server with a local generated YunoHost package installation (called `local_test`) + + +### usage + +To create/update a the first user in `install`/`upgrade`, e.g.: + +```bash +./manage.py create_superuser --username="$admin" --email="$admin_mail" +``` +This Create/update Django superuser and set a unusable password. +A password is not needed, because auth done via SSOwat ;) + + ## SSO authentication [SSOwat](https://github.com/YunoHost/SSOwat) is fully supported: @@ -28,6 +47,10 @@ Glue code to package django projects as yunohost apps. * [compare v0.1.0...master](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.0...master) **dev** * tbc +* [v0.1.1 - 28.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.0...v0.1.1) + * Refactor "create_superuser" to a manage command, useable via "django_ynh" in `INSTALLED_APPS` + * Generate "conf/requirements.txt" and use this file for install + * rename own settings and urls (in `/conf/`) * [v0.1.0 - 28.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/f578f14...v0.1.0) * first working state * [23.12.2020](https://github.com/YunoHost-Apps/django_ynh/commit/f578f144a3a6d11d7044597c37d550d29c247773) diff --git a/conf/manage.py b/conf/manage.py index 5451027..a85e3b1 100755 --- a/conf/manage.py +++ b/conf/manage.py @@ -5,7 +5,7 @@ import sys def main(): - os.environ['DJANGO_SETTINGS_MODULE'] = 'django_ynh_demo_settings' + os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.core.management import execute_from_command_line execute_from_command_line(sys.argv) diff --git a/conf/nginx.conf b/conf/nginx.conf index 2b5372d..8c05d5e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -5,7 +5,7 @@ location __PATH__/static/ { expires 30d; } -location / { +location __PATH__/ { # https://github.com/benoitc/gunicorn/blob/master/examples/nginx.conf proxy_http_version 1.1; diff --git a/conf/requirements.txt b/conf/requirements.txt new file mode 100644 index 0000000..17b51d1 --- /dev/null +++ b/conf/requirements.txt @@ -0,0 +1,62 @@ +asgiref==3.3.1; python_version >= "3.6" and python_version < "4.0" \ + --hash=sha256:5ee950735509d04eb673bd7f7120f8fa1c9e2df495394992c73234d526907e17 \ + --hash=sha256:7162a3cb30ab0609f1a4c95938fd73e8604f63bdba516a7f7d64b83ff09478f0 +django-axes==5.10.0; python_version >= "3.6" and python_version < "4.0" \ + --hash=sha256:8a62cd4cc78ef08007e8102def34be83832995eb6e3e0c814d605741b82a2796 \ + --hash=sha256:3c81ddca8a9d7fd0019cb440f711cc873c3039546f7eacb3f2ec616bf0ec1b32 +django-ipware==3.0.2; python_version >= "3.6" and python_version < "4.0" \ + --hash=sha256:c7df8e1410a8e5d6b1fbae58728402ea59950f043c3582e033e866f0f0cf5e94 +django-redis==4.12.1; python_version >= "3.5" \ + --hash=sha256:306589c7021e6468b2656edc89f62b8ba67e8d5a1c8877e2688042263daa7a63 \ + --hash=sha256:1133b26b75baa3664164c3f44b9d5d133d1b8de45d94d79f38d1adc5b1d502e5 +django==3.1.4; python_version >= "3.6" \ + --hash=sha256:5c866205f15e7a7123f1eec6ab939d22d5bde1416635cab259684af66d8e48a2 \ + --hash=sha256:edb10b5c45e7e9c0fb1dc00b76ec7449aca258a39ffd613dbd078c51d19c9f03 +gunicorn==20.0.4; python_version >= "3.4" \ + --hash=sha256:cd4a810dd51bf497552cf3f863b575dabd73d6ad6a91075b65936b151cbf4f9c \ + --hash=sha256:1904bb2b8a43658807108d59c3f3d56c2b6121a701161de0ddf9ad140073c626 +psycopg2-binary==2.8.6; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0") \ + --hash=sha256:11b9c0ebce097180129e422379b824ae21c8f2a6596b159c7659e2e5a00e1aa0 \ + --hash=sha256:d14b140a4439d816e3b1229a4a525df917d6ea22a0771a2a78332273fd9528a4 \ + --hash=sha256:1fabed9ea2acc4efe4671b92c669a213db744d2af8a9fc5d69a8e9bc14b7a9db \ + --hash=sha256:f5ab93a2cb2d8338b1674be43b442a7f544a0971da062a5da774ed40587f18f5 \ + --hash=sha256:b4afc542c0ac0db720cf516dd20c0846f71c248d2b3d21013aa0d4ef9c71ca25 \ + --hash=sha256:e74a55f6bad0e7d3968399deb50f61f4db1926acf4a6d83beaaa7df986f48b1c \ + --hash=sha256:0deac2af1a587ae12836aa07970f5cb91964f05a7c6cdb69d8425ff4c15d4e2c \ + --hash=sha256:ad20d2eb875aaa1ea6d0f2916949f5c08a19c74d05b16ce6ebf6d24f2c9f75d1 \ + --hash=sha256:950bc22bb56ee6ff142a2cb9ee980b571dd0912b0334aa3fe0fe3788d860bea2 \ + --hash=sha256:b8a3715b3c4e604bcc94c90a825cd7f5635417453b253499664f784fc4da0152 \ + --hash=sha256:d1b4ab59e02d9008efe10ceabd0b31e79519da6fb67f7d8e8977118832d0f449 \ + --hash=sha256:ac0c682111fbf404525dfc0f18a8b5f11be52657d4f96e9fcb75daf4f3984859 \ + --hash=sha256:7d92a09b788cbb1aec325af5fcba9fed7203897bbd9269d5691bb1e3bce29550 \ + --hash=sha256:aaa4213c862f0ef00022751161df35804127b78adf4a2755b9f991a507e425fd \ + --hash=sha256:c2507d796fca339c8fb03216364cca68d87e037c1f774977c8fc377627d01c71 \ + --hash=sha256:ee69dad2c7155756ad114c02db06002f4cded41132cc51378e57aad79cc8e4f4 \ + --hash=sha256:e82aba2188b9ba309fd8e271702bd0d0fc9148ae3150532bbb474f4590039ffb \ + --hash=sha256:d5227b229005a696cc67676e24c214740efd90b148de5733419ac9aaba3773da \ + --hash=sha256:a0eb43a07386c3f1f1ebb4dc7aafb13f67188eab896e7397aa1ee95a9c884eb2 \ + --hash=sha256:e1f57aa70d3f7cc6947fd88636a481638263ba04a742b4a37dd25c373e41491a \ + --hash=sha256:833709a5c66ca52f1d21d41865a637223b368c0ee76ea54ca5bad6f2526c7679 \ + --hash=sha256:ba28584e6bca48c59eecbf7efb1576ca214b47f05194646b081717fa628dfddf \ + --hash=sha256:6a32f3a4cb2f6e1a0b15215f448e8ce2da192fd4ff35084d80d5e39da683e79b \ + --hash=sha256:0e4dc3d5996760104746e6cfcdb519d9d2cd27c738296525d5867ea695774e67 \ + --hash=sha256:cec7e622ebc545dbb4564e483dd20e4e404da17ae07e06f3e780b2dacd5cee66 \ + --hash=sha256:ba381aec3a5dc29634f20692349d73f2d21f17653bda1decf0b52b11d694541f \ + --hash=sha256:a0c50db33c32594305b0ef9abc0cb7db13de7621d2cadf8392a1d9b3c437ef77 \ + --hash=sha256:2dac98e85565d5688e8ab7bdea5446674a83a3945a8f416ad0110018d1501b94 \ + --hash=sha256:bd1be66dde2b82f80afb9459fc618216753f67109b859a361cf7def5c7968729 \ + --hash=sha256:8cd0fb36c7412996859cb4606a35969dd01f4ea34d9812a141cd920c3b18be77 \ + --hash=sha256:89705f45ce07b2dfa806ee84439ec67c5d9a0ef20154e0e475e2b2ed392a5b83 \ + --hash=sha256:42ec1035841b389e8cc3692277a0bd81cdfe0b65d575a2c8862cec7a80e62e52 \ + --hash=sha256:7312e931b90fe14f925729cde58022f5d034241918a5c4f9797cac62f6b3a9dd \ + --hash=sha256:6422f2ff0919fd720195f64ffd8f924c1395d30f9a495f31e2392c2efafb5056 \ + --hash=sha256:15978a1fbd225583dd8cdaf37e67ccc278b5abecb4caf6b2d6b8e2b948e953f6 +pytz==2020.5; python_version >= "3.6" and python_version < "4.0" \ + --hash=sha256:16962c5fb8db4a8f63a26646d8886e9d769b6c511543557bc84e9569fb9a9cb4 \ + --hash=sha256:180befebb1927b16f6b57101720075a984c019ac16b1b7575673bea42c6c3da5 +redis==3.5.3; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.5" \ + --hash=sha256:432b788c4530cfe16d8d943a09d40ca6c16149727e4afe8c2c9d5580c59d9f24 \ + --hash=sha256:0e7e0cfca8660dea8b7d5cd8c4f6c5e29e11f31158c0b0ae91a397f00e5a05a2 +sqlparse==0.4.1; python_version >= "3.6" and python_version < "4.0" \ + --hash=sha256:017cde379adbd6a1f15a61873f43e8274179378e95ef3fede90b5aa64d304ed0 \ + --hash=sha256:0f91fd2e829c44362cbcfab3e9ae12e22badaa8a29ad5ff599f9ec109f0454e8 diff --git a/conf/django_ynh_demo_settings.py b/conf/settings.py similarity index 99% rename from conf/django_ynh_demo_settings.py rename to conf/settings.py index afecb94..e28d35b 100644 --- a/conf/django_ynh_demo_settings.py +++ b/conf/settings.py @@ -37,9 +37,6 @@ PATH_URL = PATH_URL.strip('/') # ----------------------------------------------------------------------------- - -ROOT_URLCONF = 'django_ynh_demo_urls' - YNH_SETUP_USER = 'setup_user.setup_demo_user' SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt diff --git a/conf/django_ynh_demo_urls.py b/conf/urls.py similarity index 100% rename from conf/django_ynh_demo_urls.py rename to conf/urls.py diff --git a/conf/wsgi.py b/conf/wsgi.py index 70d2e49..81075a9 100644 --- a/conf/wsgi.py +++ b/conf/wsgi.py @@ -4,7 +4,7 @@ import os -os.environ['DJANGO_SETTINGS_MODULE'] = 'django_ynh_demo_settings' +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.core.wsgi import get_wsgi_application diff --git a/django_ynh/__init__.py b/django_ynh/__init__.py index b794fd4..df9144c 100644 --- a/django_ynh/__init__.py +++ b/django_ynh/__init__.py @@ -1 +1 @@ -__version__ = '0.1.0' +__version__ = '0.1.1' diff --git a/django_ynh/base_settings.py b/django_ynh/base_settings.py index 71e8fa7..32dea60 100644 --- a/django_ynh/base_settings.py +++ b/django_ynh/base_settings.py @@ -7,11 +7,12 @@ # ----------------------------------------------------------------------------- # settings that should be set in project settings: -ROOT_URLCONF = None SECRET_KEY = None # ----------------------------------------------------------------------------- +ROOT_URLCONF = 'urls' # .../conf/urls.py + INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -20,6 +21,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'axes', # https://github.com/jazzband/django-axes + 'django_ynh', ] # ----------------------------------------------------------------------------- diff --git a/django_ynh/create_superuser.py b/django_ynh/create_superuser.py deleted file mode 100644 index 95d2f40..0000000 --- a/django_ynh/create_superuser.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 - -""" - Can be called e.g.: - - poetry run create_superuser --ds="foo.settings" --username="bar" \ - --email="foo@bar.tld" --password="no-password" - - or, e.g.: - - python3 -m django_ynh.create_superuser --ds="foo.settings" --username="bar" \ - --email="foo@bar.tld" \ - --password="no-password" -""" - -import argparse -import os -import sys - - -def main(): - parser = argparse.ArgumentParser(description='Create or update Django super user.') - parser.add_argument('--ds', help='The "DJANGO_SETTINGS_MODULE" string') - parser.add_argument('--username') - parser.add_argument('--email') - parser.add_argument('--password') - - args = parser.parse_args() - - os.environ['DJANGO_SETTINGS_MODULE'] = args.ds - - username = args.username - email = args.email or '' - password = args.password - - import django - - django.setup() - - from django.contrib.auth import get_user_model - - User = get_user_model() - user = User.objects.filter(username=username).first() - if user: - print(f'Update existing user "{user}" and set his password.', file=sys.stderr) - print(repr(password)) - user.is_active = True - user.is_staff = True - user.is_superuser = True - user.set_password(password) - user.email = email - user.save() - else: - print(f'Create new super user "{username}"', file=sys.stderr) - User.objects.create_superuser(username=username, email=email, password=password) - - -if __name__ == '__main__': - main() diff --git a/django_ynh/management/__init__.py b/django_ynh/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_ynh/management/commands/__init__.py b/django_ynh/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_ynh/management/commands/create_superuser.py b/django_ynh/management/commands/create_superuser.py new file mode 100644 index 0000000..f69c2ba --- /dev/null +++ b/django_ynh/management/commands/create_superuser.py @@ -0,0 +1,49 @@ +""" + Create or update Django super user with a unusable password + + A "unusable password" because it's not needed while auth via SSOwat ;) + + Can be called e.g.: + ./manage.py create_superuser --username="bar" --email="foo@bar.tld" +""" + + +import sys + +from django.contrib.auth import get_user_model +from django.core.management import BaseCommand + + +class Command(BaseCommand): + help = 'Create or update Django super user with a unusable password (auth via SSOwat)' + + def add_arguments(self, parser): + parser.add_argument( + "--username", + action="store", + required=True, + ) + parser.add_argument( + "--email", + action="store", + required=True, + ) + + def handle(self, *args, **options): + username = options['username'] + email = options['email'] + + User = get_user_model() + user = User.objects.filter(username=username).first() + if user: + self.stderr.write(f'Update existing user "{user}" and set his password.') + user.is_active = True + user.is_staff = True + user.is_superuser = True + user.email = email + else: + print(f'Create new super user "{username}"', file=sys.stderr) + user = User.objects.create_superuser(username=username, email=email, password=None) + + user.set_unusable_password() + user.save() diff --git a/django_ynh/pytest_helper.py b/django_ynh/pytest_helper.py index a806545..83b6358 100644 --- a/django_ynh/pytest_helper.py +++ b/django_ynh/pytest_helper.py @@ -32,7 +32,7 @@ def run_pytest(django_settings_path, destination): import pytest - # collect only project tests: - sys.argv = [__file__, str(test_path)] + # collect only project tests and pass existing pytest arguments: + sys.argv = [__file__, str(test_path)] + sys.argv[1:] raise SystemExit(pytest.console_main()) diff --git a/local_test.py b/local_test.py index 6be93c7..d1a1dc9 100644 --- a/local_test.py +++ b/local_test.py @@ -21,7 +21,7 @@ BASE_PATH = Path(__file__).parent def main(): create_local_test( - django_settings_path=BASE_PATH / 'conf' / 'django_ynh_demo_settings.py', + django_settings_path=BASE_PATH / 'conf' / 'settings.py', destination=BASE_PATH / 'local_test', runserver=True, ) diff --git a/manifest.json b/manifest.json index 0437bf1..23ab0b7 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Glue code to package django projects as yunohost apps." }, - "version": "0.1.0~ynh1", + "version": "0.1.1~ynh1", "url": "https://github.com/jedie/django_ynh", "license": "GPL-3.0", "maintainer": { diff --git a/pyproject.toml b/pyproject.toml index 29e65d8..84b053e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django_ynh" -version = "0.1.0" +version = "0.1.1" description = "Glue code to package django projects as yunohost apps." authors = ["JensDiemer "] license = "GPL" @@ -37,9 +37,6 @@ pyupgrade = "*" requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" -[tool.poetry.scripts] -create_superuser = "django_ynh.create_superuser:main" - [tool.isort] # https://pycqa.github.io/isort/docs/configuration/config_files/#pyprojecttoml-preferred-format atomic=true diff --git a/run_pytest.py b/run_pytest.py index ecc1ab2..a398526 100644 --- a/run_pytest.py +++ b/run_pytest.py @@ -16,7 +16,7 @@ BASE_PATH = Path(__file__).parent def main(): run_pytest( - django_settings_path=BASE_PATH / 'conf' / 'django_ynh_demo_settings.py', + django_settings_path=BASE_PATH / 'conf' / 'settings.py', destination=BASE_PATH / 'local_test', ) diff --git a/scripts/_common.sh b/scripts/_common.sh index bb2a443..66100bd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -25,14 +25,10 @@ log_file="${log_path}/django_ynh.log" #================================================= # dependencies used by the app -pkg_dependencies="build-essential python3-dev python3-pip python3-venv git \ - postgresql postgresql-contrib" +pkg_dependencies="build-essential python3-dev python3-pip python3-venv git postgresql postgresql-contrib" -# django_ynh's version for PIP and settings file -django_ynh_version="0.8.2" - -# Extra python packages: -pypi_extras="django-redis" +# To install/upgrade this project via pip: +pip_install_string="django_ynh==0.1.1" #================================================= # Redis HELPERS diff --git a/scripts/install b/scripts/install index 194260e..f949f81 100755 --- a/scripts/install +++ b/scripts/install @@ -101,9 +101,10 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell #================================================= # PIP INSTALLATION #================================================= -ynh_script_progression --message="Install django_ynh using PIP..." --weight=80 +ynh_script_progression --message="Install project via pip..." --weight=80 python3 -m venv "${final_path}/venv" +cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app" "$final_path" #run source in a 'sub shell' @@ -112,9 +113,8 @@ chown -R "$app" "$final_path" source "${final_path}/venv/bin/activate" set -o nounset ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade django_ynh=="$django_ynh_version" - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade ${pypi_extras} + ynh_exec_as $app $final_path/venv/bin/pip install -r "$final_path/requirements.txt" + ynh_exec_as $app $final_path/venv/bin/pip install --upgrade "$pip_install_string" ) #================================================= @@ -122,9 +122,6 @@ chown -R "$app" "$final_path" # ================================================ ynh_script_progression --message="Create django_ynh configuration file..." -cp ../conf/create_superuser.py "$final_path/create_superuser.py" -chmod +x "$final_path/create_superuser.py" - gunicorn_conf="$final_path/gunicorn.conf.py" cp "../conf/gunicorn.conf.py" "$gunicorn_conf" ynh_replace_string --match_string="__FINAL_HOME_PATH__" --replace_string="$final_path" --target_file="$gunicorn_conf" @@ -159,8 +156,7 @@ ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" touch "$final_path/local_settings.py" -cp "../conf/ynh_authenticate.py" "$final_path/ynh_authenticate.py" -cp "../conf/ynh_urls.py" "$final_path/ynh_urls.py" +cp "../conf/urls.py" "$final_path/urls.py" #================================================= # MIGRATE / COLLECTSTATIC / CREATEADMIN @@ -178,7 +174,8 @@ ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight ./manage.py migrate --no-input ./manage.py collectstatic --no-input - ./create_superuser.py --username="$admin" --email="$admin_mail" --password="django_ynh" + + python -m django_ynh.create_superuser --ds="django_ynh_demo_settings" --username="$admin" --email="$admin_mail" --password="$app" # Check the configuration # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. diff --git a/scripts/upgrade b/scripts/upgrade index ceb35c2..be9bdd7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -83,33 +83,28 @@ ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config --service="$app" --template="django_ynh.service" #================================================= -# UPGRADE django_ynh +# UPGRADE VENV #================================================= - -ynh_script_progression --message="Install django_ynh using PIP..." --weight=15 +ynh_script_progression --message="Upgrade project via pip..." --weight=80 python3 -m venv "${final_path}/venv" +cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app" "$final_path" #run source in a 'sub shell' ( - set +o nounset - source "${final_path}/venv/bin/activate" - set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade django_ynh=="$django_ynh_version" - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade ${pypi_extras} + set +o nounset + source "${final_path}/venv/bin/activate" + set -o nounset + ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip + ynh_exec_as $app $final_path/venv/bin/pip install -r "$final_path/requirements.txt" + ynh_exec_as $app $final_path/venv/bin/pip install --upgrade "$pip_install_string" ) #================================================= # copy config files # ================================================ -ynh_script_progression --message="Create django_ynh configuration file..." - -ynh_backup_if_checksum_is_different --file="$final_path/create_superuser.py" -cp ../conf/create_superuser.py "$final_path/create_superuser.py" -chmod +x "$final_path/create_superuser.py" +ynh_script_progression --message="Create project configuration files..." gunicorn_conf="$final_path/gunicorn.conf.py" ynh_backup_if_checksum_is_different --file="$gunicorn_conf" @@ -149,8 +144,7 @@ ynh_store_file_checksum --file="$settings" touch "$final_path/local_settings.py" -cp "../conf/ynh_authenticate.py" "$final_path/ynh_authenticate.py" -cp "../conf/ynh_urls.py" "$final_path/ynh_urls.py" +cp "../conf/urls.py" "$final_path/urls.py" #================================================= # MIGRATE django_ynh @@ -158,21 +152,23 @@ cp "../conf/ynh_urls.py" "$final_path/ynh_urls.py" ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10 ( - set +o nounset - source "${final_path}/venv/bin/activate" - set -o nounset - cd "${final_path}" + set +o nounset + source "${final_path}/venv/bin/activate" + set -o nounset + cd "${final_path}" - # Just for debugging: - ./manage.py diffsettings + # Just for debugging: + ./manage.py diffsettings - ./manage.py migrate --no-input - ./manage.py collectstatic --no-input - ./create_superuser.py --username="$admin" --email="$admin_mail" --password="django_ynh" + ./manage.py migrate --no-input + ./manage.py collectstatic --no-input - # Check the configuration - # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. - ./manage.py check --deploy || true + # Create/update Django superuser (set unusable password, because auth done via SSOwat): + ./manage.py create_superuser --username="$admin" --email="$admin_mail" + + # Check the configuration + # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. + ./manage.py check --deploy || true ) #================================================= diff --git a/tests/test_django_ynh.py b/tests/test_django_ynh.py index 18c48fb..aefe636 100644 --- a/tests/test_django_ynh.py +++ b/tests/test_django_ynh.py @@ -25,7 +25,7 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase): assert str(settings.FINAL_WWW_PATH).endswith('/local_test/var_www') assert str(settings.LOG_FILE).endswith('/local_test/var_log_django_ynh.log') - assert settings.ROOT_URLCONF == 'django_ynh_demo_urls' + assert settings.ROOT_URLCONF == 'urls' def test_urls(self): assert reverse('admin:index') == '/app_path/' diff --git a/tests/test_project_setup.py b/tests/test_project_setup.py index 49733c6..037ad73 100644 --- a/tests/test_project_setup.py +++ b/tests/test_project_setup.py @@ -31,6 +31,9 @@ def test_version(package_root=None, version=None): assert_file_contains_string(file_path=Path(package_root, 'pyproject.toml'), string=f'version = "{version}"') assert_file_contains_string(file_path=Path(package_root, 'manifest.json'), string=f'"version": "{version}~ynh') + assert_file_contains_string( + file_path=Path(package_root, 'scripts', '_common.sh'), string=f'"django_ynh=={version}"' + ) def test_poetry_check(package_root=None):