Skip to content

Commit

Permalink
fix: operator rename
Browse files Browse the repository at this point in the history
  • Loading branch information
gersmann committed Jan 21, 2024
1 parent 700b6ce commit fb4cd97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class MongoRelatedIn(MongoIn):
class MongoEqualityComparison(MongoLookup):
"""MongoDB Query Node for LessThanOrEqual"""

operator: str
filter_operator: str

def __init__(
self, operator: LessThan | LessThanOrEqual | GreaterThan | GreaterThanOrEqual, mongo_meta
):
super().__init__(operator, mongo_meta)
self.operator = {
self.filter_operator = {
LessThan: "$lt",
LessThanOrEqual: "$lte",
GreaterThan: "$gt",
Expand Down
13 changes: 13 additions & 0 deletions test/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
import os
import time
from datetime import timedelta

import pytest
from bson import ObjectId
from django.contrib.postgres.search import SearchQuery, SearchVector
from django.utils.timezone import now

from refapp.models import RefModel
from testapp.models import (
Expand Down Expand Up @@ -61,6 +63,17 @@ def test_mongo_emtpy():
assert len(list(FooModel.objects.none())) == 0


@pytest.mark.django_db(databases=["mongodb"])
def test_mongo_lookup():
FooModel.objects.all().delete()

FooModel.objects.create(name="test", json_field={"foo": "bar"})
FooModel.objects.create(name="test2", json_field={"foo": "bar"})

assert len(list(FooModel.objects.filter(datetime_field__gt=now() - timedelta(hours=1)))) == 2
assert len(list(FooModel.objects.filter(name="test"))) == 1


@pytest.mark.django_db(databases=["mongodb"])
def test_mongo_model_filter_delete():
FooModel.objects.all().delete()
Expand Down

0 comments on commit fb4cd97

Please sign in to comment.