Ejemplo n.º 1
0
    def test_update_form_on_infrastructure(self):
        self.login()

        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create()
        else:
            infra = InfrastructureFactory.create(
                geom='SRID=2154;POINT (700000 6600000)')
        infrastr = "%s" % infra

        intervention = InterventionFactory.create(target=infra)
        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['disorders'] = data['disorders'][0].pk
        data['project'] = ''
        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 = '%s?target_id=%s&target_type=%s' % (Intervention.get_add_url(
        ), infra.pk, ContentType.objects.get_for_model(Infrastructure).pk)
        response = self.client.post(formurl, data)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 2
0
    def test_unset_structure_without_structure_keep_pk(self):
        structure = StructureFactory.create(name="Test")
        infratype_no_structure = InfrastructureTypeFactory.create(
            label="type1", structure=None, pictogram=None)
        InfrastructureFactory.create(name='infra1',
                                     type=infratype_no_structure)
        infratype_structure = InfrastructureTypeFactory.create(
            label="type2", structure=structure, pictogram=None)
        InfrastructureFactory.create(name='infra2', type=infratype_structure)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertIsNone(infratype_no_structure.structure)
        self.assertIsNotNone(infratype_structure.structure)
        old_pk_no_structure = infratype_no_structure.pk
        old_pk_structure = infratype_structure.pk
        call_command('unset_structure', '--all', verbosity=0)
        type1 = InfrastructureType.objects.get(label="type1")
        type2 = InfrastructureType.objects.get(label="type1")
        new_pk_no_structure = type1.pk
        new_pk_structure = type2.pk

        self.assertEqual(old_pk_no_structure, new_pk_no_structure)
        self.assertNotEqual(old_pk_structure, new_pk_structure)

        self.assertIsNone(type1.structure)
        self.assertIsNone(type2.structure)
Ejemplo n.º 3
0
    def test_none_implantation_year_filter(self):

        self.login()
        model = self.factory._meta.model
        InfrastructureFactory.create()
        response = self.client.get(model.get_list_url())
        self.assertFalse('option value="" selected>None</option' in str(response))
Ejemplo n.º 4
0
    def test_creation_form_on_infrastructure_with_errors(self):
        self.login()

        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create()
        else:
            infra = InfrastructureFactory.create(
                geom='SRID=2154;POINT (700000 6600000)')
        infrastr = "%s" % infra

        response = self.client.get(
            '%s?target_id=%s&target_type=%s' %
            (Intervention.get_add_url(), infra.pk,
             ContentType.objects.get_for_model(Infrastructure).pk))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, infrastr)
        data = self.get_good_data()

        # If form invalid, it should not fail
        data.pop('status')
        response = self.client.post(
            '%s?target_id=%s&target_type=%s' %
            (Intervention.get_add_url(), infra.pk,
             ContentType.objects.get_for_model(Infrastructure).pk), data)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 5
0
    def test_update_form_on_infrastructure(self):
        self.login()

        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create()
        else:
            infra = InfrastructureFactory.create(
                geom='SRID=2154;POINT (700000 6600000)')
        infrastr = "%s" % infra

        intervention = InterventionFactory.create()
        intervention.set_topology(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['disorders'] = data['disorders'][0].pk
        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)
Ejemplo n.º 6
0
 def create_trek_with_infrastructures(obj, create, extracted, **kwargs):
     path = obj.paths.all()[0]
     infra1 = InfrastructureFactory.create(no_path=True)
     infra1.add_path(path, start=0.5, end=0.5)
     infra2 = InfrastructureFactory.create(no_path=True)
     infra2.add_path(path, start=0.4, end=0.4)
     if create:
         obj.save()
Ejemplo n.º 7
0
    def test_none_implantation_year_filter(self):

        self.login()
        model = self.factory._meta.model
        InfrastructureFactory.create()
        response = self.client.get(model.get_list_url())
        self.assertFalse(
            'option value="" selected>None</option' in str(response))
