Ejemplo n.º 1
0
 def test_raise_error_if_wrong_connection_used(self):
     with patch("djmongo.document.is_mongodb_connection") as m:
         m.return_value = False
         with self.assertRaises(ImproperlyConfigured):
             manager = Manager()
             manager.document = Mock()
             manager.document._meta.using = "default"
             manager.connection
Ejemplo n.º 2
0
    def test_get_indexes(self):

        mocked_collection =  Mock()
        mocked_collection.index_information = Mock(return_value={
            u'_id_': {u'key': [(u'_id', 1)], u'v': 1},
            u'titles_-1': {u'key': [(u'titles', -1)], u'v': 1},
            u'titles_-1_val_1': {u'key': [(u'titles', -1), (u'val', 1)], u'v': 1},
            u'titles_1': {u'key': [(u'titles', 1)], u'v': 1},
            u'val_1': {u'key': [(u'val', 1)], u'unique': True, u'v': 1},
        })

        manager = Manager()
        manager._get_collection = Mock(return_value=mocked_collection)
        expected = [
            Index('titles'),
            Index('_id'),
            Index('val', unique=True),
            Index([('titles', Index.DESCENDING), ('val', Index.ASCENDING)]),
            Index([('titles', Index.DESCENDING)]),
        ]
        self.assertEqual(sorted(manager.get_indexes()), sorted(expected))