Пример #1
0
    def test_undefined(self):
        """
        Raise an error if a template value is undefined.
        """

        with self.assertRaises(UndefinedError):
            ConfFiles(load_environment_from_package('confab.tests'), {})
Пример #2
0
    def test_undefined(self):
        """
        An exception is raised if a template value is undefined.
        """
        conffiles = ConfFiles(load_environment_from_package("confab.tests"), {"bar": "bar"})

        with settings(hide("user"), host_string="localhost"):
            with TempDir() as tmp_dir:
                with self.assertRaises(UndefinedError):
                    conffiles.generate(tmp_dir.path)
Пример #3
0
    def test_should_render(self):
        """
        Passing a mime_type_func controls whether templates are rendered.
        """
        conffiles = ConfFiles(load_environment_from_package("confab.tests"), {"bar": "bar", "foo": "foo"})

        with Options(should_render=lambda mime_type: False):
            with settings(hide("user"), host_string="localhost"):
                with TempDir() as tmp_dir:
                    conffiles.generate(tmp_dir.path)

                    # templates not rendered (though paths are)
                    self.assertEquals("{{foo}}", tmp_dir.read("localhost/foo.txt"))
                    self.assertEquals("{{bar}}", tmp_dir.read("localhost/bar/bar.txt"))
Пример #4
0
    def test_filter_func(self):
        """
        Passing a filter_func limits which templates are generated.
        """

        with Options(filter_func=lambda file_name: file_name != 'foo.txt'):
            conffiles = ConfFiles(load_environment_from_package('confab.tests'),
                                  {'bar': 'bar'})

            self.assertEquals(1, len(conffiles.conffiles))

            names = map(lambda x: x.name, conffiles.conffiles)

            self.assertTrue('bar/bar.txt' in names)
Пример #5
0
    def test_get_conf_files(self):
        """
        Generating conf files finds all templates in the package
        and generates their names properly.
        """
        conffiles = ConfFiles(load_environment_from_package('confab.tests'),
                              {'bar': 'bar'})

        self.assertEquals(2, len(conffiles.conffiles))

        names = map(lambda x: x.name, conffiles.conffiles)

        self.assertTrue('foo.txt' in names)
        self.assertTrue('bar/bar.txt' in names)
Пример #6
0
    def test_generate(self):
        """
        Generated templates have the correct values.
        """
        conffiles = ConfFiles(load_environment_from_package("confab.tests"), {"bar": "bar", "foo": "foo"})

        with settings(hide("user"), host_string="localhost"):
            with TempDir() as tmp_dir:
                conffiles.generate(tmp_dir.path)

                # foo.txt is populated with 'foo'
                self.assertEquals("foo", tmp_dir.read("localhost/foo.txt"))

                # bar.txt is populated with 'bar' and path is substituted
                self.assertEquals("bar", tmp_dir.read("localhost/bar/bar.txt"))
Пример #7
0
    def test_should_render(self):
        """
        Passing a mime_type_func controls whether templates are rendered.
        """
        conffiles = ConfFiles(load_environment_from_package('confab.tests'),
                              {'bar': 'bar', 'foo': 'foo'})

        with Options(should_render=lambda mime_type: False):
            with settings(hide('user'),
                          host_string='localhost'):
                with TempDir() as tmp_dir:
                    conffiles.generate(tmp_dir.path)

                    # templates not rendered (though paths are)
                    self.assertEquals('{{foo}}', tmp_dir.read('localhost/foo.txt'))
                    self.assertEquals('{{bar}}', tmp_dir.read('localhost/bar/bar.txt'))
Пример #8
0
    def test_unicode(self):
        """
        Generated templates with unicode data.
        """
        conffiles = ConfFiles(load_environment_from_package('confab.tests'),
                              {'bar': 'bar', 'foo': u'\xc5\xae'})
        with settings(hide('user'),
                      host_string='localhost'):
            with TempDir() as tmp_dir:
                conffiles.generate(tmp_dir.path)

                # foo.txt is populated with u'\xc5\xae'
                self.assertEquals(u'\xc5\xae', tmp_dir.read('localhost/foo.txt'))

                # bar.txt is populated with 'bar' and path is substituted
                self.assertEquals('bar', tmp_dir.read('localhost/bar/bar.txt'))