diff --git a/mypy.ini b/mypy.ini index bfede6e..0bfb45b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,20 +1,20 @@ [mypy] namespace_packages = True warn_unused_ignores = True # support for django magic: https://github.com/typeddjango/django-stubs plugins = mypy_django_plugin.main, mypy_drf_plugin.main [mypy.plugins.django-stubs] -django_settings_module = swh.auth.tests.app.apptest.settings +django_settings_module = swh.auth.tests.django.app.apptest.settings # 3rd party libraries without stubs (yet) [mypy-pkg_resources.*] ignore_missing_imports = True [mypy-pytest.*] ignore_missing_imports = True [mypy-keycloak.*] ignore_missing_imports = True diff --git a/pytest.ini b/pytest.ini index 81fe35e..0e4be09 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ [pytest] norecursedirs = docs .* -DJANGO_SETTINGS_MODULE = swh.auth.tests.app.apptest.settings +DJANGO_SETTINGS_MODULE = swh.auth.tests.django.app.apptest.settings diff --git a/swh/auth/tests/app/__init__.py b/swh/auth/tests/django/__init__.py similarity index 100% copy from swh/auth/tests/app/__init__.py copy to swh/auth/tests/django/__init__.py diff --git a/swh/auth/tests/app/apptest/__init__.py b/swh/auth/tests/django/app/__init__.py similarity index 100% rename from swh/auth/tests/app/apptest/__init__.py rename to swh/auth/tests/django/app/__init__.py diff --git a/swh/auth/tests/app/__init__.py b/swh/auth/tests/django/app/apptest/__init__.py similarity index 100% rename from swh/auth/tests/app/__init__.py rename to swh/auth/tests/django/app/apptest/__init__.py diff --git a/swh/auth/tests/app/apptest/apps.py b/swh/auth/tests/django/app/apptest/apps.py similarity index 86% rename from swh/auth/tests/app/apptest/apps.py rename to swh/auth/tests/django/app/apptest/apps.py index 9ebdc06..0be5723 100644 --- a/swh/auth/tests/app/apptest/apps.py +++ b/swh/auth/tests/django/app/apptest/apps.py @@ -1,10 +1,10 @@ # Copyright (C) 2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from django.apps import AppConfig class TestApp(AppConfig): - name = "swh.auth.tests.app" + name = "swh.auth.tests.django.app.apptest" diff --git a/swh/auth/tests/app/apptest/models.py b/swh/auth/tests/django/app/apptest/models.py similarity index 100% rename from swh/auth/tests/app/apptest/models.py rename to swh/auth/tests/django/app/apptest/models.py diff --git a/swh/auth/tests/app/apptest/settings.py b/swh/auth/tests/django/app/apptest/settings.py similarity index 76% rename from swh/auth/tests/app/apptest/settings.py rename to swh/auth/tests/django/app/apptest/settings.py index 163c790..543d0ac 100644 --- a/swh/auth/tests/app/apptest/settings.py +++ b/swh/auth/tests/django/app/apptest/settings.py @@ -1,7 +1,7 @@ SECRET_KEY = "o+&ayiuk(y^wh4ijz5e=c2$$kjj7g^6r%z+8d*c0lbpfs##k#7" INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", - "swh.auth.tests.app.apptest.apps.TestApp", + "swh.auth.tests.django.app.apptest", ] diff --git a/swh/auth/tests/app/apptest/urls.py b/swh/auth/tests/django/app/apptest/urls.py similarity index 100% rename from swh/auth/tests/app/apptest/urls.py rename to swh/auth/tests/django/app/apptest/urls.py diff --git a/swh/auth/tests/app/manage.py b/swh/auth/tests/django/app/manage.py similarity index 88% rename from swh/auth/tests/app/manage.py rename to swh/auth/tests/django/app/manage.py index 57db14f..8c77d38 100755 --- a/swh/auth/tests/app/manage.py +++ b/swh/auth/tests/django/app/manage.py @@ -1,23 +1,23 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys def main(): os.environ.setdefault( - "DJANGO_SETTINGS_MODULE", "swh.auth.tests.app.apptest.settings" + "DJANGO_SETTINGS_MODULE", "swh.auth.tests.django.app.apptest.settings" ) try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) if __name__ == "__main__": main() diff --git a/swh/auth/tests/test_models.py b/swh/auth/tests/django/test_models.py similarity index 97% rename from swh/auth/tests/test_models.py rename to swh/auth/tests/django/test_models.py index 8f61216..c5ebf3a 100644 --- a/swh/auth/tests/test_models.py +++ b/swh/auth/tests/django/test_models.py @@ -1,68 +1,68 @@ # Copyright (C) 2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from typing import Set import pytest -from swh.auth.tests.app.apptest.models import AppUser +from .app.apptest.models import AppUser PERMISSIONS: Set[str] = set(["api", "app-label-read"]) NO_PERMISSION: Set[str] = set() @pytest.fixture def appuser(): return AppUser( id=666, username="foo", password="bar", first_name="foobar", last_name="", email="foo@bar.org", ) @pytest.fixture def appuser_admin(appuser): appuser_admin = appuser appuser_admin.is_active = True appuser_admin.is_superuser = True return appuser_admin def test_django_appuser(appuser): appuser.permissions = PERMISSIONS assert appuser.get_group_permissions() == PERMISSIONS assert appuser.get_group_permissions(appuser) == PERMISSIONS assert appuser.get_all_permissions() == PERMISSIONS assert appuser.get_all_permissions(appuser) == PERMISSIONS assert "api" in PERMISSIONS assert appuser.has_perm("api") is True assert appuser.has_perm("something") is False assert "app-label-read" in PERMISSIONS assert appuser.has_module_perms("app-label") is True assert appuser.has_module_perms("app-something") is False def test_django_appuser_admin(appuser_admin): appuser_admin.permissions = NO_PERMISSION assert appuser_admin.get_group_permissions() == NO_PERMISSION assert appuser_admin.get_group_permissions(appuser_admin) == NO_PERMISSION assert appuser_admin.get_all_permissions() == NO_PERMISSION assert appuser_admin.get_all_permissions(appuser) == NO_PERMISSION assert "foobar" not in PERMISSIONS assert appuser_admin.has_perm("foobar") is True assert "something" not in PERMISSIONS assert appuser_admin.has_perm("something") is True assert appuser_admin.has_module_perms("app-label") is True assert appuser_admin.has_module_perms("really-whatever-app") is True diff --git a/swh/auth/tests/test_utils.py b/swh/auth/tests/django/test_utils.py similarity index 100% rename from swh/auth/tests/test_utils.py rename to swh/auth/tests/django/test_utils.py