It works if I call insure_indexes() method. I can't understand why. Is 
there to avoid it ?

My code that works :

>
> from django.test import TestCase
> from les_classiques.models import Author
> import mongoengine
>
>
> class DatabaseTest(TestCase):
>     def setUp(self):
>         db = mongoengine.connection.get_db()
>         for collection in 
> db.collection_names(include_system_collections=False):
>             db.drop_collection(collection)
>
>     def test_insert_new_author(self):
>         author = Author(name='Hugo', first_name='Victor')
>         author.save()
>         db_author = Author.objects(name='Hugo', first_name='Victor')[0]
>         self.assertEqual(db_author.name, 'Hugo')
>
>     def test_insert_duplicate_author_failure(self):
>
          Author.insure_indexes()

>         author = Author(name='Peguy', first_name='Charles')
>         author2 = Author(name='Peguy', first_name='Charles')
>         author.save()
>         self.assertRaises(mongoengine.NotUniqueError, author2.save)
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/516c3bc1-fa7a-45e4-8041-8880aa24aeee%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to