Skip to content

Commit 252f364

Browse files
committed
edits
1 parent 0d6f719 commit 252f364

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/checkout@v4
3434
with:
3535
repository: 'mongodb-forks/django'
36-
ref: 'mongodb-5.1.x'
36+
ref: 'mongodb-5.2.x'
3737
path: 'django_repo'
3838
persist-credentials: false
3939
- name: Install system packages for Django's Python test dependencies

tests/indexes_/models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class Data(EmbeddedModel):
1515

1616

1717
class SearchIndexTestModel(models.Model):
18-
text = models.CharField(max_length=100)
19-
object_id = ObjectIdField()
20-
number = models.IntegerField()
18+
boolean = models.BooleanField()
19+
date = models.DateTimeField(auto_now=True)
2120
embedded = EmbeddedModelField(Data)
21+
float = models.FloatField()
2222
json_data = models.JSONField()
23-
vector_integer = ArrayField(models.IntegerField(), size=10)
23+
number = models.IntegerField()
24+
object_id = ObjectIdField()
25+
text = models.CharField(max_length=100)
2426
vector_float = ArrayField(models.FloatField(), size=10)
25-
boolean = models.BooleanField()
26-
date = models.DateTimeField(auto_now=True)
27+
vector_integer = ArrayField(models.IntegerField(), size=10)

tests/indexes_/test_search_indexes.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
from unittest import mock
2+
13
from django.db import connection
2-
from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature
4+
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
35

46
from django_mongodb_backend.indexes import SearchIndex, VectorSearchIndex
57

68
from .models import SearchIndexTestModel
79
from .test_base import SchemaAssertionMixin
810

911

10-
@skipIfDBFeature("supports_atlas_search")
12+
@mock.patch.object(connection.features, "supports_atlas_search", False)
1113
class UnsupportedSearchIndexesTests(TestCase):
1214
def test_search_index_not_created(self):
1315
with connection.schema_editor() as editor:
@@ -37,7 +39,7 @@ def test_vector_index_not_created(self):
3739

3840

3941
class VectorSearchIndexTests(SimpleTestCase):
40-
def test_deconstruct_default_similarity(self):
42+
def test_deconstruct(self):
4143
index = VectorSearchIndex(name="recent_test_idx", fields=["number"])
4244
name, args, kwargs = index.deconstruct()
4345
new = VectorSearchIndex(*args, **kwargs)
@@ -87,21 +89,23 @@ def test_simple(self):
8789
name="recent_test_idx",
8890
fields=["text"],
8991
)
90-
self.assertAddRemoveIndex(index=index, model=SearchIndexTestModel)
92+
with connection.schema_editor() as editor:
93+
self.assertAddRemoveIndex(editor, index=index, model=SearchIndexTestModel)
9194

9295
def test_all_fields(self):
9396
index = SearchIndex(
9497
name="recent_test_idx",
9598
fields=[
96-
"text",
97-
"object_id",
98-
"number",
99+
"boolean",
100+
"date",
99101
"embedded",
102+
"float",
100103
"json_data",
104+
"number",
105+
"object_id",
106+
"text",
101107
"vector_integer",
102108
"vector_float",
103-
"boolean",
104-
"date",
105109
],
106110
)
107111
with connection.schema_editor() as editor:
@@ -115,7 +119,14 @@ def test_all_fields(self):
115119
"dynamic": False,
116120
"fields": {
117121
"boolean": {"type": "boolean"},
122+
"date": {"type": "date"},
118123
"embedded": {"dynamic": False, "fields": {}, "type": "embeddedDocuments"},
124+
"float": {
125+
"indexDoubles": True,
126+
"indexIntegers": True,
127+
"representation": "double",
128+
"type": "number",
129+
},
119130
"json_data": {"dynamic": False, "fields": {}, "type": "document"},
120131
"number": {
121132
"indexDoubles": True,
@@ -130,7 +141,6 @@ def test_all_fields(self):
130141
"store": True,
131142
"type": "string",
132143
},
133-
"date": {"type": "date"},
134144
"vector_float": {"dynamic": False, "fields": {}, "type": "embeddedDocuments"},
135145
"vector_integer": {"dynamic": False, "fields": {}, "type": "embeddedDocuments"},
136146
},
@@ -144,9 +154,10 @@ def test_all_fields(self):
144154

145155
@skipUnlessDBFeature("supports_atlas_search")
146156
class VectorSearchIndexSchemaTests(SchemaAssertionMixin, TestCase):
147-
def test_simple_vector_search(self):
157+
def test_simple(self):
148158
index = VectorSearchIndex(name="recent_test_idx", fields=["number"])
149-
self.assertAddRemoveIndex(index=index, model=SearchIndexTestModel)
159+
with connection.schema_editor() as editor:
160+
self.assertAddRemoveIndex(editor, index=index, model=SearchIndexTestModel)
150161

151162
def test_multiple_fields(self):
152163
index = VectorSearchIndex(

0 commit comments

Comments
 (0)