def test_header(self): template = ExportTemplate() template.fields = [] assert template.header == "", "header should be empty" template.fields = [{"name": "foo"}, {"name": "bar"}] assert template.header == "foo\tbar", "header should be correctly generated" template.fields = [{}, {}, {}] assert template.header == "\t\t", "empty column headers should stay as such" template.fields = [{"name": "foo\tbar"}, {"name": '"baz"'}] assert template.header == '"foo\tbar"\t"""baz"""', "column should be quoted"
def test_need(self): template = ExportTemplate() template.fields = [] assert template.needs == set(), "should have no need" template.fields = [{"value": "'foo'"}, {"value": "3 + 2"}] assert template.needs == set(), "should have no need" template.fields = [{"value": "foo"}, {"value": "bar + baz"}] assert template.needs == set(["foo", "bar", "baz"]), "should extract the needs" template.fields = [{"value": "foo"}, {"value": "bar + foo"}, {"value": "bar"}] assert template.needs == set(["foo", "bar"]), "should deduplicate the needs"
def test_links(self): template = ExportTemplate() template.fields = [] assert template.links == [], "should have no link" template.fields = [{"value": "foo"}] assert template.links == [], "should have no link" template.fields = [{"value": "links['foo'] + bar"}] assert template.links == ["foo"], "should extract the link" template.fields = [{"value": "mainlinks + linksbar + mainlinks['bar']"}] assert template.links == [], "should not be fooled by value including `links`" template.fields = [ {"value": "links['foo']"}, {"value": "links['bar'] + links['foo']"}, ] assert template.links == ["bar", "foo"], "should dedupe links" template.fields = [{"value": "links['bar'] + links['foo']"}] tmp_links = template.links template.fields = [{"value": "links['foo'] + links['bar']"}] assert template.links == tmp_links, "order should stay the same"