def test_interpolates_parameters(self): param_name = factory.make_name('param', sep='_') param_value = factory.make_string() self.assertEqual( "X %s Y" % param_value, render_dns_template( self.make_file(contents="X {{%s}} Y" % param_name), {param_name: param_value}))
def test_combines_parameter_dicts(self): self.assertEqual( "aaa bbb", render_dns_template( self.make_file(contents="{{one}} {{two}}"), {"one": "aaa"}, {"two": "bbb"}, ), )
def test_takes_latest_value_of_redefined_parameter(self): self.assertEqual( "last", render_dns_template( self.make_file(contents="{{var}}"), {"var": "first"}, {"var": "middle"}, {"var": "last"}, ), )
def write_zone_file(cls, output_file, *parameters): """Write a zone file based on the zone file template. There is a subtlety with zone files: their filesystem timestamp must increase with every rewrite. Some filesystems (ext3?) only seem to support a resolution of one second, and so this method may set an unexpected modification time in order to maintain that property. """ if not isinstance(output_file, list): output_file = [output_file] for outfile in output_file: content = render_dns_template(cls.template_file_name, *parameters) with report_missing_config_dir(): incremental_write(content.encode("utf-8"), outfile, mode=0o644) pass
def test_renders_template(self): template_text = "X %d Y" % random.randint(1, 10000) self.assertEqual( template_text, render_dns_template(self.make_file(contents=template_text)), )
def test_takes_latest_value_of_redefined_parameter(self): self.assertEqual( "last", render_dns_template(self.make_file(contents='{{var}}'), {'var': 'first'}, {'var': 'middle'}, {'var': 'last'}))
def test_combines_parameter_dicts(self): self.assertEqual( "aaa bbb", render_dns_template(self.make_file(contents='{{one}} {{two}}'), {'one': 'aaa'}, {'two': 'bbb'}))