Skip to content

Commit 8e211b7

Browse files
authored
Merge branch 'main' into PYTHON-5579
2 parents f5bc796 + a53d9a2 commit 8e211b7

35 files changed

+685
-401
lines changed

.evergreen/run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pip install -e ..
1515
pip install -r requirements/py3.txt
1616
popd
1717

18-
# Copy the test settings file
19-
cp ./.github/workflows/mongodb_settings.py django_repo/tests/
18+
# Copy the test settings files
19+
cp ./.github/workflows/*_settings.py django_repo/tests/
2020

2121
# Copy the test runner file
2222
cp ./.github/workflows/runtests.py django_repo/tests/runtests_.py

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656

5757
# Initializes the CodeQL tools for scanning.
5858
- name: Initialize CodeQL
59-
uses: github/codeql-action/init@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
59+
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
6060
with:
6161
languages: ${{ matrix.language }}
6262
build-mode: none
@@ -72,6 +72,6 @@ jobs:
7272
pip install -e .
7373
7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
75+
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
7676
with:
7777
category: "/language:${{ matrix.language }}"

.github/workflows/dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Create packages
3333
run: python -m build .
3434
- name: Store package artifacts
35-
uses: actions/upload-artifact@v4
35+
uses: actions/upload-artifact@v5
3636
with:
3737
name: all-dist-${{ github.run_id }}
3838
path: "dist/*"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Settings for django/tests.
2+
import os
3+
4+
from pymongo.uri_parser import parse_uri
5+
6+
if mongodb_uri := os.getenv("MONGODB_URI"):
7+
db_settings = {
8+
"ENGINE": "django_mongodb_backend",
9+
"HOST": mongodb_uri,
10+
}
11+
# Workaround for https://github.com/mongodb-labs/mongo-orchestration/issues/268
12+
uri = parse_uri(mongodb_uri)
13+
if uri.get("username") and uri.get("password"):
14+
db_settings["OPTIONS"] = {"tls": True, "tlsAllowInvalidCertificates": True}
15+
DATABASES = {
16+
"default": {**db_settings, "NAME": "djangotests"},
17+
"other": {**db_settings, "NAME": "djangotests-other"},
18+
}
19+
else:
20+
DATABASES = {
21+
"default": {
22+
"ENGINE": "django_mongodb_backend",
23+
"NAME": "djangotests",
24+
# Required when connecting to the Atlas image in Docker.
25+
"OPTIONS": {"directConnection": True},
26+
},
27+
"other": {
28+
"ENGINE": "django_mongodb_backend",
29+
"NAME": "djangotests-other",
30+
"OPTIONS": {"directConnection": True},
31+
},
32+
}
33+
34+
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
35+
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
36+
SECRET_KEY = "django_tests_secret_key" # noqa: S105
37+
USE_TZ = False
Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
1-
import os
1+
# Settings for django_mongodb_backend/tests.
2+
from django_settings import * # noqa: F403
23

3-
from pymongo.uri_parser import parse_uri
4-
5-
if mongodb_uri := os.getenv("MONGODB_URI"):
6-
db_settings = {
7-
"ENGINE": "django_mongodb_backend",
8-
"HOST": mongodb_uri,
9-
}
10-
# Workaround for https://github.com/mongodb-labs/mongo-orchestration/issues/268
11-
uri = parse_uri(mongodb_uri)
12-
if uri.get("username") and uri.get("password"):
13-
db_settings["OPTIONS"] = {"tls": True, "tlsAllowInvalidCertificates": True}
14-
DATABASES = {
15-
"default": {**db_settings, "NAME": "djangotests"},
16-
"other": {**db_settings, "NAME": "djangotests-other"},
17-
}
18-
else:
19-
DATABASES = {
20-
"default": {
21-
"ENGINE": "django_mongodb_backend",
22-
"NAME": "djangotests",
23-
# Required when connecting to the Atlas image in Docker.
24-
"OPTIONS": {"directConnection": True},
25-
},
26-
"other": {
27-
"ENGINE": "django_mongodb_backend",
28-
"NAME": "djangotests-other",
29-
"OPTIONS": {"directConnection": True},
30-
},
31-
}
32-
33-
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
34-
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
35-
SECRET_KEY = "django_tests_secret_key"
36-
USE_TZ = False
4+
DATABASE_ROUTERS = ["django_mongodb_backend.routers.MongoRouter"]

.github/workflows/release-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
id-token: write
7676
steps:
7777
- name: Download all the dists
78-
uses: actions/download-artifact@v5
78+
uses: actions/download-artifact@v6
7979
with:
8080
name: all-dist-${{ github.run_id }}
8181
path: dist/

.github/workflows/runtests.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,19 @@
171171
test_apps.extend(["gis_tests", "gis_tests_"])
172172

173173
runtests = pathlib.Path(__file__).parent.resolve() / "runtests.py"
174-
run_tests_cmd = f"python3 {runtests} %s --settings mongodb_settings -v 2"
174+
run_tests_cmd = f"python3 {runtests} %s --settings %s -v 2"
175175

176176
shouldFail = False
177177
for app_name in test_apps:
178-
res = os.system(run_tests_cmd % app_name) # noqa: S605
178+
# Use the custom settings module only for django_mongodb_backend's tests
179+
# (which always end with an underscore). Some of Django's tests aren't
180+
# compatible with extra DATABASE_ROUTERS or other DATABASES aliases.
181+
settings_module = (
182+
os.environ.get("DJANGO_SETTINGS_MODULE", "mongodb_settings")
183+
if app_name.endswith("_")
184+
else "django_settings"
185+
)
186+
res = os.system(run_tests_cmd % (app_name, settings_module)) # noqa: S605
179187
if res != 0:
180188
shouldFail = True
181189
sys.exit(1 if shouldFail else 0)

.github/workflows/test-python-atlas.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
cd django_repo/tests/
4646
pip3 install -e ..
4747
pip3 install -r requirements/py3.txt
48-
- name: Copy the test settings file
49-
run: cp .github/workflows/mongodb_settings.py django_repo/tests/
48+
- name: Copy the test settings files
49+
run: cp .github/workflows/*_settings.py django_repo/tests/
5050
- name: Copy the test runner file
5151
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py
5252
- name: Start local Atlas

.github/workflows/test-python-geo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
cd django_repo/tests/
4747
pip3 install -e ..
4848
pip3 install -r requirements/py3.txt
49-
- name: Copy the test settings file
50-
run: cp .github/workflows/mongodb_settings.py django_repo/tests/
49+
- name: Copy the test settings files
50+
run: cp .github/workflows/*_settings.py django_repo/tests/
5151
- name: Copy the test runner file
5252
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py
5353
- name: Start MongoDB

.github/workflows/test-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
cd django_repo/tests/
4646
pip3 install -e ..
4747
pip3 install -r requirements/py3.txt
48-
- name: Copy the test settings file
49-
run: cp .github/workflows/mongodb_settings.py django_repo/tests/
48+
- name: Copy the test settings files
49+
run: cp .github/workflows/*_settings.py django_repo/tests/
5050
- name: Copy the test runner file
5151
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py
5252
- name: Start MongoDB

0 commit comments

Comments
 (0)