'Test _render_template'

@mock.patch('config.get_auto_confd_path', return_value=os.path.join(os.path.dirname(__file__), 'fixtures/auto_conf/'))
def test_render_template(self, mock_get_auto_confd_path):

    valid_configs = [(({}, {'host': '%%host%%'}, {'host': 'foo'}), ({}, {'host': 'foo'})), (({}, {'host': '%%host%%', 'port': '%%port%%'}, {'host': 'foo', 'port': '1337'}), ({}, {'host': 'foo', 'port': '1337'})), (({'foo': '%%bar%%'}, {}, {'bar': 'w00t'}), ({'foo': 'w00t'}, {})), (({'foo': '%%bar%%'}, {'host': '%%host%%'}, {'bar': 'w00t', 'host': 'localhost'}), ({'foo': 'w00t'}, {'host': 'localhost'}))]
    invalid_configs = [({}, {'host': '%%host%%'}, {}), ({}, {'host': '%%host%%'}, {'port': 42}), ({'foo': '%%bar%%'}, {'host': '%%host%%'}, {'host': 'foo'})]
    with mock.patch('utils.dockerutil.DockerUtil.client', return_value=None):
        with mock.patch.object(EtcdStore, 'get_client', return_value=None):
            with mock.patch.object(ConsulStore, 'get_client', return_value=None):
                for agentConfig in self.agentConfigs:
                    sd_backend = get_sd_backend(agentConfig=agentConfig)
                    for (tpl, res) in valid_configs:
                        (init, instance, variables) = tpl
                        config = sd_backend._render_template(init, instance, variables)
                        self.assertEquals(config, res)
                    for (init, instance, variables) in invalid_configs:
                        config = sd_backend._render_template(init, instance, variables)
                        self.assertEquals(config, None)
                        clear_singletons(agentConfig)