Ejemplo n.º 8
0
 def create_trek_with_infrastructures(obj, create, extracted, **kwargs):
     path = obj.paths.all()[0]
     infra1 = InfrastructureFactory.create(no_path=True)
     infra1.add_path(path, start=0.5, end=0.5)
     infra2 = InfrastructureFactory.create(no_path=True)
     infra2.add_path(path, start=0.4, end=0.4)
     if create:
         obj.save()
Ejemplo n.º 9
0
    def test_helpers(self):
        p = PathFactory.create()

        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create(paths=[p])
        else:
            infra = InfrastructureFactory.create(geom=p.geom)

        self.assertCountEqual(p.infrastructures, [infra])
Ejemplo n.º 10
0
    def create_infrastructure_point_intervention(obj, create, extracted, **kwargs):
        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create(no_path=True)

            infra.add_path(PathFactory.create(), start=0.5, end=0.5)
        else:
            infra = InfrastructureFactory.create(geom='SRID=2154;POINT (700040 6600040)')
        obj.set_topology(infra)
        if create:
            obj.save()
Ejemplo n.º 11
0
    def test_detail_target_objects(self):
        self.login()
        if settings.TREKKING_TOPOLOGY_ENABLED:
            path = PathFactory.create(geom=LineString((200, 200), (300, 300)))
            signa = SignageFactory.create(paths=[(path, .5, .5)])
            signa.save()
            infrastructure = InfrastructureFactory.create(paths=[(path, .5,
                                                                  .5)])
            infrastructure.save()
            poi = POIFactory.create(paths=[(path, .5, .5)])
            trek = TrekFactory.create(paths=[(path, .5, .5)])
            service = ServiceFactory.create(paths=[(path, .5, .5)])
            topo = TopologyFactory.create(paths=[(path, .5, .5)])
            topo.save()

            path_other = PathFactory.create(
                geom=LineString((10000, 0), (10010, 0)))
            signa_other = SignageFactory.create(paths=[(path_other, .5, .5)])
            signa_other.save()
        else:
            signa = SignageFactory.create(geom='SRID=2154;POINT (250 250)')
            infrastructure = InfrastructureFactory.create(
                geom='SRID=2154;POINT (250 250)')
            poi = POIFactory.create(geom='SRID=2154;POINT (250 250)')
            trek = TrekFactory.create(geom='SRID=2154;POINT (250 250)')
            service = ServiceFactory.create(geom='SRID=2154;POINT (250 250)')
            topo = TopologyFactory.create(geom='SRID=2154;POINT (250 250)')

            signa_other = SignageFactory.create(
                geom='SRID=2154;POINT (10005 0)')

        intervention_signa = InterventionFactory.create(target=signa)
        intervention_infra = InterventionFactory.create(target=infrastructure)
        intervention_poi = InterventionFactory.create(target=poi)
        intervention_trek = InterventionFactory.create(target=trek)
        intervention_service = InterventionFactory.create(target=service)
        intervention_topo = InterventionFactory.create(target=topo)
        blade = BladeFactory(signage=signa, number="1")
        intervention_blade = InterventionFactory.create(target=blade)

        intervention_other = InterventionFactory.create(target=signa_other)

        response = self.client.get(signa.get_detail_url())
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, intervention_signa.target_display)
        self.assertContains(response, intervention_infra.target_display)
        self.assertContains(response, intervention_poi.target_display)
        self.assertContains(response, intervention_trek.target_display)
        self.assertContains(response, intervention_service.target_display)
        self.assertContains(response, intervention_blade.target_display)
        self.assertContains(response, intervention_topo.target_display)

        self.assertNotContains(response, intervention_other.target_display)
Ejemplo n.º 12
0
    def create_infrastructure_point_intervention(obj, create, extracted,
                                                 **kwargs):
        if settings.TREKKING_TOPOLOGY_ENABLED:
            infra = InfrastructureFactory.create(paths=[(PathFactory.create(),
                                                         0.5, 0.5)])

        else:
            infra = InfrastructureFactory.create(
                geom='SRID=2154;POINT (700040 6600040)')
        obj.target = infra
        if create:
            obj.save()
