def test_project_bbox_filter(self):
        self.login()

        p1 = ProjectFactory.create()
        ProjectFactory.create()
        ProjectFactory.create()
        if settings.TREKKING_TOPOLOGY_ENABLED:
            t = TopologyFactory.create()
        else:
            t = TopologyFactory.create(geom='SRID=2154;POINT (700000 6600000)')
        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 = response.json()
            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 create_pair_of_distinct_by_topo_project(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)

        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
Esempio n. 3
0
    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_filter_by_year(self):
     project = ProjectFactory.create(begin_year=2015, end_year=2017)
     ProjectFactory.create(begin_year=2011, end_year=2013)
     filterset = ProjectFilterSet(data={'year': [2016]})
     self.assertTrue(filterset.is_valid(), filterset.errors)
     self.assertEqual(len(filterset.qs), 1)
     self.assertEqual(filterset.qs[0], project)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
 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])
Esempio n. 8
0
 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])
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
    def setUpTestData(cls):
        p1 = PathFactory()
        cls.seek_path = PathFactory(geom=getRandomLineStringInBounds())

        topo_1 = TopologyFactory.create(paths=[p1])
        seek_topo = TopologyFactory.create(paths=[cls.seek_path])

        it_p1 = InterventionFactory.create(target=topo_1)
        seek_it = InterventionFactory.create(target=seek_topo)

        cls.seek_proj = ProjectFactory.create()
        cls.seek_proj.interventions.add(seek_it)

        proj_1 = ProjectFactory.create()
        proj_1.interventions.add(it_p1)
Esempio n. 12
0
    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_path_helpers(self):
        p = PathFactory.create()

        self.assertEqual(len(p.interventions), 0)
        self.assertEqual(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_topology(sign)
        i1.save()

        self.assertCountEqual(p.interventions, [i1])

        i2 = InterventionFactory.create()
        i2.set_topology(infra)
        i2.save()

        self.assertCountEqual(p.interventions, [i1, i2])

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        proj.interventions.add(i2)

        self.assertCountEqual(p.projects, [proj])
    def test_helpers(self):
        infra = InfrastructureFactory.create()
        sign = SignageFactory.create()
        interv = InterventionFactory.create()
        proj = ProjectFactory.create()

        self.assertFalse(interv.on_existing_topology)
        self.assertEqual(interv.infrastructure, None)

        interv.set_topology(infra)
        self.assertTrue(interv.on_existing_topology)
        self.assertFalse(interv.is_signage)
        self.assertTrue(interv.is_infrastructure)
        self.assertEqual(interv.signages, [])
        self.assertEqual(interv.infrastructures, [infra])
        self.assertEqual(interv.infrastructure, infra)

        interv.set_topology(sign)
        self.assertTrue(interv.on_existing_topology)
        self.assertTrue(interv.is_signage)
        self.assertFalse(interv.is_infrastructure)
        self.assertEqual(interv.signages, [sign])
        self.assertEqual(interv.infrastructures, [])
        self.assertEqual(interv.signage, sign)

        self.assertFalse(interv.in_project)
        interv.project = proj
        self.assertTrue(interv.in_project)
Esempio n. 15
0
    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)
Esempio n. 16
0
 def test_filter_out_district(self):
     filter = ProjectFilterSet(
         data={'district': [DistrictFactory.create(geom=self.geom_zoning)]})
     project_out = ProjectFactory.create()
     project_out.interventions.add(self.intervention_out)
     self.assertTrue(filter.is_valid())
     self.assertEqual(len(filter.qs), 0)
    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_topology(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)
Esempio n. 18
0
    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_helpers_nds(self):
        i1 = InterventionFactory.create()
        i2 = InterventionFactory.create()
        i3 = InterventionFactory.create()
        sign = SignageFactory.create(geom="SRID=4326;POINT(0 5)")
        i1.set_topology(sign)

        infra = InfrastructureFactory.create(geom="SRID=4326;POINT(1 5)")
        i2.set_topology(infra)

        t = TopologyFactory.create(geom="SRID=4326;POINT(2 5)")
        i3.topology = t

        proj = ProjectFactory.create()
        self.assertCountEqual(proj.paths.all(), [])
        self.assertEqual(proj.signages, [])
        self.assertEqual(proj.infrastructures, [])

        i1.save()

        proj.interventions.add(i1)
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [])

        i2.save()

        proj.interventions.add(i2)
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])

        i3.save()

        proj.interventions.add(i3)
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])
Esempio n. 20
0
 def test_filter_in_city(self):
     filter = ProjectFilterSet(
         data={'city': [CityFactory.create(geom=self.geom_zoning)]})
     project_in = ProjectFactory.create()
     project_in.interventions.add(self.intervention_in)
     self.assertTrue(filter.is_valid())
     self.assertIn(project_in, filter.qs)
     self.assertEqual(len(filter.qs), 1)
