tests.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #coding: utf-8
  2. from nose.plugins.skip import SkipTest
  3. from mongoengine.python_support import PY3
  4. from mongoengine import connect
  5. try:
  6. from django.test import TestCase
  7. from django.conf import settings
  8. except Exception as err:
  9. if PY3:
  10. from unittest import TestCase
  11. # Dummy value so no error
  12. class settings:
  13. MONGO_DATABASE_NAME = 'dummy'
  14. else:
  15. raise err
  16. class MongoTestCase(TestCase):
  17. def setUp(self):
  18. if PY3:
  19. raise SkipTest('django does not have Python 3 support')
  20. """
  21. TestCase class that clear the collection between the tests
  22. """
  23. db_name = 'test_%s' % settings.MONGO_DATABASE_NAME
  24. def __init__(self, methodName='runtest'):
  25. self.db = connect(self.db_name).get_db()
  26. super(MongoTestCase, self).__init__(methodName)
  27. def _post_teardown(self):
  28. super(MongoTestCase, self)._post_teardown()
  29. for collection in self.db.collection_names():
  30. if collection == 'system.indexes':
  31. continue
  32. self.db.drop_collection(collection)