diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-27 17:51:52 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-27 17:51:52 +0200 |
commit | a3aa47a3cc09cdc8d13a33f909aadc70cbbe3397 (patch) | |
tree | 20ebf8d742f2241482420cc89c8a3c4d8d87ab92 /ishtar_common/tests.py | |
parent | 6b80f7b90c714c335533fa55ba5bf859de717e38 (diff) | |
download | Ishtar-a3aa47a3cc09cdc8d13a33f909aadc70cbbe3397.tar.bz2 Ishtar-a3aa47a3cc09cdc8d13a33f909aadc70cbbe3397.zip |
Command import_insee_comm_csv: import town relations
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 2b0a87386..4aa290ed1 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -92,6 +92,9 @@ class TestCase(BaseTestCase): class CommandsTestCase(TestCase): + fixtures = [settings.ROOT_PATH + + '../ishtar_common/fixtures/test_towns.json'] + def test_clean_ishtar(self): """ Clean ishtar db @@ -108,11 +111,47 @@ class CommandsTestCase(TestCase): self.assertEqual(Parcel.objects.filter(pk=p.pk).count(), 0) def test_import_geofla(self): - town_nb = models.Town.objects.count() + q = models.Town.objects + town_nb = q.count() out = StringIO() call_command('import_geofla_csv', '../ishtar_common/tests/geofla-test.csv', stdout=out) self.assertEqual(town_nb + 9, models.Town.objects.count()) + call_command('import_geofla_csv', + '../ishtar_common/tests/geofla-test.csv', stdout=out) + # no new town + self.assertEqual(town_nb + 9, models.Town.objects.count()) + + def test_import_insee(self): + q = models.Town.objects + town_nb = q.count() + first, union_start, union_end = '', '', [] + for idx, town in enumerate(q.all()): + l = 'MULTIPOLYGON((({x1} 1,{x2} 1,{x2} 0,{x1} 0,{x1} 1)))'.format( + x1=idx, x2=idx + 1) + if union_start: + union_start += ", " + else: + first = '{x1} 1'.format(x1=idx) + union_start += '{x2} 1'.format(x1=idx, x2=idx + 1) + union_end.append('{x2} 0'.format(x1=idx, x2=idx + 1)) + town.limit = l + town.save() + union = 'MULTIPOLYGON (((' + first + ", " + union_start + \ + ", " + ", ".join(reversed(union_end)) + ", 0 0, " + first + ")))" + out = StringIO() + call_command('import_insee_comm_csv', + '../ishtar_common/tests/insee-test.csv', stdout=out) + self.assertEqual(town_nb + 1, models.Town.objects.count()) + new = models.Town.objects.order_by('-pk').all()[0] + self.assertEqual(new.parents.count(), 2) + + self.assertEqual(new.limit.wkt, union) + + call_command('import_insee_comm_csv', + '../ishtar_common/tests/insee-test.csv', stdout=out) + # no new town + self.assertEqual(town_nb + 1, models.Town.objects.count()) class WizardTestFormData(object): |