Esempio n. 21
0
    def test_project_layer(self):
        self.login()
        p1 = ProjectFactory.create()
        ProjectFactory.create()
        if settings.TREKKING_TOPOLOGY_ENABLED:
            InterventionFactory.create(project=p1)
        else:
            InterventionFactory.create(project=p1, geom='SRID=2154;POINT (700000 6600000)')

        # Check that only p1 is in geojson
        response = self.client.get(self.model.get_layer_url())
        self.assertEqual(response.status_code, 200)
        geojson = response.json()
        features = geojson['features']

        self.assertEqual(len(Project.objects.all()), 2)
        self.assertEqual(len(features), 1)
        self.assertEqual(features[0]['properties']['pk'], p1.pk)
Esempio n. 22
0
    def test_deleted_intervention(self):
        sign = SignageFactory.create()
        i1 = InterventionFactory.create(target=sign)

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        self.assertEqual(proj.signages, [sign])
        i1.delete()
        self.assertEqual(proj.signages, [])
Esempio n. 23
0
    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
Esempio n. 24
0
    def test_deleted_infrastructure(self):
        infra = InfrastructureFactory.create()
        i1 = InterventionFactory.create(target=infra)

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        self.assertEqual(proj.infrastructures, [infra])

        infra.delete()

        self.assertEqual(proj.infrastructures, [])
    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.assertEqual(proj.signages, [sign])
        i1.delete()
        self.assertEqual(proj.signages, [])
Esempio n. 26
0
    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, [])
Esempio n. 27
0
    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, [])
Esempio n. 28
0
    def test_deleted_intervention(self):
        i1 = InterventionFactory.create()
        sign = SignageFactory.create()
        i1.set_infrastructure(sign)

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        self.assertEquals(proj.signages, [sign])

        i1.delete()

        self.assertEquals(proj.signages, [])
    def test_deleted_infrastructure(self):
        i1 = InterventionFactory.create()
        infra = InfrastructureFactory.create()
        i1.set_topology(infra)
        i1.save()

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        self.assertEqual(proj.infrastructures, [infra])

        infra.delete()

        self.assertEqual(proj.infrastructures, [])
Esempio n. 30
0
    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)
Esempio n. 31
0
    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)
Esempio n. 32
0
    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)
Esempio n. 33
0
    def setUp(self):
        infra = InfrastructureFactory.create()
        self.intervention = InterventionFactory.create(target=infra)
        self.project = ProjectFactory.create()
        self.project.interventions.add(self.intervention)
        self.project.interventions.add(InterventionFactory.create())

        path = infra.paths.get()

        self.signagemgt = SignageManagementEdgeFactory.create(paths=[(path, 0.3, 0.7)])
        self.workmgt = WorkManagementEdgeFactory.create(paths=[(path, 0.3, 0.7)])
        self.competencemgt = CompetenceEdgeFactory.create(paths=[(path, 0.3, 0.7)])

        self.cityedge = CityEdgeFactory.create(paths=[(path, 0.3, 0.7)])
        self.districtedge = DistrictEdgeFactory.create(paths=[(path, 0.3, 0.7)])
        self.restricted = RestrictedAreaEdgeFactory.create(paths=[(path, 0.3, 0.7)])
Esempio n. 34
0
    def test_deleted_interventions(self):
        project = ProjectFactory.create()
        if settings.TREKKING_TOPOLOGY_ENABLED:
            intervention = InterventionFactory.create()
        else:
            intervention = InterventionFactory.create(geom='SRID=2154;POINT (700000 6600000)')
        project.interventions.add(intervention)

        self.login()
        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)
Esempio n. 35
0
    def test_helpers(self):
        i1 = InterventionFactory.create(target=None)
        i2 = InterventionFactory.create(target=None)
        i3 = InterventionFactory.create(target=None)
        sign = SignageFactory.create()
        i1.target = sign
        i1.save()

        p1 = sign.paths.get()

        infra = InfrastructureFactory.create()
        i2.target = infra
        i2.save()
        p2 = infra.paths.get()

        t = TopologyFactory.create(paths=[p1])
        i3.target = t

        proj = ProjectFactory.create()
        self.assertCountEqual(proj.paths.all(), [])
        self.assertEqual(proj.signages, [])
        self.assertEqual(proj.infrastructures, [])

        i1.save()

        proj.interventions.add(i1)
        self.assertCountEqual(proj.paths.all(), [p1])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [])

        i2.save()

        proj.interventions.add(i2)
        self.assertCountEqual(proj.paths.all(), [p1, p2])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])

        i3.save()

        proj.interventions.add(i3)
        self.assertCountEqual(proj.paths.all(), [p1, p2])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])