Ejemplo n.º 13
0
    def test_implantation_year_filter(self):
        filter = InfrastructureFilterSet(data={'implantation_year': 2015})
        self.login()
        model = self.factory._meta.model
        i = InfrastructureFactory.create(implantation_year=2015)
        i2 = InfrastructureFactory.create(implantation_year=2016)
        response = self.client.get(model.get_list_url())

        self.assertTrue('<option value="2015">2015</option>' in str(response))
        self.assertTrue('<option value="2016">2016</option>' in str(response))

        self.assertTrue(i in filter.qs)
        self.assertFalse(i2 in filter.qs)
Ejemplo n.º 14
0
    def test_implantation_year_filter_with_str(self):
        filter = InfrastructureFilterSet(data={'implantation_year': 'toto'})
        self.login()
        model = self.factory._meta.model
        i = InfrastructureFactory.create(implantation_year=2015)
        i2 = InfrastructureFactory.create(implantation_year=2016)
        response = self.client.get(model.get_list_url())

        self.assertContains(response, '<option value="2015">2015</option>')
        self.assertContains(response, '<option value="2016">2016</option>')

        self.assertIn(i, filter.qs)
        self.assertIn(i2, filter.qs)
Ejemplo n.º 15
0
    def test_implantation_year_filter_with_str(self):
        filter = InfrastructureFilterSet(data={'implantation_year': 'toto'})
        self.login()
        model = self.factory._meta.model
        i = InfrastructureFactory.create(implantation_year=2015)
        i2 = InfrastructureFactory.create(implantation_year=2016)
        response = self.client.get(model.get_list_url())

        self.assertTrue('<option value="2015">2015</option>' in str(response))
        self.assertTrue('<option value="2016">2016</option>' in str(response))

        self.assertIn(i, filter.qs)
        self.assertIn(i2, filter.qs)
Ejemplo n.º 16
0
    def test_command_unset_structure(self):
        structure1 = StructureFactory.create(name="coucou")
        structure2 = StructureFactory.create(name="coco")

        infratype1 = InfrastructureTypeFactory.create(label="annyeong",
                                                      structure=structure1,
                                                      pictogram=None)
        infratype2 = InfrastructureTypeFactory.create(label="annyeong",
                                                      structure=structure2,
                                                      pictogram=None)

        path = PathFactory.create(name="pass")
        usage1 = UsageFactory.create(usage="hello", structure=structure1)
        usage2 = UsageFactory.create(usage="hello", structure=structure2)
        path.usages.add(usage1)
        path.usages.add(usage2)

        infrastructure1 = InfrastructureFactory.create(name='pissenlit',
                                                       type=infratype1)
        infrastructure2 = InfrastructureFactory.create(name='rhododendron',
                                                       type=infratype2)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertEqual(Usage.objects.count(), 2)

        self.assertEqual(infrastructure1.type.label, 'annyeong')
        self.assertEqual(infrastructure1.type.structure.name, 'coucou')
        self.assertEqual(infrastructure2.type.label, 'annyeong')
        self.assertEqual(infrastructure2.type.structure.name, 'coco')

        self.assertEqual(path.usages.count(), 2)
        self.assertEqual(usage1.structure.name, 'coucou')
        self.assertEqual(usage2.structure.name, 'coco')
        output = StringIO()
        call_command('unset_structure', '--all', verbosity=2, stdout=output)
        response = output.getvalue()
        self.assertIn("Create hello", response)
        self.assertEqual(InfrastructureType.objects.count(), 1)
        self.assertEqual(Usage.objects.count(), 1)

        infra = Infrastructure.objects.first()

        self.assertEqual(infra.type.label, 'annyeong')
        self.assertEqual(infra.type.structure, None)

        path_usages = Path.objects.first().usages.first()

        self.assertEqual(path_usages.usage, 'hello')
        self.assertEqual(path_usages.structure, None)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
 def _prepare(cls, create, **kwargs):
     intervention = super(InfrastructureInterventionFactory, cls)._prepare(create, **kwargs)
     infra = InfrastructureFactory.create()
     intervention.set_infrastructure(infra)
     if create:
         intervention.save()
     return intervention
