File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 11from bson import ObjectId
2+ from django .core import exceptions
23from django .test import SimpleTestCase
34
45from django_mongodb .fields import ObjectIdField
@@ -19,5 +20,15 @@ def test_get_internal_type(self):
1920 def test_to_python (self ):
2021 f = ObjectIdField ()
2122 expected = ObjectId ("1" * 24 )
22- self .assertEqual (f .to_python ("1" * 24 ), expected )
23- self .assertEqual (f .to_python (expected ), expected )
23+ for value in ["1" * 24 , ObjectId ("1" * 24 )]:
24+ with self .subTest (value = value ):
25+ self .assertEqual (f .to_python (value ), expected )
26+ with self .subTest (value = None ):
27+ self .assertIsNone (f .to_python (None ))
28+
29+ def test_to_python_invalid_value (self ):
30+ for invalid_value in [3 , "None" , {}, []]:
31+ with self .subTest (invalid_value = invalid_value ):
32+ msg = f"['“{ invalid_value } ” value must be an Object Id.']"
33+ with self .assertRaisesMessage (exceptions .ValidationError , msg ):
34+ ObjectIdField ().to_python (invalid_value )
You can’t perform that action at this time.
0 commit comments