diff --git a/Makefile b/Makefile index 87bbe51..f174071 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ tox: check-poetry ## Run pytest via tox with all environments poetry run tox pytest: install ## Run pytest - poetry run python3 ./run_pytest.py + poetry run pytest local-test: install ## Run local_test.py to run the project locally poetry run python3 ./local_test.py diff --git a/conf/urls.py b/conf/urls.py index 367500a..9774f12 100644 --- a/conf/urls.py +++ b/conf/urls.py @@ -22,10 +22,8 @@ if settings.PATH_URL: # Prefix all urls with "PATH_URL": urlpatterns = [ # path(f'{settings.PATH_URL}/debug/', debug_view), - # MEDIA_URL contains the "PATH_URL" already: path(settings.MEDIA_URL.lstrip('/'), include('django_tools.serve_media_app.urls')), - path(f'{settings.PATH_URL}/', admin.site.urls), path(f'{settings.PATH_URL}/ckeditor/', include('ckeditor_uploader.urls')), ] diff --git a/poetry.lock b/poetry.lock index c94cd9c..7fb39f7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -832,31 +832,6 @@ pytest = ">=5.4.0" docs = ["sphinx", "sphinx-rtd-theme"] testing = ["django", "django-configurations (>=2.0)"] -[[package]] -name = "pytest-flake8" -version = "1.1.1" -description = "pytest plugin to check FLAKE8 requirements" -category = "dev" -optional = false -python-versions = "*" - -[package.dependencies] -flake8 = ">=4.0" -pytest = ">=7.0" - -[[package]] -name = "pytest-isort" -version = "3.0.0" -description = "py.test plugin to check import ordering using isort" -category = "dev" -optional = false -python-versions = ">=3.6,<4" - -[package.dependencies] -importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} -isort = ">=4.0" -pytest = ">=5.0" - [[package]] name = "python-stdnum" version = "1.17" @@ -1122,7 +1097,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>= [metadata] lock-version = "1.1" python-versions = ">=3.7,<4.0.0" -content-hash = "f5b4aed88d8eef1bf5a3842ca9f0c0c04cb7094b81220f94f5dd0602d3fbaec7" +content-hash = "cf487e10c2856aad310b7d5ea174044e12605989d49a06517750b0192c85609a" [metadata.files] asgiref = [ @@ -1532,14 +1507,6 @@ pytest-django = [ {file = "pytest-django-4.5.2.tar.gz", hash = "sha256:d9076f759bb7c36939dbdd5ae6633c18edfc2902d1a69fdbefd2426b970ce6c2"}, {file = "pytest_django-4.5.2-py3-none-any.whl", hash = "sha256:c60834861933773109334fe5a53e83d1ef4828f2203a1d6a0fa9972f4f75ab3e"}, ] -pytest-flake8 = [ - {file = "pytest-flake8-1.1.1.tar.gz", hash = "sha256:ba4f243de3cb4c2486ed9e70752c80dd4b636f7ccb27d4eba763c35ed0cd316e"}, - {file = "pytest_flake8-1.1.1-py2.py3-none-any.whl", hash = "sha256:e0661a786f8cbf976c185f706fdaf5d6df0b1667c3bcff8e823ba263618627e7"}, -] -pytest-isort = [ - {file = "pytest-isort-3.0.0.tar.gz", hash = "sha256:4fe4b26ead2af776730ec23f5870d7421f35aace22a41c4e938586ef4d8787cb"}, - {file = "pytest_isort-3.0.0-py3-none-any.whl", hash = "sha256:2d96a25a135d6fd084ac36878e7d54f26f27c6987c2c65f0d12809bffade9cb9"}, -] python-stdnum = [ {file = "python-stdnum-1.17.tar.gz", hash = "sha256:374e2b5e13912ccdbf50b0b23fca2c3e0531174805c32d74e145f37756328340"}, {file = "python_stdnum-1.17-py2.py3-none-any.whl", hash = "sha256:a46e6cf9652807314d369b654b255c86a59f93d18be2834f3d567ed1a346c547"}, diff --git a/pyproject.toml b/pyproject.toml index 1376c1f..4944132 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,8 +22,8 @@ pytest = "*" pytest-cov = "*" pytest-django = "*" pytest-darker = "*" # https://github.com/akaihola/pytest-darker -pytest-flake8 = "*" -pytest-isort = "*" +flake8 = "*" +isort = "*" coveralls = "*" flynt = "*" pyupgrade = "*" @@ -86,8 +86,6 @@ addopts = """ --no-cov-on-fail --showlocals --darker - --flake8 - --isort --doctest-modules --failed-first --last-failed-no-failures all diff --git a/run_pytest.py b/run_pytest.py deleted file mode 100644 index 086b5ef..0000000 --- a/run_pytest.py +++ /dev/null @@ -1,25 +0,0 @@ -""" - Run pytest against local test creation -""" - -from pathlib import Path - - -try: - from django_yunohost_integration.pytest_helper import run_pytest -except ImportError as err: - raise ImportError('Did you forget to activate a virtual environment?') from err - - -BASE_PATH = Path(__file__).parent - - -def main(): - run_pytest( - django_settings_path=BASE_PATH / 'conf' / 'settings.py', - destination=BASE_PATH / 'local_test', - ) - - -if __name__ == '__main__': - main() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..75f20f0 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,43 @@ +""" + Special pytest init: + + - Build a "local_test" YunoHost installation + - init Django with this local test installation + + So the pytests will run against this local test installation +""" +import os +import sys +from pathlib import Path + +import django +from django_yunohost_integration.local_test import create_local_test + + +BASE_PATH = Path(__file__).parent.parent + +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + + +def pytest_configure(): + print('Compile YunoHost files...') + final_path = create_local_test( + django_settings_path=BASE_PATH / 'conf' / 'settings.py', + destination=BASE_PATH / 'local_test', + runserver=False, + extra_replacements={ + '__DEBUG_ENABLED__': '0', + '__LOG_LEVEL__': 'INFO', + '__ADMIN_EMAIL__': 'foo-bar@test.tld', + '__DEFAULT_FROM_EMAIL__': 'django_app@test.tld', + }, + ) + print('Local test files created here:') + print(f'"{final_path}"') + + os.chdir(final_path) + final_home_str = str(final_path) + if final_home_str not in sys.path: + sys.path.insert(0, final_home_str) + + django.setup() diff --git a/tests/test_project_setup.py b/tests/test_project_setup.py index 98e50c2..2278693 100644 --- a/tests/test_project_setup.py +++ b/tests/test_project_setup.py @@ -24,12 +24,8 @@ def assert_file_contains_string(file_path, string): def test_version(): version = inventory.__version__ - assert_file_contains_string( - file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh' - ) - 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, 'pyproject.toml'), string=f'version = "{version}~ynh') + assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh') def poetry_check_output(*args): @@ -52,7 +48,7 @@ def test_poetry_check(): def test_requirements_txt(): - requirements_txt = Path('conf', 'requirements.txt') + requirements_txt = PACKAGE_ROOT / 'conf' / 'requirements.txt' assert_is_file(requirements_txt) output = poetry_check_output('export', '-f', 'requirements.txt')