Skip to content

Commit d7da67c

Browse files
committed
move to single package
1 parent 01fa6de commit d7da67c

File tree

14 files changed

+168
-34
lines changed

14 files changed

+168
-34
lines changed

.github/workflows/runtests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pathlib
44
import sys
55

6+
from django.core.exceptions import ImproperlyConfigured
7+
68
test_apps = [
79
"admin_changelist",
810
"admin_checks",
@@ -157,6 +159,15 @@
157159
]
158160
),
159161
]
162+
163+
try:
164+
from django.contrib.gis.gdal import GDAL_VERSION # noqa: F401
165+
except ImproperlyConfigured:
166+
# GDAL not installed.
167+
pass
168+
else:
169+
test_apps.append("gis_tests")
170+
160171
runtests = pathlib.Path(__file__).parent.resolve() / "runtests.py"
161172
run_tests_cmd = f"python3 {runtests} %s --settings mongodb_settings -v 2"
162173

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Python Tests on Atlas
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.py'
7+
- '!setup.py'
8+
- '.github/workflows/test-python-atlas.yml'
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
defaults:
16+
run:
17+
shell: bash -eux {0}
18+
19+
jobs:
20+
build:
21+
name: Django Test Suite
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout django-mongodb-backend
25+
uses: actions/checkout@v4
26+
with:
27+
persist-credentials: false
28+
- name: install django-mongodb-backend
29+
run: |
30+
pip3 install --upgrade pip
31+
pip3 install -e .
32+
- name: Checkout Django
33+
uses: actions/checkout@v4
34+
with:
35+
repository: 'mongodb-forks/django'
36+
ref: 'mongogis'
37+
path: 'django_repo'
38+
persist-credentials: false
39+
- name: Install system packages for Django's Python test dependencies
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install gdal-bin libmemcached-dev
43+
- name: Install Django and its Python test dependencies
44+
run: |
45+
cd django_repo/tests/
46+
pip3 install -e ..
47+
pip3 install -r requirements/py3.txt
48+
- name: Copy the test settings file
49+
run: cp .github/workflows/mongodb_settings.py django_repo/tests/
50+
- name: Copy the test runner file
51+
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py
52+
- name: Start local Atlas
53+
working-directory: .
54+
run: bash .github/workflows/start_local_atlas.sh mongodb/mongodb-atlas-local:7
55+
- name: Run tests
56+
run: python3 django_repo/tests/runtests.py --settings mongodb_settings -v 2

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Python Tests with GeoDjango
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.py'
7+
- '!setup.py'
8+
- '.github/workflows/test-python.yml'
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
defaults:
16+
run:
17+
shell: bash -eux {0}
18+
19+
jobs:
20+
build:
21+
name: Django Test Suite
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout django-mongodb-backend
25+
uses: actions/checkout@v4
26+
with:
27+
persist-credentials: false
28+
- name: install django-mongodb-backend
29+
run: |
30+
pip3 install --upgrade pip
31+
pip3 install -e .
32+
- name: Checkout Django
33+
uses: actions/checkout@v4
34+
with:
35+
repository: 'mongodb-forks/django'
36+
ref: 'mongogis'
37+
path: 'django_repo'
38+
persist-credentials: false
39+
- name: Install system packages for Django's Python test dependencies
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install gdal-bin libmemcached-dev
43+
- name: Install Django and its Python test dependencies
44+
run: |
45+
cd django_repo/tests/
46+
pip3 install -e ..
47+
pip3 install -r requirements/py3.txt
48+
- name: Copy the test settings file
49+
run: cp .github/workflows/mongodb_settings.py django_repo/tests/
50+
- name: Copy the test runner file
51+
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py
52+
- name: Start MongoDB
53+
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
54+
with:
55+
mongodb-version: 6.0
56+
- name: Run tests
57+
run: python3 django_repo/tests/runtests_.py

django_mongodb_backend/features.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
from django.core.exceptions import ImproperlyConfigured
12
from django.db.backends.base.features import BaseDatabaseFeatures
23
from django.utils.functional import cached_property
34
from pymongo.errors import OperationFailure
45

6+
try:
7+
from .gis.features import GISFeatures
8+
except ImproperlyConfigured:
9+
# GIS libraries not installed
10+
class GISFeatures:
11+
pass
512

6-
class DatabaseFeatures(BaseDatabaseFeatures):
13+
14+
class DatabaseFeatures(GISFeatures, BaseDatabaseFeatures):
715
minimum_database_version = (6, 0)
816
allow_sliced_subqueries_with_in = False
917
allows_multiple_constraints_on_same_fields = False
@@ -135,7 +143,7 @@ def django_test_expected_failures(self):
135143
expected_failures.update(self._django_test_expected_failures_no_transactions)
136144
return expected_failures
137145

