Skip to content

Misc updates #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ uv.lock
docs/_build/
config/wagtail/wagtail_settings.py
customer-master-key.txt
mongocryptd.pid
7 changes: 4 additions & 3 deletions config/allauth/allauth_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions config/debug_toolbar/debug_toolbar_settings.py
Original file line number Diff line number Diff line change
@@ -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__))

Expand Down
19 changes: 17 additions & 2 deletions config/django/django_settings.py
Original file line number Diff line number Diff line change
@@ -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",)
Expand Down
6 changes: 3 additions & 3 deletions config/extensions/debug_toolbar_settings.py
Original file line number Diff line number Diff line change
@@ -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__))

Expand Down
9 changes: 4 additions & 5 deletions config/filter/filter_settings.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions config/rest_framework/rest_framework_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions config/wagtail/wagtail_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,8 +27,6 @@

TIME_ZONE = "Asia/Tokyo"

DATABASES = get_databases("wagtail")

SECRET_KEY = "not needed"

ROOT_URLCONF = "wagtail.test.urls"
Expand Down
11 changes: 0 additions & 11 deletions django_mongodb_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 3 additions & 16 deletions justfile
Original file line number Diff line number Diff line change
@@ -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 ----------------------------------------

Expand All @@ -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 ----------------------------------------

Expand Down Expand Up @@ -111,6 +97,7 @@ sphinx-clean:
alias sc := sphinx-clean

# ---------------------------------------- qe ----------------------------------------

qe:
python qe.py
alias q := qe
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down