Ejemplo n.º 19
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])
Ejemplo n.º 20
0
 def test_delete_topology(self):
     infra = InfrastructureFactory.create()
     interv = InterventionFactory.create(target=infra)
     interv.save()
     infra.delete()
     self.assertEqual(Infrastructure.objects.existing().count(), 0)
     self.assertEqual(Intervention.objects.existing().count(), 0)
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
    def test_helpers(self):
        p = PathFactory.create()

        infra = InfrastructureFactory.create(no_path=True)
        infra.add_path(path=p)

        self.assertItemsEqual(p.infrastructures, [infra])
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
 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_load_infrastructure(self):
     output = StringIO()
     structure = StructureFactory.create(name='structure')
     filename = os.path.join(os.path.dirname(__file__), 'data',
                             'signage.shp')
     building = InfrastructureFactory(name="name", implantation_year=2010)
     call_command('loadinfrastructure',
                  filename,
                  '--infrastructure',
                  type_default='label',
                  name_default='name',
                  condition_default='condition',
                  structure_default='structure',
                  description_default='description',
                  year_default=2010,
                  verbosity=2,
                  stdout=output)
     self.assertIn('Infrastructures will be linked to %s' % structure,
                   output.getvalue())
     self.assertIn('2 objects created.', output.getvalue())
     value = Infrastructure.objects.all()
     self.assertEquals(building.name, value[1].name)
     self.assertEquals(building.implantation_year,
                       value[1].implantation_year)
     self.assertEquals(value.count(), 3)
Ejemplo n.º 27
0
    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_load_infrastructure_with_fields(self):
     output = StringIO()
     structure = StructureFactory.create(name='structure')
     filename = os.path.join(os.path.dirname(__file__), 'data',
                             'signage.shp')
     InfrastructureFactory(name="name")
     call_command('loadinfrastructure',
                  filename,
                  '--infrastructure',
                  type_field='label',
                  name_field='name',
                  condition_field='condition',
                  structure_default='structure',
                  description_field='descriptio',
                  year_field='year',
                  verbosity=1,
                  stdout=output)
     self.assertIn('Infrastructures will be linked to %s' % structure,
                   output.getvalue())
     self.assertIn("InfrastructureType 'type' created", output.getvalue())
     self.assertIn("Condition Type 'condition' created", output.getvalue())
     value = Infrastructure.objects.all()
     names = [val.name for val in value]
     years = [val.implantation_year for val in value]
     self.assertIn('coucou', names)
     self.assertIn(2010, years)
     self.assertIn(2012, years)
     self.assertEquals(value.count(), 3)
Ejemplo n.º 29
0
    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_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_topology(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_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)
Ejemplo n.º 33
0
 def create_infrastructure_point_intervention(obj, create, extracted,
                                              **kwargs):
     infra = InfrastructureFactory.create(no_path=True)
     infra.add_path(PathFactory.create(), start=0.5, end=0.5)
     obj.set_infrastructure(infra)
     if create:
         obj.save()
Ejemplo n.º 34
0
 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)
Ejemplo n.º 35
0
 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)
Ejemplo n.º 36
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)
Ejemplo n.º 37
0
    def test_helpers(self):
        p = PathFactory.create()

        infra = InfrastructureFactory.create(no_path=True)
        infra.add_path(path=p)

        self.assertCountEqual(p.infrastructures, [infra])
