summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index bbb449fe3..e107bd6fb 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
@@ -107,6 +110,53 @@ class CommandsTestCase(TestCase):
self.assertEqual(parcel_nb - 1, Parcel.objects.count())
self.assertEqual(Parcel.objects.filter(pk=p.pk).count(), 0)
+ def test_import_geofla(self):
+ 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()):
+ x1 = float(idx) / 10
+ if not x1:
+ x1 = 0
+ x2 = float(idx) / 10 + 0.1
+ l = 'MULTIPOLYGON((({x1} 0.1,{x2} 0.1,{x2} 0,{x1} 0,' \
+ '{x1} 0.1)))'.format(x1=x1, x2=x2)
+ if union_start:
+ union_start += ", "
+ else:
+ first = '{x1} 0.1'.format(x1=x1)
+ union_start += '{x2} 0.1'.format(x1=x1, x2=x2)
+ union_end.append('{x2} 0'.format(x1=x1, x2=x2))
+ 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):
"""