예제 #1
0
    def test_registry_dynamic_template_addition(self):
        module_map = {'tmp': mkdtemp_singleton(self)}
        stub_mod_mock_resources_filename(self, pkg_resources, module_map)
        (working_set, main_template,
         sub_template) = setup_tmp_mold_templates(self)
        registry = MoldRegistry.create(_working_set=working_set,
                                       auto_reload=True)

        path = registry.lookup_path('tmp/mold/template.nja')
        self.assertEqual(main_template, path)

        tmpdir = mkdtemp_singleton(self)
        mold_root = join(tmpdir, 'tmp', 'root')
        mold_base = join(mold_root, 'new_mold')
        mkdir(mold_base)
        path = registry.lookup_path('tmp/new_mold/template.nja')
        new_tmpl = join(mold_base, 'template.nja')
        self.assertEqual(path, new_tmpl)

        with self.assertRaises(OSError):
            registry.verify_path('tmp/new_mold/template.nja')

        with open(new_tmpl, 'w') as fd:
            fd.write('<div>New Template</div>')

        self.assertEqual(registry.verify_path('tmp/new_mold/template.nja'),
                         new_tmpl)
예제 #2
0
    def test_registry_verify_path_registered(self):
        registry = self.mk_test_registry()
        path = registry.verify_path(
            'nunja.testing.templates/itemlist/template.nja')
        with open(path, 'r') as fd:
            contents = fd.readline()
        self.assertEqual(
            contents, '<ul{%- if list_id %} id="{{ list_id }}"{% endif -%}>\n')

        # fake a registration
        registry.templates['ntm/faketemplate/nosuchpath.nja'] = 'nowhere_path'
        with self.assertRaises(OSError):
            registry.verify_path('ntm/faketemplate/nosuchpath.nja')
예제 #3
0
 def test_registry_verify_traversal(self):
     registry = self.mk_test_registry()
     path = registry.verify_path('nunja.testing.mold/itemlist/template.nja')
     with open(join(path), 'r') as fd:
         contents = fd.readline()
     self.assertEqual(
         contents, '<ul{%- if list_id %} id="{{ list_id }}"{% endif -%}>\n')
예제 #4
0
 def test_registry_verify_path_unregistered(self):
     registry = self.mk_test_registry(['ntm = nunja.testing:mold'])
     with self.assertRaises(OSError):
         registry.verify_path('ntm/itemlist/nosuchpath.nja')