def setUp(self): self.intervention = InterventionFactory.create() self.project = ProjectFactory.create() self.project.interventions.add(self.intervention) self.project.interventions.add(InterventionFactory.create()) infra = InfrastructureFactory.create() self.intervention.set_infrastructure(infra) self.intervention.save() path = infra.paths.get() self.signagemgt = SignageManagementEdgeFactory.create(no_path=True) self.signagemgt.add_path(path, start=0.3, end=0.7) self.workmgt = WorkManagementEdgeFactory.create(no_path=True) self.workmgt.add_path(path, start=0.3, end=0.7) self.competencemgt = CompetenceEdgeFactory.create(no_path=True) self.competencemgt.add_path(path, start=0.3, end=0.7) self.cityedge = CityEdgeFactory.create(no_path=True) self.cityedge.add_path(path, start=0.3, end=0.7) self.districtedge = DistrictEdgeFactory.create(no_path=True) self.districtedge.add_path(path, start=0.3, end=0.7) self.restricted = RestrictedAreaEdgeFactory.create(no_path=True) self.restricted.add_path(path, start=0.3, end=0.7)
def test_project_bbox_filter(self): self.login() p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() t = TopologyFactory.create() InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = json.loads(response.content) return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual(len(jsonlist('?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))')), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((2.9%2046.4%2C%203.1%2046.4%2C%203.1%2046.6%2C%202.9%2046.6%2C%202.9%2046.4))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_delete_show_topologies(self): self.login() path = PathFactory(name="PATH_AB", geom=LineString((0, 0), (4, 0))) poi = POIFactory.create(name='POI', no_path=True) poi.add_path(path, start=0.5, end=0.5) trail = TrailFactory.create(name='Trail', no_path=True) trail.add_path(path, start=0.1, end=0.2) trek = TrekFactory.create(name='Trek', no_path=True) trek.add_path(path, start=0.2, end=0.3) service = ServiceFactory.create(no_path=True, type__name='ServiceType') service.add_path(path, start=0.2, end=0.3) signage = SignageFactory.create(name='Signage', no_path=True) signage.add_path(path, start=0.2, end=0.2) infrastructure = InfrastructureFactory.create(name='Infrastructure', no_path=True) infrastructure.add_path(path, start=0.2, end=0.2) intervention1 = InterventionFactory.create(topology=signage, name='Intervention1') t = TopologyFactory.create(no_path=True) t.add_path(path, start=0.2, end=0.5) intervention2 = InterventionFactory.create(topology=t, name='Intervention2') response = self.client.get(path.get_delete_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Different topologies are linked with this path') self.assertContains(response, '<a href="/poi/%d/">POI</a>' % poi.pk) self.assertContains(response, '<a href="/trail/%d/">Trail</a>' % trail.pk) self.assertContains(response, '<a href="/trek/%d/">Trek</a>' % trek.pk) self.assertContains(response, '<a href="/service/%d/">ServiceType</a>' % service.pk) self.assertContains(response, '<a href="/signage/%d/">Signage</a>' % signage.pk) self.assertContains(response, '<a href="/infrastructure/%d/">Infrastructure</a>' % infrastructure.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention1</a>' % intervention1.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention2</a>' % intervention2.pk)
def test_path_helpers(self): p = PathFactory.create() self.assertEquals(len(p.interventions), 0) self.assertEquals(len(p.projects), 0) sign = SignageFactory.create(no_path=True) sign.add_path(p, start=0.5, end=0.5) infra = InfrastructureFactory.create(no_path=True) infra.add_path(p) i1 = InterventionFactory.create() i1.set_infrastructure(sign) i1.save() self.assertItemsEqual(p.interventions, [i1]) i2 = InterventionFactory.create() i2.set_infrastructure(infra) i2.save() self.assertItemsEqual(p.interventions, [i1, i2]) proj = ProjectFactory.create() proj.interventions.add(i1) proj.interventions.add(i2) self.assertItemsEqual(p.projects, [proj])
def test_delete_multiple_path(self): path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0))) path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2))) poi = POIFactory.create(no_path=True, name="POI_1") poi.add_path(path_1, start=0, end=0) infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1") infrastructure.add_path(path_1, start=0, end=1) signage = SignageFactory.create(no_path=True, name="SIGNA_1") signage.add_path(path_1, start=0, end=1) trail = TrailFactory.create(no_path=True, name="TRAIL_1") trail.add_path(path_2, start=0, end=1) service = ServiceFactory.create(no_path=True) service.add_path(path_2, start=0, end=1) InterventionFactory.create(topology=signage, name="INTER_1") response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)])) self.assertIn("POI_1", response.content) self.assertIn("INFRA_1", response.content) self.assertIn("SIGNA_1", response.content) self.assertIn("TRAIL_1", response.content) self.assertIn("ServiceType", response.content) self.assertIn("INTER_1", response.content) response = self.client.post(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)])) self.assertEqual(response.status_code, 302) self.assertEqual(Path.objects.count(), 2) self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0)
def create_pair_of_distinct_by_topo_intervention(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=topo_1, path=p1, start_position=0, end_position=1) seek_topo = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=seek_topo, path=seek_path, start_position=0, end_position=1) it_p1 = InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) return seek_it, seek_path
def create_pair_of_distinct_by_topo_intervention(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) topo_1.add_path(path=p1, start=0, end=1) seek_topo = TopologyFactory.create(no_path=True) seek_topo.add_path(path=seek_path, start=0, end=1) InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) return seek_it, seek_path
def test_project_layer(self): p1 = ProjectFactory.create() ProjectFactory.create() InterventionFactory.create(project=p1) # Check that only p1 is in geojson response = self.client.get(self.model.get_layer_url()) self.assertEqual(response.status_code, 200) geojson = json.loads(response.content) features = geojson['features'] self.assertEqual(len(Project.objects.all()), 2) self.assertEqual(len(features), 1) self.assertEqual(features[0]['properties']['pk'], p1.pk)
def test_helpers(self): infra = InfrastructureFactory.create() sign = SignageFactory.create() interv = InterventionFactory.create() proj = ProjectFactory.create() self.assertFalse(interv.on_infrastructure) self.assertEquals(interv.infrastructure, None) interv.set_infrastructure(infra) self.assertTrue(interv.on_infrastructure) self.assertFalse(interv.is_signage) self.assertTrue(interv.is_infrastructure) self.assertEquals(interv.signages, []) self.assertEquals(interv.infrastructures, [infra]) self.assertEquals(interv.infrastructure, infra) interv.set_infrastructure(sign) self.assertTrue(interv.on_infrastructure) self.assertTrue(interv.is_signage) self.assertFalse(interv.is_infrastructure) self.assertEquals(interv.signages, [sign]) self.assertEquals(interv.infrastructures, []) self.assertEquals(interv.infrastructure, sign) self.assertFalse(interv.in_project) interv.project = proj self.assertTrue(interv.in_project)
def test_default_stake(self): i = InterventionFactory.create() i.stake = None self.assertTrue(i.stake is None) i.save() self.assertTrue(i.stake is None) lowstake = StakeFactory.create() highstake = StakeFactory.create() if lowstake > highstake: tmp = lowstake lowstake = highstake highstake = tmp # Add paths to topology infra = InfrastructureFactory.create(no_path=True) infra.add_path(PathFactory.create(stake=lowstake)) infra.add_path(PathFactory.create(stake=highstake)) infra.add_path(PathFactory.create(stake=lowstake)) i.set_infrastructure(infra) # Stake is not None anymore i.save() self.assertFalse(i.stake is None) # Make sure it took higher stake self.assertEqual(i.stake, highstake)
def test_update_form_on_signage(self): self.login() signa = SignageFactory.create() signage = u"%s" % signa intervention = InterventionFactory.create() self.assertIsNone(intervention.signage) intervention.set_topology(signa) intervention.save() self.assertIsNotNone(intervention.signage) response = self.client.get(intervention.get_update_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, signage) # Should be able to save form successfully form = response.context['form'] data = form.initial data['disorders'] = data['disorders'][0].pk data['project'] = '' data['signage'] = form.fields['signage'].initial.pk # because it is set after form init, not form.initial :( data.update(**{ 'manday_set-TOTAL_FORMS': '0', 'manday_set-INITIAL_FORMS': '0', 'manday_set-MAX_NUM_FORMS': '', }) # Form URL is modified in form init formurl = intervention.get_update_url() + '?signage=%s' % signa.pk response = self.client.post(formurl, data) self.assertEqual(response.status_code, 302)
def test_update_form_on_infrastructure(self): self.login() infra = InfrastructureFactory.create() infrastr = u"%s" % infra intervention = InterventionFactory.create() intervention.set_infrastructure(infra) intervention.save() response = self.client.get(intervention.get_update_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, infrastr) # Should be able to save form successfully form = response.context['form'] data = form.initial data['project'] = '' data['infrastructure'] = form.fields['infrastructure'].initial.pk # because it is set after form init, not form.initial :( data.update(**{ 'manday_set-TOTAL_FORMS': '0', 'manday_set-INITIAL_FORMS': '0', 'manday_set-MAX_NUM_FORMS': '', }) # Form URL is modified in form init formurl = intervention.get_update_url() + '?infrastructure=%s' % infra.pk response = self.client.post(formurl, data) self.assertEqual(response.status_code, 302)
def test_delete_topology(self): infra = InfrastructureFactory.create() interv = InterventionFactory.create() interv.set_infrastructure(infra) interv.save() infra.delete() self.assertEqual(Infrastructure.objects.existing().count(), 0) self.assertEqual(Intervention.objects.existing().count(), 0)
def test_infrastructure(self): i = InterventionFactory.create() self.assertFalse(i.on_infrastructure) infra = InfrastructureFactory.create() i.set_infrastructure(infra) self.assertTrue(i.on_infrastructure) sign = SignageFactory.create() i.set_infrastructure(sign) self.assertTrue(i.on_infrastructure)
def test_infrastructure(self): i = InterventionFactory.create() self.assertFalse(i.on_existing_topology) infra = InfrastructureFactory.create() i.set_topology(infra) self.assertTrue(i.on_existing_topology) sign = SignageFactory.create() i.set_topology(sign) self.assertTrue(i.on_existing_topology)
def test_structurerelated_not_loggedin(self): # Test that it does not fail on update if not logged in self.client.logout() response = self.client.get(Intervention.get_add_url()) self.assertEqual(response.status_code, 302) i = InterventionFactory.create() response = self.client.get(i.get_update_url()) self.assertEqual(response.status_code, 302)
def create_pair_of_distinct_by_topo_project(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) topo_1.add_path(path=p1, start=0, end=1) seek_topo = TopologyFactory.create(no_path=True) seek_topo.add_path(path=seek_path, start=0, end=1) it_p1 = InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) seek_proj = ProjectFactory.create() seek_proj.interventions.add(seek_it) proj_1 = ProjectFactory.create() proj_1.interventions.add(it_p1) return seek_proj, seek_path
def test_deleted_intervention(self): i1 = InterventionFactory.create() sign = SignageFactory.create() i1.set_topology(sign) i1.save() proj = ProjectFactory.create() proj.interventions.add(i1) self.assertEquals(proj.signages, [sign]) i1.delete() self.assertEquals(proj.signages, [])
def test_helpers(self): i1 = InterventionFactory.create() i2 = InterventionFactory.create() i3 = InterventionFactory.create() sign = SignageFactory.create() i1.set_topology(sign) p1 = sign.paths.get() infra = InfrastructureFactory.create() i2.set_topology(infra) p2 = infra.paths.get() t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1) i3.topology = t proj = ProjectFactory.create() self.assertItemsEqual(proj.paths.all(), []) self.assertEquals(proj.signages, []) self.assertEquals(proj.infrastructures, []) i1.save() proj.interventions.add(i1) self.assertItemsEqual(proj.paths.all(), [p1]) self.assertEquals(proj.signages, [sign]) self.assertEquals(proj.infrastructures, []) i2.save() proj.interventions.add(i2) self.assertItemsEqual(proj.paths.all(), [p1, p2]) self.assertEquals(proj.signages, [sign]) self.assertEquals(proj.infrastructures, [infra]) i3.save() proj.interventions.add(i3) self.assertItemsEqual(proj.paths.all(), [p1, p2]) self.assertEquals(proj.signages, [sign]) self.assertEquals(proj.infrastructures, [infra])
def test_denormalized_fields(self): interv = InterventionFactory.create(width = 10.0, height = 10.0) interv.reload() self.assertEqual(interv.area, 100.0) infra = InfrastructureFactory.create() infra.save() self.assertNotEqual(infra.length, 0.0) interv.set_infrastructure(infra) interv.save() self.assertEqual(interv.length, infra.length)
def test_deleted_infrastructure(self): i1 = InterventionFactory.create() infra = InfrastructureFactory.create() i1.set_infrastructure(infra) proj = ProjectFactory.create() proj.interventions.add(i1) self.assertEquals(proj.infrastructures, [infra]) infra.delete() self.assertEquals(proj.infrastructures, [])
def test_form_deleted_projects(self): self.login() p1 = ProjectFactory.create() p2 = ProjectFactory.create() i = InterventionFactory.create(project=p1) response = self.client.get(i.get_update_url()) self.assertEqual(response.status_code, 200) form = self.get_form(response) projects = form.fields['project'].queryset.all() self.assertItemsEqual(projects, [p1, p2]) p2.delete() projects = form.fields['project'].queryset.all() self.assertItemsEqual(projects, [p1])
def test_deleted_interventions(self): project = ProjectFactory.create() intervention = InterventionFactory.create() project.interventions.add(intervention) response = self.client.get(project.get_detail_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, intervention.name) intervention.delete() response = self.client.get(project.get_detail_url()) self.assertEqual(response.status_code, 200) self.assertNotContains(response, intervention.name)
def test_project_bbox_filter(self): p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() t = TopologyFactory.create() InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = json.loads(response.content) return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual(len(jsonlist('?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))')), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((-1.3630753338765911%20-5.9838497371070440%2C%20-1.3630694576343052%20-5.9838497371070440%2C%20-1.3630694576343052%20-5.9838431650051289%2C%20-1.3630753338765911%20-5.9838431650051289%2C%20-1.3630753338765911%20-5.9838497371070440))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_form_on_infrastructure(self): self.login() infra = InfrastructureFactory.create() infrastr = u"%s" % infra # For creation response = self.client.get(Intervention.get_add_url() + '?infrastructure=%s' % infra.pk) self.assertEqual(response.status_code, 200) self.assertContains(response, infrastr) # For edition intervention = InterventionFactory.create() intervention.set_infrastructure(infra) response = self.client.get(infra.get_update_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, infrastr)
def test_denormalized_fields(self): infra = InfrastructureFactory.create() infra.save() self.assertNotEqual(infra.length, 0.0) # After setting related infrastructure interv = InterventionFactory.create() interv.set_infrastructure(infra) interv.save() self.assertEqual(interv.length, infra.length) # After update related infrastructure infra.length = 3.14 infra.save() interv.reload() self.assertEqual(interv.length, infra.length)
def test_topology_has_intervention_kind(self): topo = TopologyFactory.create() self.assertEqual('TOPOLOGY', topo.kind) i = InterventionFactory.create(topology=topo) self.assertEqual('INTERVENTION', i.topology.kind)
def test_shape_mixed(self): """ Test that a project made of intervention of different geom create multiple files. Check that those files are each of a different type (Point/LineString) and that the project and the intervention are correctly referenced in it. """ # Create topology line topo_line = TopologyFactory.create(no_path=True) line = PathFactory.create(geom=LineString(Point(10, 10, 0), Point(11, 10, 0))) PathAggregationFactory.create(topo_object=topo_line, path=line) # Create a topology point lng, lat = tuple(Point(1, 1, srid=settings.SRID).transform(settings.API_SRID, clone=True)) closest_path = PathFactory(geom=LineString(Point(0, 0, 0), Point(1, 0, 0), srid=settings.SRID)) topo_point = TopologyHelper._topologypoint(lng, lat, None).reload() self.assertEquals(topo_point.paths.get(), closest_path) # Create one intervention by geometry (point/linestring) it_point = InterventionFactory.create(topology=topo_point) it_line = InterventionFactory.create(topology=topo_line) # reload it_point = type(it_point).objects.get(pk=it_point.pk) it_line = type(it_line).objects.get(pk=it_line.pk) proj = ProjectFactory.create() proj.interventions.add(it_point) proj.interventions.add(it_line) # instanciate the class based view 'abnormally' to use create_shape directly # to avoid making http request, authent and reading from a zip pfl = ZipShapeSerializer() devnull = open(os.devnull, "wb") pfl.serialize(Project.objects.all(), stream=devnull, delete=False, fields=ProjectFormatList.columns) self.assertEquals(len(pfl.layers), 2) ds_point = gdal.DataSource(pfl.layers.values()[0]) layer_point = ds_point[0] ds_line = gdal.DataSource(pfl.layers.values()[1]) layer_line = ds_line[0] self.assertEquals(layer_point.geom_type.name, 'MultiPoint') self.assertEquals(layer_line.geom_type.name, 'LineString') for layer in [layer_point, layer_line]: self.assertEquals(layer.srs.name, 'RGF93_Lambert_93') self.assertItemsEqual(layer.fields, ['domain', 'name', 'type', 'period', 'id']) self.assertEquals(len(layer_point), 1) self.assertEquals(len(layer_line), 1) for feature in layer_point: self.assertEquals(str(feature['id']), str(proj.pk)) self.assertTrue(feature.geom.geos.equals(it_point.geom)) for feature in layer_line: self.assertEquals(str(feature['id']), str(proj.pk)) self.assertTrue(feature.geom.geos.equals(it_line.geom)) # Clean-up temporary shapefiles for layer_file in pfl.layers.values(): for subfile in shapefile_files(layer_file): os.remove(subfile)
def test_infrastructure_display_is_path_by_default(self): translation.activate('en') on_path = InterventionFactory.create() self.assertIn('Path', on_path.infrastructure_display) self.assertIn('path-16.png', on_path.infrastructure_display)
def test_infrastructure_display_is_path_by_default(self): translation.activate('en') on_path = InterventionFactory.create() self.assertIn('Path', on_path.target_display) self.assertIn('path-16.png', on_path.target_display)
def create_interv(): interv = InterventionFactory.create(target=infra) return interv
def test_shape_mixed(self): """ Test that a project made of intervention of different geom create multiple files. Check that those files are each of a different type (Point/LineString) and that the project and the intervention are correctly referenced in it. """ # Create topology line topo_line = TopologyFactory.create(no_path=True) line = PathFactory.create( geom=LineString(Point(10, 10), Point(11, 10))) PathAggregationFactory.create(topo_object=topo_line, path=line) # Create a topology point lng, lat = tuple( Point(1, 1, srid=settings.SRID).transform(settings.API_SRID, clone=True)) closest_path = PathFactory( geom=LineString(Point(0, 0), Point(1, 0), srid=settings.SRID)) topo_point = TopologyHelper._topologypoint(lng, lat, None).reload() self.assertEquals(topo_point.paths.get(), closest_path) # Create one intervention by geometry (point/linestring) it_point = InterventionFactory.create(topology=topo_point) it_line = InterventionFactory.create(topology=topo_line) # reload it_point = type(it_point).objects.get(pk=it_point.pk) it_line = type(it_line).objects.get(pk=it_line.pk) proj = ProjectFactory.create() proj.interventions.add(it_point) proj.interventions.add(it_line) # instanciate the class based view 'abnormally' to use create_shape directly # to avoid making http request, authent and reading from a zip pfl = ZipShapeSerializer() devnull = open(os.devnull, "wb") pfl.serialize(Project.objects.all(), stream=devnull, delete=False, fields=ProjectFormatList.columns) self.assertEquals(len(pfl.layers), 2) ds_point = gdal.DataSource(pfl.layers.values()[0]) layer_point = ds_point[0] ds_line = gdal.DataSource(pfl.layers.values()[1]) layer_line = ds_line[0] self.assertEquals(layer_point.geom_type.name, 'MultiPoint') self.assertEquals(layer_line.geom_type.name, 'LineString') for layer in [layer_point, layer_line]: self.assertEquals(layer.srs.name, 'RGF93_Lambert_93') self.assertItemsEqual(layer.fields, [ u'id', u'name', u'period', u'type', u'domain', u'constraint', u'global_cos', u'interventi', u'interven_1', u'comments', u'contractor', u'project_ow', u'project_ma', u'founders', u'related_st', u'insertion_', u'update_dat', u'cities', u'districts', u'restricted' ]) self.assertEquals(len(layer_point), 1) self.assertEquals(len(layer_line), 1) for feature in layer_point: self.assertEquals(str(feature['id']), str(proj.pk)) self.assertEquals(len(feature.geom.geos), 1) self.assertAlmostEqual(feature.geom.geos[0].x, it_point.geom.x) self.assertAlmostEqual(feature.geom.geos[0].y, it_point.geom.y) for feature in layer_line: self.assertEquals(str(feature['id']), str(proj.pk)) self.assertTrue(feature.geom.geos.equals(it_line.geom)) # Clean-up temporary shapefiles for layer_file in pfl.layers.values(): for subfile in shapefile_files(layer_file): os.remove(subfile)
def test_shape_mixed(self): """ Test that a project made of intervention of different geom create multiple files. Check that those files are each of a different type (Point/LineString) and that the project and the intervention are correctly referenced in it. """ # Create topology line line = PathFactory.create(geom=LineString(Point(10, 10), Point(11, 10))) topo_line = TopologyFactory.create(paths=[line]) # Create a topology point lng, lat = tuple(Point(1, 1, srid=settings.SRID).transform(settings.API_SRID, clone=True)) closest_path = PathFactory(geom=LineString(Point(0, 0), Point(1, 0), srid=settings.SRID)) topo_point = Topology._topologypoint(lng, lat, None) topo_point.save() self.assertEqual(topo_point.paths.get(), closest_path) # Create one intervention by geometry (point/linestring) it_point = InterventionFactory.create(target=topo_point) it_line = InterventionFactory.create(target=topo_line) # reload it_point = type(it_point).objects.get(pk=it_point.pk) it_line = type(it_line).objects.get(pk=it_line.pk) proj = ProjectFactory.create() proj.interventions.add(it_point) proj.interventions.add(it_line) # instanciate the class based view 'abnormally' to use create_shape directly # to avoid making http request, authent and reading from a zip pfl = ZipShapeSerializer() shapefiles = pfl.path_directory devnull = open(os.devnull, "wb") pfl.serialize(Project.objects.all(), stream=devnull, delete=False, fields=ProjectFormatList.columns) shapefiles = [shapefile for shapefile in os.listdir(shapefiles) if shapefile[-3:] == "shp"] datasources = [gdal.DataSource(os.path.join(pfl.path_directory, s)) for s in shapefiles] layers = [ds[0] for ds in datasources] self.assertEqual(len(datasources), 2) geom_type_layer = {layer.name: layer for layer in layers} geom_types = geom_type_layer.keys() self.assertIn('MultiPoint', geom_types) self.assertIn('MultiLineString', geom_types) for layer in layers: self.assertEqual(layer.srs.name, 'RGF93_Lambert_93') self.assertCountEqual(layer.fields, [ 'id', 'name', 'period', 'type', 'domain', 'constraint', 'global_cos', 'interventi', 'comments', 'contractor', 'project_ow', 'project_ma', 'founders', 'related_st', 'insertion_', 'update_dat', 'cities', 'districts', 'restricted' ]) self.assertEqual(len(layers[0]), 1) self.assertEqual(len(layers[1]), 1) for feature in geom_type_layer['MultiPoint']: self.assertEqual(str(feature['id']), str(proj.pk)) self.assertEqual(len(feature.geom.geos), 1) self.assertAlmostEqual(feature.geom.geos[0].x, it_point.geom.x) self.assertAlmostEqual(feature.geom.geos[0].y, it_point.geom.y) for feature in geom_type_layer['MultiLineString']: self.assertEqual(str(feature['id']), str(proj.pk)) self.assertTrue(feature.geom.geos.equals(it_line.geom))
def test_mandays(self): i = InterventionFactory.create() ManDayFactory.create(intervention=i, nb_days=5) ManDayFactory.create(intervention=i, nb_days=8) self.assertEqual(i.total_manday, 14) # intervention haz a default manday
def test_topology_has_intervention_kind(self): topo = TopologyFactory.create() self.assertEqual('TOPOLOGY', topo.kind) i = InterventionFactory.create(target_id=topo.pk) self.assertEqual('TOPOLOGY', i.target.kind)