diff --git a/.gitignore b/.gitignore index 075ae0b..e3651d1 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ uv.lock docs/_build/ config/wagtail/wagtail_settings.py customer-master-key.txt +mongocryptd.pid diff --git a/config/allauth/allauth_settings.py b/config/allauth/allauth_settings.py index f83e805..de853a7 100644 --- a/config/allauth/allauth_settings.py +++ b/config/allauth/allauth_settings.py @@ -3,10 +3,11 @@ from django.contrib.auth.hashers import PBKDF2PasswordHasher -from django_mongodb_cli.utils import get_databases +import os +import django_mongodb_backend - -DATABASES = get_databases("allauth") +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} SECRET_KEY = "psst" SITE_ID = ObjectId() diff --git a/config/debug_toolbar/debug_toolbar_settings.py b/config/debug_toolbar/debug_toolbar_settings.py index 9fe7add..0f8c94f 100644 --- a/config/debug_toolbar/debug_toolbar_settings.py +++ b/config/debug_toolbar/debug_toolbar_settings.py @@ -1,10 +1,10 @@ """Django settings for tests.""" import os -from django_mongodb_cli.utils import get_databases +import django_mongodb_backend - -DATABASES = get_databases("debug_toolbar") +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} BASE_DIR = os.path.dirname(os.path.dirname(__file__)) diff --git a/config/django/django_settings.py b/config/django/django_settings.py index da7c830..0ac47c9 100644 --- a/config/django/django_settings.py +++ b/config/django/django_settings.py @@ -1,7 +1,22 @@ -from django_mongodb_cli.utils import get_databases +import os +import django_mongodb_backend +kms_providers = django_mongodb_backend.get_kms_providers() -DATABASES = get_databases("django") +HOME = os.environ.get("HOME") + +auto_encryption_opts = django_mongodb_backend.get_auto_encryption_opts( + kms_providers=kms_providers, + crypt_shared_lib_path=f"{HOME}/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib", +) + +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = { + "default": django_mongodb_backend.parse_uri(DATABASE_URL), + "encryption": django_mongodb_backend.parse_uri( + DATABASE_URL, options={"auto_encryption_opts": auto_encryption_opts} + ), +} DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField" PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) diff --git a/config/extensions/debug_toolbar_settings.py b/config/extensions/debug_toolbar_settings.py index 09d1245..d1be000 100644 --- a/config/extensions/debug_toolbar_settings.py +++ b/config/extensions/debug_toolbar_settings.py @@ -1,10 +1,10 @@ """Django settings for tests.""" import os -from django_mongodb_cli.utils import get_databases +import django_mongodb_backend - -DATABASES = get_databases("debug_toolbar") +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} BASE_DIR = os.path.dirname(os.path.dirname(__file__)) diff --git a/config/filter/filter_settings.py b/config/filter/filter_settings.py index 236e819..81bb0b0 100644 --- a/config/filter/filter_settings.py +++ b/config/filter/filter_settings.py @@ -1,12 +1,11 @@ # ensure package/conf is importable from django_filters.conf import DEFAULTS +import os +import django_mongodb_backend -from django_mongodb_cli.utils import get_databases - - -DATABASES = get_databases("django_filter") - +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} INSTALLED_APPS = ( "tests.mongo_apps.MongoContentTypesConfig", diff --git a/config/rest_framework/rest_framework_settings.py b/config/rest_framework/rest_framework_settings.py index 3c27fbc..93baf61 100644 --- a/config/rest_framework/rest_framework_settings.py +++ b/config/rest_framework/rest_framework_settings.py @@ -4,7 +4,10 @@ from bson import ObjectId from django.core import management -from django_mongodb_cli.utils import get_databases +import django_mongodb_backend + +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} def pytest_addoption(parser): @@ -22,7 +25,7 @@ def pytest_configure(config): settings.configure( DEBUG_PROPAGATE_EXCEPTIONS=True, - DATABASES=get_databases("rest_framework"), + DATABASES=DATABASES, SITE_ID=ObjectId("000000000000000000000001"), SECRET_KEY="not very secret in tests", USE_I18N=True, diff --git a/config/wagtail/wagtail_settings.py b/config/wagtail/wagtail_settings.py index c58a386..372c427 100644 --- a/config/wagtail/wagtail_settings.py +++ b/config/wagtail/wagtail_settings.py @@ -6,7 +6,9 @@ from django.utils.translation import gettext_lazy as _ from wagtail.test.numberformat import patch_number_formats -from django_mongodb_cli.utils import get_databases + +DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests") +DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} WAGTAIL_CHECK_TEMPLATE_NUMBER_FORMAT = ( os.environ.get("WAGTAIL_CHECK_TEMPLATE_NUMBER_FORMAT", "0") == "1" @@ -25,8 +27,6 @@ TIME_ZONE = "Asia/Tokyo" -DATABASES = get_databases("wagtail") - SECRET_KEY = "not needed" ROOT_URLCONF = "wagtail.test.urls" diff --git a/django_mongodb_cli/utils.py b/django_mongodb_cli/utils.py index c53a7cf..1a1908e 100644 --- a/django_mongodb_cli/utils.py +++ b/django_mongodb_cli/utils.py @@ -79,17 +79,6 @@ def get_management_command(command=None): return base_command -def get_databases(app): - """Get the databases configuration for the specified app.""" - import django_mongodb_backend - - DATABASE_URL = os.environ.get( - "MONGODB_URI", f"mongodb://localhost:27017/{app}_tests" - ) - DATABASES = {"default": django_mongodb_backend.parse_uri(DATABASE_URL)} - return DATABASES - - def get_repos(pyproject_path): with open(pyproject_path, "r") as f: pyproject_data = toml.load(f) diff --git a/justfile b/justfile index 3ef5944..53a6fd3 100644 --- a/justfile +++ b/justfile @@ -1,24 +1,13 @@ default: echo 'Hello, world!' -install: pip-install git-clone dev-install +install: pip-install git-clone repo-install alias i := install -dev-install: +repo-install: dm repo install django dm repo install django-mongodb-backend - dm repo install django-mongodb-extensions dm repo install mongo-python-driver - dm repo install python-xmlsec - dm repo install libmongocrypt - - -demo: - dm repo test django queries_ - dm repo test django-filter tests.test_filters - dm repo test django-debug-toolbar - dm repo test django-allauth allauth/account/tests -alias d := demo # ---------------------------------------- git ---------------------------------------- @@ -31,10 +20,7 @@ git-clone: dm repo clone django-mongodb-extensions dm repo clone django-mongodb-project dm repo clone django-mongodb-templates - dm repo clone django-rest-framework - dm repo clone libmongocrypt dm repo clone mongo-python-driver - dm repo clone python-xmlsec # ---------------------------------------- django ---------------------------------------- @@ -111,6 +97,7 @@ sphinx-clean: alias sc := sphinx-clean # ---------------------------------------- qe ---------------------------------------- + qe: python qe.py alias q := qe diff --git a/pyproject.toml b/pyproject.toml index 298bf19..1eed2f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "python3-openid", # For django-allauth "python3-saml", # For django-allauth "pyjwt[crypto]", # For django-allauth + "pymongocrypt", # For django-mongodb-backend QE "pytest", "pytest-html", "pytest-django", # For django-rest-framework and django-debug-toolbar