Ejemplo n.º 38
0
    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])
 def test_update_same_eid(self):
     output = StringIO()
     filename = os.path.join(os.path.dirname(__file__), 'data', 'infrastructure.shp')
     InfrastructureFactory(name="name", eid="eid_2")
     call_command('loadinfrastructure', filename, eid_field='eid', type_default='label',
                  name_default='name', verbosity=2, stdout=output)
     self.assertIn("Update : name with eid eid1", output.getvalue())
     self.assertEqual(Infrastructure.objects.count(), 2)
Ejemplo n.º 40
0
 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)
Ejemplo n.º 41
0
 def _prepare(cls, create, **kwargs):
     intervention = super(InfrastructurePointInterventionFactory, cls)._prepare(create, **kwargs)
     infra = InfrastructureFactory.create(no_path=True)
     infra.add_path(PathFactory.create(), start=0.5, end=0.5)
     intervention.set_infrastructure(infra)
     if create:
         intervention.save()
     return intervention
Ejemplo n.º 42
0
 def create_trek_with_infrastructures(obj, create, extracted, **kwargs):
     if settings.TREKKING_TOPOLOGY_ENABLED:
         path = obj.paths.all()[0]
         InfrastructureFactory.create(paths=[(path, 0.5, 0.5)])
         InfrastructureFactory.create(paths=[(path, 0.4, 0.4)])
         if create:
             obj.save()
     else:
         InfrastructureFactory.create(geom='SRID=2154;POINT (700040 6600040)')
         InfrastructureFactory.create(geom='SRID=2154;POINT (700050 6600050)')
Ejemplo n.º 43
0
 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)
Ejemplo n.º 44
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)
Ejemplo n.º 45
0
    def test_command_unset_structure(self):
        structure1 = StructureFactory.create(name="coucou")
        structure2 = StructureFactory.create(name="coco")

        infratype1 = InfrastructureTypeFactory.create(label="annyeong", structure=structure1, pictogram=None)
        infratype2 = InfrastructureTypeFactory.create(label="annyeong", structure=structure2, pictogram=None)

        path = PathFactory.create(name="pass")
        usage1 = UsageFactory.create(usage="hello", structure=structure1)
        usage2 = UsageFactory.create(usage="hello", structure=structure2)
        path.usages.add(usage1)
        path.usages.add(usage2)

        infrastructure1 = InfrastructureFactory.create(name='pissenlit', type=infratype1)
        infrastructure2 = InfrastructureFactory.create(name='rhododendron', type=infratype2)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertEqual(Usage.objects.count(), 2)

        self.assertEqual(infrastructure1.type.label, 'annyeong')
        self.assertEqual(infrastructure1.type.structure.name, 'coucou')
        self.assertEqual(infrastructure2.type.label, 'annyeong')
        self.assertEqual(infrastructure2.type.structure.name, 'coco')

        self.assertEqual(path.usages.count(), 2)
        self.assertEqual(usage1.structure.name, 'coucou')
        self.assertEqual(usage2.structure.name, 'coco')
        output = StringIO()
        call_command('unset_structure', '--all', verbosity=2, stdout=output)
        response = output.getvalue()
        self.assertIn("Create hello", response)
        self.assertEqual(InfrastructureType.objects.count(), 1)
        self.assertEqual(Usage.objects.count(), 1)

        infra = Infrastructure.objects.first()

        self.assertEqual(infra.type.label, 'annyeong')
        self.assertEqual(infra.type.structure, None)

        path_usages = Path.objects.first().usages.first()

        self.assertEqual(path_usages.usage, 'hello')
        self.assertEqual(path_usages.structure, None)
Ejemplo n.º 46
0
    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)
Ejemplo n.º 47
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, [])
Ejemplo n.º 48
0
    def test_helpers(self):
        p = PathFactory.create()

        self.assertEquals(len(p.infrastructures), 0)
        sign = SignageFactory.create(no_path=True)
        PathAggregationFactory.create(topo_object=sign, path=p, start_position=0.5, end_position=0.5)

        self.assertItemsEqual(p.signages, [sign])

        infra = InfrastructureFactory.create(no_path=True)
        PathAggregationFactory.create(topo_object=infra, path=p)

        self.assertItemsEqual(p.infrastructures, [infra])