138-
django_test_skips = {
146+
_django_test_skips = {
139147
"Database defaults aren't supported by MongoDB.": {
140148
# bson.errors.InvalidDocument: cannot encode object:
141149
# <django.db.models.expressions.DatabaseDefault
@@ -588,6 +596,12 @@ def django_test_expected_failures(self):
588596
},
589597
}
590598

599+
@cached_property
600+
def django_test_skips(self):
601+
skips = super().django_test_skips
602+
skips.update(self._django_test_skips)
603+
return skips
604+
591605
@cached_property
592606
def is_mongodb_6_3(self):
593607
return self.connection.get_database_version() >= (6, 3)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.core.exceptions import ImproperlyConfigured
2+
3+
try:
4+
from .lookups import register_lookups
5+
except ImproperlyConfigured:
6+
# GIS libraries not installed
7+
pass
8+
else:
9+
register_lookups()

django_mongodb_backend_gis/features.py renamed to django_mongodb_backend/gis/features.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
22
from django.utils.functional import cached_property
33

4-
from django_mongodb_backend.features import DatabaseFeatures as MongoFeatures
54

6-
7-
class DatabaseFeatures(BaseSpatialFeatures, MongoFeatures):
5+
class GISFeatures(BaseSpatialFeatures):
86
has_spatialrefsys_table = False
97
supports_transform = False
108

@@ -18,20 +16,16 @@ def django_test_expected_failures(self):
1816
"gis_tests.geoapp.tests.GeoModelTest.test_proxy",
1917
# MongoDB does not support the within lookup
2018
"gis_tests.relatedapp.tests.RelatedGeoModelTest.test06_f_expressions",
19+
"gis_tests.geoapp.tests.GeoModelTest.test_gis_query_as_string",
2120
# 'Adapter' object has no attribute 'srid'
2221
"gis_tests.geoapp.test_expressions.GeoExpressionsTests.test_geometry_value_annotation",
2322
# Object of type ObjectId is not JSON serializable
2423
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_fields_option",
2524
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_geometry_field_option",
2625
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_serialization_base",
2726
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_srid_option",
28-
# KeyError: 'within' connection.ops.gis_operators[self.lookup_name]
29-
"gis_tests.geoapp.tests.GeoModelTest.test_gis_query_as_string",
3027
# No lookups are supported (yet?)
3128
"gis_tests.geoapp.tests.GeoLookupTest.test_gis_lookups_with_complex_expressions",
32-
# Trying to remove spatial index fails:
33-
# "index not found with name [gis_neighborhood_geom_id]"
34-
"gis_tests.gis_migrations.test_operations.OperationTests.test_alter_field_remove_spatial_index",
3529
}
3630
)
3731
return expected_failures
@@ -62,6 +56,10 @@ def django_test_skips(self):
6256
# migrations don't need to call it, so the check doesn't happen.
6357
"gis_tests.gis_migrations.test_operations.NoRasterSupportTests",
6458
},
59+
"MongoDB doesn't support redundant spatial indexes.": {
60+
# Error: Index already exists with a different name
61+
"gis_tests.geoapp.test_indexes.SchemaIndexesTests.test_index_name",
62+
},
6563
},
6664
)
6765
return skips

django_mongodb_backend_gis/operations.py renamed to django_mongodb_backend/gis/operations.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
from django.contrib.gis.db import models
33
from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
44

5-
from django_mongodb_backend.operations import (
6-
DatabaseOperations as MongoOperations,
7-
)
8-
95
from .adapter import Adapter
106

117

12-
class DatabaseOperations(BaseSpatialOperations, MongoOperations):
8+
class GISOperations(BaseSpatialOperations):
139
Adapter = Adapter
1410

1511
disallowed_aggregates = (

django_mongodb_backend_gis/schema.py renamed to django_mongodb_backend/gis/schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from pymongo import GEOSPHERE
22
from pymongo.operations import IndexModel
33

4-
from django_mongodb_backend.schema import DatabaseSchemaEditor as BaseSchemaEditor
54

6-
7-
class DatabaseSchemaEditor(BaseSchemaEditor):
5+
class GISSchemaEditor:
86
def _field_should_be_indexed(self, model, field):
97
if getattr(field, "spatial_index", False):
108
return True

0 commit comments

Comments
 (0)