Ejemplo n.º 1
0
    def test_basic(self):
        """It can be initialized with a given separator and a mapping.
        it loads a data file and read its headers."""

        importer = CSVImporter(separator=" ", mapping=None)
        importer.open("fixtures/test_1.csv")
        self.assertEquals(['country.name', 'city.name'], importer._headers)
Ejemplo n.º 2
0
    def setUp(self):
        self.mapping = CSVImporterMapping()
        self.mapping.map_class('country', Country)
        self.mapping.map_class('city', City)

        self.importer = CSVImporter(separator=" ", mapping=self.mapping)
        self.importer.open("fixtures/test_1.csv")
Ejemplo n.º 3
0
class MappingTestCase(TestCase):

    def setUp(self):
        self.mapping = CSVImporterMapping()
        self.importer = CSVImporter(separator=" ", mapping=self.mapping)
        self.importer.open("fixtures/test_1.csv")

    def test_mapping(self):
        """It receives a mapping of classes"""

        self.mapping.map_class('country', Country)
        self.mapping.map_class('city', City)

    def test_mapping_relations(self):
        """Relations can be defined"""

        self.mapping.map_relation(base="city", attribute="country", target="country")
Ejemplo n.º 4
0
class ReadTestCase(TestCase):

    def setUp(self):
        self.mapping = CSVImporterMapping()
        self.mapping.map_class('country', Country)
        self.mapping.map_class('city', City)

        self.importer = CSVImporter(separator=" ", mapping=self.mapping)
        self.importer.open("fixtures/test_1.csv")


    def test_readline(self):
        """It can read a line and construct the corresponding models"""

        results = self.importer.readline()
        results['country'].__class__ == Country
        results['city'].__class__ == City

    def test_relation(self):
        """It can establish relationships betweeen models on the same line."""

        self.mapping.map_relation(base="city", attribute="country", target="country")

        results = self.importer.readline()
        self.assertEqual(results['city'].country, results['country'])

    def test_save(self):
        """It can save the parsed result to the DB."""

        self.mapping.map_relation(base="city", attribute="country", target="country")

        results = self.importer.readline()
        self.importer.save_row(results)

        for name, obj in results.items():
            self.assertNotEquals(None, obj.pk)

    def test_save_all(self):
        """It can iterate over the entire file and save al to db"""
        self.mapping.map_relation(base="city", attribute="country", target="country")

        self.importer.save_all()
Ejemplo n.º 5
0
 def setUp(self):
     self.mapping = CSVImporterMapping()
     self.importer = CSVImporter(separator=" ", mapping=self.mapping)
     self.importer.open("fixtures/test_1.csv")