Esempio n. 36
0
    def test_helpers(self):
        infra = InfrastructureFactory.create()
        sign = SignageFactory.create()
        interv = InterventionFactory.create(target=infra)
        proj = ProjectFactory.create()

        self.assertEqual(interv.target, infra)

        self.assertEqual(interv.signages, [])
        self.assertEqual(interv.infrastructures, [infra])

        interv.target = sign
        interv.save()

        self.assertEqual(interv.signages, [sign])
        self.assertEqual(interv.infrastructures, [])

        self.assertFalse(interv.in_project)
        interv.project = proj
        self.assertTrue(interv.in_project)
    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.assertCountEqual(proj.paths.all(), [])
        self.assertEqual(proj.signages, [])
        self.assertEqual(proj.infrastructures, [])

        i1.save()

        proj.interventions.add(i1)
        self.assertCountEqual(proj.paths.all(), [p1])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [])

        i2.save()

        proj.interventions.add(i2)
        self.assertCountEqual(proj.paths.all(), [p1, p2])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])

        i3.save()

        proj.interventions.add(i3)
        self.assertCountEqual(proj.paths.all(), [p1, p2])
        self.assertEqual(proj.signages, [sign])
        self.assertEqual(proj.infrastructures, [infra])
Esempio n. 38
0
    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])
Esempio n. 39
0
    def test_path_helpers(self):
        p = PathFactory.create()

        self.assertEqual(len(p.interventions), 0)
        self.assertEqual(len(p.projects), 0)

        sign = SignageFactory.create(paths=[p])

        infra = InfrastructureFactory.create(paths=[p])

        i1 = InterventionFactory.create(target=sign)

        self.assertCountEqual(p.interventions, [i1])

        i2 = InterventionFactory.create(target=infra)

        self.assertCountEqual(p.interventions, [i1, i2])

        proj = ProjectFactory.create()
        proj.interventions.add(i1)
        proj.interventions.add(i2)

        self.assertCountEqual(p.projects, [proj])
Esempio n. 40
0
 def test_new_projects_can_be_filtered_on_new_years(self):
     filter = ProjectFilterSet(data={'in_year': 1250})
     p = ProjectFactory.create(begin_year=1200, end_year=1300)
     self.assertIn(p, filter.qs)
     self.assertEqual(len(filter.qs), 1)
Esempio n. 41
0
    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)
Esempio n. 42
0
 def setUp(self):
     ProjectFactory.create(begin_year=1500, end_year=2000)
     ProjectFactory.create(begin_year=1700, end_year=1800)
     self.filter = ProjectFilterSet()
     self.widget = self.filter.filters['year'].field.widget
Esempio n. 43
0
 def test_filter_year_with_string(self):
     filter = ProjectFilterSet(data={'year': 'toto'})
     p = ProjectFactory.create(begin_year=1200, end_year=1300)
     self.assertIn(p, filter.qs)
     self.assertEqual(len(filter.qs), 3)
Esempio n. 44
0
 def setUp(self):
     ProjectFactory.create(begin_year=1500, end_year=2000)
     ProjectFactory.create(begin_year=1700, end_year=1800)
     self.filter = ProjectFilterSet()
     self.widget = self.filter.filters['in_year'].field.widget
Esempio n. 45
0
 def test_filter_year_with_string(self):
     filter = ProjectFilterSet(data={'in_year': 'toto'})
     p = ProjectFactory.create(begin_year=1200, end_year=1300)
     self.assertIn(p, filter.qs)
     self.assertEqual(len(filter.qs), 3)
Esempio n. 46
0
 def test_new_interventions_appear_dynamically(self):
     ProjectFactory.create(begin_year=1500, end_year=2100)
     output = self.widget.render(name='year', value=None)
     self.assertEqual(output.count('<option'), 6)
     self.assertIn('>2100<', output)
Esempio n. 47
0
    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.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)
Esempio n. 48
0
    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)

        shp_creator = shape_exporter.ShapeCreator()

        #  instanciate the class based view 'abnormally' to use create_shape directly
        # to avoid making http request, authent and reading from a zip
        pfl = ZipShapeSerializer()
        pfl.create_shape(shp_creator, Project.objects.all(), ProjectFormatList.columns)

        self.assertEquals(len(shp_creator.shapes), 2)

        ds_point = gdal.DataSource(shp_creator.shapes[0][1])
        layer_point = ds_point[0]
        ds_line = gdal.DataSource(shp_creator.shapes[1][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))