示例#1
0
文件: tests.py 项目: kmalloc/django
 def test_table_exists(self):
     with app_cache._with_app('app1'), app_cache._with_app('app2'):
         call_command('migrate', verbosity=0)
         from .app1.models import ProxyModel
         from .app2.models import NiceModel
         self.assertEqual(NiceModel.objects.all().count(), 0)
         self.assertEqual(ProxyModel.objects.all().count(), 0)
示例#2
0
 def testI18NDifferentNonEnLangs(self):
     """
     Similar to above but with neither default or requested language being
     English.
     """
     with app_cache._with_app('view_tests.app3'), app_cache._with_app('view_tests.app4'):
         with self.settings(LANGUAGE_CODE='fr'), override('es-ar'):
             response = self.client.get('/views/jsi18n_multi_packages2/')
             self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
示例#3
0
 def testI18NLanguageEnglishDefault(self):
     """
     Check if the JavaScript i18n view returns a complete language catalog
     if the default language is en-us, the selected language has a
     translation available and a catalog composed by djangojs domain
     translations of multiple Python packages is requested. See #13388,
     #3594 and #13514 for more details.
     """
     with app_cache._with_app('view_tests.app1'), app_cache._with_app('view_tests.app2'):
         with self.settings(LANGUAGE_CODE='en-us'), override('fr'):
             response = self.client.get('/views/jsi18n_multi_packages1/')
             self.assertContains(response, javascript_quote('il faut traduire cette chaîne de caractères de app1'))
示例#4
0
 def test_existing(self):
     "A template can be loaded from an egg"
     with app_cache._with_app('egg_1'):
         egg_loader = EggLoader()
         contents, template_name = egg_loader.load_template_source("y.html")
         self.assertEqual(contents, "y")
         self.assertEqual(template_name, "egg:egg_1:templates/y.html")
示例#5
0
文件: tests.py 项目: kmalloc/django
 def test_egg5(self):
     """Loading an app from an egg that has an import error in its models module raises that error"""
     egg_name = '%s/brokenapp.egg' % self.egg_dir
     sys.path.append(egg_name)
     with six.assertRaisesRegex(self, ImportError, 'modelz'):
         with app_cache._with_app('broken_app'):
             app_cache.get_app_config('omelet.app_no_models').models_module
示例#6
0
文件: tests.py 项目: kmalloc/django
 def test_egg4(self):
     """Loading an app with no models from under the top-level egg package generates no error"""
     egg_name = '%s/omelet.egg' % self.egg_dir
     sys.path.append(egg_name)
     with app_cache._with_app('omelet.app_no_models'):
         models_module = app_cache.get_app_config('app_no_models').models_module
         self.assertIsNone(models_module)
示例#7
0
文件: tests.py 项目: kmalloc/django
 def test_egg3(self):
     """Models module can be loaded from an app located under an egg's top-level package"""
     egg_name = '%s/omelet.egg' % self.egg_dir
     sys.path.append(egg_name)
     with app_cache._with_app('omelet.app_with_models'):
         models_module = app_cache.get_app_config('app_with_models').models_module
         self.assertIsNotNone(models_module)
示例#8
0
文件: tests.py 项目: kmalloc/django
 def test_egg2(self):
     """Loading an app from an egg that has no models returns no models (and no error)"""
     egg_name = '%s/nomodelapp.egg' % self.egg_dir
     sys.path.append(egg_name)
     with app_cache._with_app('app_no_models'):
         models_module = app_cache.get_app_config('app_no_models').models_module
         self.assertIsNone(models_module)
示例#9
0
文件: tests.py 项目: kmalloc/django
 def test_egg1(self):
     """Models module can be loaded from an app in an egg"""
     egg_name = '%s/modelapp.egg' % self.egg_dir
     sys.path.append(egg_name)
     with app_cache._with_app('app_with_models'):
         models_module = app_cache.get_app_config('app_with_models').models_module
         self.assertIsNotNone(models_module)
示例#10
0
 def test_app_locales(self):
     """
     Test that gen_filenames also yields from locale dirs in installed apps.
     """
     with app_cache._empty(), app_cache._with_app('django.contrib.admin'):
         filenames = list(gen_filenames())
     self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale',
                                'nl', 'LC_MESSAGES', 'django.mo'),
                   filenames)
示例#11
0
 def test_nonenglish_default_english_userpref(self):
     """
     Same as above with the difference that there IS an 'en' translation
     available. The Javascript i18n view must return a NON empty language catalog
     with the proper English translations. See #13726 for more details.
     """
     with app_cache._with_app('view_tests.app0'):
         with self.settings(LANGUAGE_CODE='fr'), override('en-us'):
             response = self.client.get('/views/jsi18n_english_translation/')
             self.assertContains(response, javascript_quote('this app0 string is to be translated'))
示例#12
0
    def test_migration_path(self):
        test_apps = ["migrations.migrations_test_apps.normal", "migrations.migrations_test_apps.with_package_model"]

        base_dir = os.path.dirname(os.path.dirname(__file__))

        for app in test_apps:
            with app_cache._with_app(app):
                migration = migrations.Migration("0001_initial", app.split(".")[-1])
                expected_path = os.path.join(base_dir, *(app.split(".") + ["migrations", "0001_initial.py"]))
                writer = MigrationWriter(migration)
                self.assertEqual(writer.path, expected_path)
示例#13
0
文件: tests.py 项目: kmalloc/django
    def test_invalid_models(self):
        with app_cache._with_app("invalid_models_tests.invalid_models"):
            module = app_cache.get_app_config("invalid_models").models_module
            get_validation_errors(self.stdout, module)

        self.stdout.seek(0)
        error_log = self.stdout.read()
        actual = error_log.split('\n')
        expected = module.model_errors.split('\n')

        unexpected = [err for err in actual if err not in expected]
        missing = [err for err in expected if err not in actual]
        self.assertFalse(unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
        self.assertFalse(missing, "Missing Errors: " + '\n'.join(missing))
示例#14
0
文件: tests.py 项目: kmalloc/django
    def test_shortcut_view(self):
        """
        Check that the shortcut view (used for the admin "view on site"
        functionality) returns a complete URL regardless of whether the sites
        framework is installed
        """

        request = HttpRequest()
        request.META = {
            "SERVER_NAME": "Example.com",
            "SERVER_PORT": "80",
        }
        user_ct = ContentType.objects.get_for_model(FooWithUrl)
        obj = FooWithUrl.objects.create(name="john")

        with app_cache._with_app('django.contrib.sites'):
            response = shortcut(request, user_ct.id, obj.id)
            self.assertEqual("http://%s/users/john/" % get_current_site(request).domain,
                             response._headers.get("location")[1])

        with app_cache._without_app('django.contrib.sites'):
            response = shortcut(request, user_ct.id, obj.id)
            self.assertEqual("http://Example.com/users/john/",
                             response._headers.get("location")[1])
示例#15
0
 def test_non_existing(self):
     "Template loading fails if the template is not in the egg"
     with app_cache._with_app('egg_1'):
         egg_loader = EggLoader()
         self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html")
示例#16
0
 def test_empty(self):
     "Loading any template on an empty egg should fail"
     with app_cache._with_app('egg_empty'):
         egg_loader = EggLoader()
         self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html")