Example #1
0
 def test_default_object_id(self):
     """
     Test :py:meth:`.MongoengineEncoder.default` ``ObjectId`` object.
     """
     obj = Mock()
     encoder = MongoengineEncoder()
     self.assertEqual(unicode(obj), encoder.default(obj))
Example #2
0
 def test_default_object_id(self):
     """
     Test :py:meth:`.MongoengineEncoder.default` ``ObjectId`` object.
     """
     obj = Mock()
     encoder = MongoengineEncoder()
     self.assertEqual(unicode(obj), encoder.default(obj))
Example #3
0
    def test_default_default_fallback(self, json):
        """
        Test :py:meth:`.MongoengineEncoder.default` with default fallback.
        """
        json.JSONEncoder.default.return_value = 'default-fallback'

        obj = Mock()
        encoder = MongoengineEncoder()
        self.assertEqual('default-fallback', encoder.default(obj))
        json.JSONEncoder.default.assert_called_once_with(encoder, obj)
Example #4
0
    def test_default_default_fallback(self, json):
        """
        Test :py:meth:`.MongoengineEncoder.default` with default fallback.
        """
        json.JSONEncoder.default.return_value = 'default-fallback'

        obj = Mock()
        encoder = MongoengineEncoder()
        self.assertEqual('default-fallback', encoder.default(obj))
        json.JSONEncoder.default.assert_called_once_with(encoder, obj)
Example #5
0
    def test_default_iter(self):
        """
        Test :py:meth:`.MongoengineEncoder.default` with iterable.
        """
        class DummyIter(dict):
            def __getattr__(self, name):
                return self[name]

        encoder = MongoengineEncoder()
        dummy_iter = DummyIter({'foo': 'bar'})
        self.assertEqual({'foo': 'bar'}, encoder.default(dummy_iter))
Example #6
0
    def test_default_iter(self):
        """
        Test :py:meth:`.MongoengineEncoder.default` with iterable.
        """
        class DummyIter(dict):
            def __getattr__(self, name):
                return self[name]

        encoder = MongoengineEncoder()
        dummy_iter = DummyIter({'foo': 'bar'})
        self.assertEqual({'foo': 'bar'}, encoder.default(dummy_iter))