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.py41
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):