Ejemplo n.º 49
0
    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)
Ejemplo n.º 50
0
    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)
Ejemplo n.º 51
0
    def test_creation_form_on_infrastructure(self):
        self.login()

        infra = InfrastructureFactory.create()
        infrastr = u"%s" % infra

        response = self.client.get(Intervention.get_add_url() + '?infrastructure=%s' % infra.pk)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, infrastr)
        form = response.context['form']
        self.assertEqual(form.initial['infrastructure'], infra)
        # Should be able to save form successfully
        data = self.get_good_data()
        data['infrastructure'] = infra.pk
        response = self.client.post(Intervention.get_add_url() + '?infrastructure=%s' % infra.pk, data)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 52
0
    def test_creation_form_on_infrastructure_with_errors(self):
        self.login()

        infra = InfrastructureFactory.create()
        infrastr = u"%s" % infra

        response = self.client.get(Intervention.get_add_url() + '?infrastructure=%s' % infra.pk)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, infrastr)
        form = response.context['form']
        self.assertEqual(form.initial['infrastructure'], infra)
        data = self.get_good_data()
        data['infrastructure'] = infra.pk

        # If form invalid, it should not fail
        data.pop('status')
        response = self.client.post(Intervention.get_add_url() + '?infrastructure=%s' % infra.pk, data)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 53
0
    def setUp(self):
        self.source_a = RecordSourceFactory()
        self.source_b = RecordSourceFactory()

        self.portal_a = TargetPortalFactory()
        self.portal_b = TargetPortalFactory()
        information_desks = InformationDeskFactory.create()
        self.trek_1 = TrekWithPublishedPOIsFactory.create(sources=(self.source_a, ),
                                                          portals=(self.portal_b,),
                                                          published=True)
        self.trek_1.information_desks.add(information_desks)
        self.attachment_1 = AttachmentFactory.create(content_object=self.trek_1,
                                                     attachment_file=get_dummy_uploaded_image())
        self.trek_2 = TrekFactory.create(sources=(self.source_b,),
                                         published=True)
        self.trek_3 = TrekFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True)
        self.trek_4 = TrekFactory.create(portals=(self.portal_a,),
                                         published=True)

        self.poi_1 = trek_models.POI.objects.first()
        self.attachment_poi_image_1 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_image_2 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_file = AttachmentFactory.create(content_object=self.poi_1,
                                                            attachment_file=get_dummy_uploaded_file())

        infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
        infrastructure.add_path(self.trek_1.paths.first(), start=0, end=0)
        signage = SignageFactory.create(no_path=True, name="SIGNA_1")
        signage.add_path(self.trek_1.paths.first(), start=0, end=0)
        SensitiveAreaFactory.create(published=True)
        self.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        self.attachment_touristic_content = AttachmentFactory.create(content_object=self.touristic_content,
                                                                     attachment_file=get_dummy_uploaded_image())
        self.attachment_touristic_event = AttachmentFactory.create(content_object=self.touristic_event,
                                                                   attachment_file=get_dummy_uploaded_image())
Ejemplo n.º 54
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])
Ejemplo n.º 55
0
 def test_description_in_detail_page(self):
     infra = InfrastructureFactory.create(description="<b>Beautiful !</b>")
     self.login()
     response = self.client.get(infra.get_detail_url())
     self.assertContains(response, "<b>Beautiful !</b>")
Ejemplo n.º 56
0
 def create_infrastructure_point_intervention(obj, create, extracted, **kwargs):
     infra = InfrastructureFactory.create(no_path=True)
     infra.add_path(PathFactory.create(), start=0.5, end=0.5)
     obj.set_topology(infra)
     if create:
         obj.save()
Ejemplo n.º 57
0
 def create_infrastructure_intervention(obj, create, extracted, **kwargs):
     infra = InfrastructureFactory.create()
     obj.set_topology(infra)
     if create:
         obj.save()