Changeset 7750
- Timestamp:
- 06/25/08 23:22:12 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/regressiontests/templates/loaders.py
r7567 r7750 1 # -*- coding: utf-8 -*-2 1 """ 3 2 Test cases for the template loaders 3 4 Note: This test requires setuptools! 4 5 """ 5 6 … … 18 19 from django.template.loaders.eggs import load_template_source as lts_egg 19 20 20 # Mock classes and objects for pkg_resources functions21 # Mock classes and objects for pkg_resources functions. 21 22 class MockProvider(pkg_resources.NullProvider): 22 23 def __init__(self, module): … … 36 37 return self.module._resources[path].read() 37 38 38 class MockLoader(object): pass 39 class MockLoader(object): 40 pass 39 41 40 42 def create_egg(name, resources): 41 43 """ 42 Creates a mock egg with a list of resources 43 44 name: The name of the module 45 resources: A dictionary of resources. Keys are the names and values the the data. 44 Creates a mock egg with a list of resources. 45 46 name: The name of the module. 47 resources: A dictionary of resources. Keys are the names and values the the data. 46 48 """ 47 49 egg = imp.new_module(name) … … 50 52 sys.modules[name] = egg 51 53 52 53 54 class EggLoader(unittest.TestCase): 54 55 def setUp(self): 55 56 pkg_resources._provider_factories[MockLoader] = MockProvider 56 57 57 58 self.empty_egg = create_egg("egg_empty", {}) 58 59 self.egg_1 = create_egg("egg_1", { … … 62 63 self._old_installed_apps = settings.INSTALLED_APPS 63 64 settings.INSTALLED_APPS = [] 64 65 65 66 def tearDown(self): 66 67 settings.INSTALLED_APPS = self._old_installed_apps … … 75 76 settings.INSTALLED_APPS = ['egg_1'] 76 77 self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html") 77 78 78 79 def test_existing(self): 79 80 "A template can be loaded from an egg" … … 82 83 self.assertEqual(contents, "y") 83 84 self.assertEqual(template_name, "egg:egg_1:templates/y.html") 84 85 85 86 def test_not_installed(self): 86 87 "Loading an existent template from an egg not included in INSTALLED_APPS should fail" … … 88 89 self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html") 89 90 90 91 91 if __name__ == "__main__": 92 92 unittest.main()
