From 057051815f9dcada8da69ca6282ea5eeed9e8181 Mon Sep 17 00:00:00 2001 From: Emanuel Lupi Date: Mon, 18 Nov 2024 20:01:47 -0300 Subject: [PATCH] Add ObjectIdField unit tests. --- tests/model_fields_/test_objectidfield.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/model_fields_/test_objectidfield.py diff --git a/tests/model_fields_/test_objectidfield.py b/tests/model_fields_/test_objectidfield.py new file mode 100644 index 00000000..46c8566d --- /dev/null +++ b/tests/model_fields_/test_objectidfield.py @@ -0,0 +1,23 @@ +from bson import ObjectId +from django.test import SimpleTestCase + +from django_mongodb.fields import ObjectIdField + + +class MethodTests(SimpleTestCase): + def test_deconstruct(self): + field = ObjectIdField() + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django_mongodb.fields.ObjectIdField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {}) + + def test_get_internal_type(self): + f = ObjectIdField() + self.assertEqual(f.get_internal_type(), "ObjectIdField") + + def test_to_python(self): + f = ObjectIdField() + expected = ObjectId("1" * 24) + self.assertEqual(f.to_python("1" * 24), expected) + self.assertEqual(f.to_python(expected), expected)