-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import datetime | ||
import uuid | ||
from decimal import Decimal | ||
|
||
from bson import Decimal128 | ||
from django.db.models import Value | ||
from django.test import SimpleTestCase | ||
|
||
|
||
class ValueTests(SimpleTestCase): | ||
def test_date(self): | ||
self.assertEqual( | ||
Value(datetime.date(2025, 1, 1)).as_mql(None, None), | ||
{"$literal": datetime.datetime(2025, 1, 1)}, | ||
) | ||
|
||
def test_datetime(self): | ||
self.assertEqual( | ||
Value(datetime.datetime(2025, 1, 1, 9, 8, 7)).as_mql(None, None), | ||
{"$literal": datetime.datetime(2025, 1, 1)}, | ||
) | ||
|
||
def test_decimal(self): | ||
self.assertEqual(Value(Decimal("1.0")).as_mql(None, None), {"$literal": Decimal128("1.0")}) | ||
|
||
def test_time(self): | ||
self.assertEqual( | ||
Value(datetime.time(9, 8, 7)).as_mql(None, None), | ||
{"$literal": datetime.datetime(1, 1, 1, 9, 8, 7)}, | ||
) | ||
|
||
def test_timedelta(self): | ||
self.assertEqual( | ||
Value(datetime.timedelta(3600)).as_mql(None, None), {"$literal": 311040000000.0} | ||
) | ||
|
||
def test_int(self): | ||
self.assertEqual(Value(1).as_mql(None, None), {"$literal": 1}) | ||
|
||
def test_str(self): | ||
self.assertEqual(Value("foo").as_mql(None, None), {"$literal": "foo"}) | ||
|
||
def test_uuid(self): | ||
value = uuid.UUID(int=1) | ||
self.assertEqual( | ||
Value(value).as_mql(None, None), {"$literal": "00000000000000000000000000000001"} | ||
) |