2013-12-11 20:44:27 +00:00
|
|
|
from django.apps.cache import get_app
|
2011-09-22 21:09:00 +00:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2010-09-12 20:05:07 +00:00
|
|
|
from django.test import TestCase
|
2011-09-22 21:09:00 +00:00
|
|
|
from django.test.utils import override_settings
|
2012-09-07 17:17:09 +00:00
|
|
|
from django.utils import six
|
2010-09-12 20:05:07 +00:00
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
from .models import Empty
|
2010-09-12 20:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EmptyModelTests(TestCase):
|
|
|
|
def test_empty(self):
|
|
|
|
m = Empty()
|
|
|
|
self.assertEqual(m.id, None)
|
|
|
|
m.save()
|
2012-09-07 17:17:09 +00:00
|
|
|
Empty.objects.create()
|
2010-09-12 20:05:07 +00:00
|
|
|
self.assertEqual(len(Empty.objects.all()), 2)
|
|
|
|
self.assertTrue(m.id is not None)
|
|
|
|
existing = Empty(m.id)
|
|
|
|
existing.save()
|
2011-09-22 21:09:00 +00:00
|
|
|
|
2012-09-07 17:17:09 +00:00
|
|
|
|
2011-09-22 21:09:00 +00:00
|
|
|
class NoModelTests(TestCase):
|
|
|
|
"""
|
|
|
|
Test for #7198 to ensure that the proper error message is raised
|
|
|
|
when attempting to load an app with no models.py file.
|
|
|
|
|
2011-09-22 23:30:05 +00:00
|
|
|
Because the test runner won't currently load a test module with no
|
2011-09-22 21:09:00 +00:00
|
|
|
models.py file, this TestCase instead lives in this module.
|
|
|
|
|
|
|
|
It seemed like an appropriate home for it.
|
|
|
|
"""
|
2013-02-26 12:19:18 +00:00
|
|
|
@override_settings(INSTALLED_APPS=("empty.no_models",))
|
2011-09-22 21:09:00 +00:00
|
|
|
def test_no_models(self):
|
2012-09-07 17:17:09 +00:00
|
|
|
with six.assertRaisesRegex(self, ImproperlyConfigured,
|
2011-09-22 21:09:00 +00:00
|
|
|
'App with label no_models is missing a models.py module.'):
|
|
|
|
get_app('no_models')
|