class TestTSVResource(object): def setup(self): self.path = '%s' self.resource = TSVResource(resource_name=None, config=None, proxies=None, path=self.path) def test_serialize(self): data = [ dict(id="12", name="name1", country="France"), dict(id="45", name="name2", country=""), dict(id="78", name="name3"), ] assert_equals( "country\tname\tid\nFrance\tname1\t12\n\tname2\t45\n\tname3\t78", self.resource.serialize(data)) def test_deserialize(self): tsv = "id\tname\tcountry\n12\tname1\tFrance\n45\tname2\t\n78\tname3" data = self.resource.deserialize(tsv) assert_equals(3, len(data)) assert_equals("12", data[0]["id"]) assert_equals("name1", data[0]["name"]) assert_equals("France", data[0]["country"]) assert_equals("45", data[1]["id"]) assert_equals("name2", data[1]["name"]) assert_equals("", data[1]["country"]) assert_equals("78", data[2]["id"]) assert_equals("name3", data[2]["name"]) assert_equals("", data[2]["country"])
def setup(self): self.path = '%s' self.resource = TSVResource(resource_name=None, config=None, proxies=None, path=self.path)