Ejemplo n.º 1
0
    def test_helpers(self):

        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        trek = TrekFactory.create(paths=[(p1, 0.5, 1), (p2, 0, 1)])
        poi = POIFactory.create(paths=[(p1, 0.6, 0.6)])
        poi2 = POIFactory.create(paths=[(p1, 0.6, 0.6)])
        service = ServiceFactory.create(paths=[(p1, 0.7, 0.7)])
        service.type.practices.add(trek.practice)
        trek.pois_excluded.add(poi2.pk)

        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))
        # Ensure related objects are accessible
        self.assertCountEqual(trek.pois_excluded.all(), [poi2])
        self.assertCountEqual(trek.all_pois, [poi, poi2])
        self.assertCountEqual(trek.pois, [poi])
        self.assertCountEqual(trek.services, [service])
        self.assertCountEqual(poi.treks, [trek])
        self.assertCountEqual(service.treks, [trek])
        self.assertCountEqual(trek.districts, [d1])

        # Ensure there is no duplicates

        self.assertCountEqual(trek.pois_excluded.all(), [poi2])
        self.assertCountEqual(trek.all_pois, [poi, poi2])
        self.assertCountEqual(trek.pois, [poi])
        self.assertCountEqual(trek.services, [service])
        self.assertCountEqual(poi.treks, [trek])
        self.assertCountEqual(service.treks, [trek])

        d2 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
        self.assertCountEqual(trek.districts, [d1, d2])
Ejemplo n.º 2
0
    def setUp(self):
        geom_1 = LineString((0, 0), (1, 0), (2, 0))
        self.p1 = Path.objects.create(name='First Path', geom=geom_1)
        self.p2 = Path.objects.create(name='Second Path', geom=geom_1)

        geom_2 = LineString((0, 2), (1, 2), (2, 2))
        self.p3 = Path.objects.create(name='Third Path', geom=geom_2)
        self.p4 = Path.objects.create(name='Fourth Path', geom=geom_2)

        geom_3 = LineString((2, 2), (1, 2), (0, 2))
        self.p5 = Path.objects.create(name='Fifth Path', geom=geom_3)

        geom_4 = LineString((4, 0), (6, 0))

        self.p6 = Path.objects.create(name='Sixth Path', geom=geom_4)
        self.p7 = Path.objects.create(name='Seventh Path', geom=geom_4)

        geom_5 = LineString((0, 6), (1, 6), (2, 6))

        self.p8 = Path.objects.create(name='Eighth Path', geom=geom_5)
        self.p9 = Path.objects.create(name='Nineth Path', geom=geom_5)

        poi1 = POIFactory.create(name='POI1', no_path=True)
        poi1.add_path(self.p1, start=0.5, end=0.5)
        poi2 = POIFactory.create(name='POI2', no_path=True)
        poi2.add_path(self.p2, start=0.5, end=0.5)
        poi3 = POIFactory.create(name='POI3', no_path=True)
        poi3.add_path(self.p4, start=0.5, end=0.5)
Ejemplo n.º 3
0
    def setUp(self):
        geom_1 = LineString((0, 0), (1, 0), (2, 0))
        self.p1 = Path.objects.create(name='First Path', geom=geom_1)
        self.p2 = Path.objects.create(name='Second Path', geom=geom_1)

        geom_2 = LineString((0, 2), (1, 2), (2, 2))
        self.p3 = Path.objects.create(name='Third Path', geom=geom_2)
        self.p4 = Path.objects.create(name='Fourth Path', geom=geom_2)

        geom_3 = LineString((2, 2), (1, 2), (0, 2))
        self.p5 = Path.objects.create(name='Fifth Path', geom=geom_3)

        geom_4 = LineString((4, 0), (6, 0))

        self.p6 = Path.objects.create(name='Sixth Path', geom=geom_4)
        self.p7 = Path.objects.create(name='Seventh Path', geom=geom_4)

        geom_5 = LineString((0, 6), (1, 6), (2, 6))

        self.p8 = Path.objects.create(name='Eighth Path', geom=geom_5)
        self.p9 = Path.objects.create(name='Nineth Path', geom=geom_5)

        poi1 = POIFactory.create(name='POI1', no_path=True)
        poi1.add_path(self.p1, start=0.5, end=0.5)
        poi2 = POIFactory.create(name='POI2', no_path=True)
        poi2.add_path(self.p2, start=0.5, end=0.5)
        poi3 = POIFactory.create(name='POI3', no_path=True)
        poi3.add_path(self.p4, start=0.5, end=0.5)
Ejemplo n.º 4
0
 def setUp(self):
     profile = UserProfileFactory.create(user__username='******',
                                         user__password='******')
     user = profile.user
     user.groups.add(Group.objects.get(name=u"Référents communication"))
     self.client.login(username=user.username, password='******')
     self.content1 = POIFactory.create()
     structure = StructureFactory.create()
     self.content2 = POIFactory.create(structure=structure)
Ejemplo n.º 5
0
 def test_delete_view_multiple_path_one_wrong_structure(self):
     other_structure = StructureFactory(name="Other")
     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)), structure=other_structure)
     POIFactory.create(paths=[(path_1, 0, 0)])
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, reverse('core:path_list'))
     self.assertIn(response.content, b'Access to the requested resource is restricted by structure.')
     self.assertEqual(Path.objects.count(), 4)
Ejemplo n.º 6
0
 def setUp(self):
     testutil._MAX_LENGTH = 10000
     creation = make_aware(datetime.datetime(2014, 1, 1), utc)
     self.trek = TrekFactory.create(published=True)
     self.trek.date_insert = creation
     self.trek.save()
     self.poi = POIFactory.create(published=True)
     self.poi.date_insert = creation
     self.poi.save()
     TrekFactory.create(published=False)
     POIFactory.create(published=False)
Ejemplo n.º 7
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.º 8
0
    def test_pois_is_not_ordered_by_progression(self):
        self.trek = TrekFactory.create(geom=LineString((0, 0), (8, 8)))

        self.trek_reverse = TrekFactory.create(geom=LineString((6.4, 6.4), (0.8, 0.8)))

        self.poi1 = POIFactory.create(geom=Point(3.2, 3.2))
        self.poi2 = POIFactory.create(geom=Point(1.2, 1.2))
        self.poi3 = POIFactory.create(geom=Point(4, 4))

        pois = self.trek.pois
        self.assertCountEqual([self.poi1, self.poi2, self.poi3], pois)
        pois = self.trek_reverse.pois
        self.assertCountEqual([self.poi1, self.poi2, self.poi3], pois)
Ejemplo n.º 9
0
    def test_pois_should_be_ordered_by_progression(self):
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        self.trek = TrekFactory.create(paths=[p1, p2])

        self.trek_reverse = TrekFactory.create(paths=[(p2, 0.8, 0), (p1, 1, 0.2)])

        self.poi1 = POIFactory.create(paths=[(p1, 0.8, 0.8)])
        self.poi2 = POIFactory.create(paths=[(p1, 0.3, 0.3)])
        self.poi3 = POIFactory.create(paths=[(p2, 0.5, 0.5)])

        pois = self.trek.pois
        self.assertEqual([self.poi2, self.poi1, self.poi3], list(pois))
        pois = self.trek_reverse.pois
        self.assertEqual([self.poi3, self.poi1, self.poi2], list(pois))
Ejemplo n.º 10
0
    def test_helpers(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        poi = POIFactory.create(no_path=True)
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      start_position=0.5)
        PathAggregationFactory.create(topo_object=trek, path=p2)
        PathAggregationFactory.create(topo_object=poi, path=p1,
                                      start_position=0.6, end_position=0.6)
        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))

        # Ensure related objects are accessible
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])
        self.assertItemsEqual(trek.districts, [d1])

        # Ensure there is no duplicates
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      end_position=0.5)
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])

        d2 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
        self.assertItemsEqual(trek.districts, [d1, d2])
Ejemplo n.º 11
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.º 12
0
    def test_pois_geojson(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0, 0), (4, 4, 2)))
        poi = POIFactory(no_path=True)
        trek.add_path(p1, start=0.5, end=1.0)
        poi.add_path(p1, start=0.6, end=0.6)
        AttachmentFactory.create(obj=poi, attachment_file=get_dummy_uploaded_image())
        self.assertNotEqual(poi.thumbnail, None)
        self.assertEqual(len(trek.pois), 1)

        url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        poislayer = json.loads(response.content)
        poifeature = poislayer['features'][0]
        self.assertTrue('serializable_thumbnail' in poifeature['properties'])
Ejemplo n.º 13
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.º 14
0
 def test_show_delete_multiple_path_in_list(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:path_list'))
     self.assertIn('<a href="#delete" id="btn-delete" role="button">', response.content)
Ejemplo n.º 15
0
 def test_poi_geojson_translation(self):
     # Create a Trek with a POI
     trek = TrekFactory.create(no_path=True)
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     poi = POIFactory.create(no_path=True)
     poi.name_fr = "Chapelle"
     poi.name_en = "Chapel"
     poi.name_it = "Capela"
     poi.published_fr = True
     poi.published_en = True
     poi.published_it = True
     poi.save()
     trek.add_path(p1, start=0.5)
     poi.add_path(p1, start=0.6, end=0.6)
     # Check that it applies to GeoJSON also :
     self.assertEqual(len(trek.pois), 1)
     poi = trek.pois[0]
     for lang, expected in [('fr-FR', poi.name_fr),
                            ('it-IT', poi.name_it)]:
         url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
         self.login()
         response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=lang)
         self.assertEqual(response.status_code, 200)
         obj = json.loads(response.content)
         jsonpoi = obj.get('features', [])[0]
         self.assertEqual(jsonpoi.get('properties', {}).get('name'), expected)
         self.client.logout()  # Django 1.6 keeps language in session
Ejemplo n.º 16
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.º 17
0
 def test_poi_geojson_translation(self):
     # Create a Trek with a POI
     trek = TrekFactory.create(no_path=True, published_fr=True, published_it=True)
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     poi = POIFactory.create(no_path=True)
     poi.name_fr = "Chapelle"
     poi.name_en = "Chapel"
     poi.name_it = "Capela"
     poi.published_fr = True
     poi.published_en = True
     poi.published_it = True
     poi.save()
     trek.add_path(p1, start=0.5)
     poi.add_path(p1, start=0.6, end=0.6)
     # Check that it applies to GeoJSON also :
     self.assertEqual(len(trek.pois), 1)
     poi = trek.pois[0]
     for lang, expected in [('fr', poi.name_fr),
                            ('it', poi.name_it)]:
         url = '/api/{lang}/treks/{pk}/pois.geojson'.format(lang=lang, pk=trek.pk)
         self.login()
         response = self.client.get(url)
         self.assertEqual(response.status_code, 200)
         obj = json.loads(response.content)
         jsonpoi = obj.get('features', [])[0]
         self.assertEqual(jsonpoi.get('properties', {}).get('name'), expected)
         self.client.logout()  # Django 1.6 keeps language in session
Ejemplo n.º 18
0
 def test_deleted_pois(self):
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     trek = TrekFactory.create(paths=[p1])
     poi = POIFactory.create(paths=[(p1, 0.6, 0.6)])
     self.assertCountEqual(trek.pois, [poi])
     poi.delete()
     self.assertCountEqual(trek.pois, [])
Ejemplo n.º 19
0
 def test_show_delete_multiple_path_in_list(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:path_list'))
     self.assertIn('<a href="#delete" id="btn-delete" role="button">', response.content)
Ejemplo n.º 20
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.º 21
0
    def test_helpers(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0, 0), (4, 4, 2)))
        p2 = PathFactory.create(geom=LineString((4, 4, 2), (8, 8, 4)))
        poi = POIFactory.create(no_path=True)
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      start_position=0.5)
        PathAggregationFactory.create(topo_object=trek, path=p2)
        PathAggregationFactory.create(topo_object=poi, path=p1,
                                      start_position=0.6, end_position=0.6)
        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))

        # Ensure related objects are accessible
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])
        self.assertItemsEqual(trek.districts, [d1])

        # Ensure there is no duplicates
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      end_position=0.5)
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])

        d2 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
        self.assertItemsEqual(trek.districts, [d1, d2])
Ejemplo n.º 22
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((700000 6600000, 700000 6600003, 700003 6600003, 700003 6600000, 700000 6600000)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.poi = POIFactory.create(published=True)

        self.attachment = AttachmentFactory.create(obj=self.poi,
                                                   attachment_file=get_dummy_uploaded_image())

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(701000 6601000)' % settings.SRID, published=True)  # too far
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=True)
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=False)  # not published
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(700002 6600002)' % settings.SRID, published=True).delete()  # deleted
        tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(702000 6602000)' % settings.SRID, published=True)  # too far

        self.pk = self.poi.pk
        url = '/api/pois/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)
Ejemplo n.º 23
0
 def test_delete_view_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)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 200)
     self.assertIn('Do you really wish to delete', response.content)
Ejemplo n.º 24
0
 def test_delete_view_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)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 200)
     self.assertIn('Do you really wish to delete', response.content)
Ejemplo n.º 25
0
 def test_deleted_pois(self):
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     trek = TrekFactory.create(no_path=True)
     trek.add_path(p1)
     poi = POIFactory.create(no_path=True)
     poi.add_path(p1, start=0.6, end=0.6)
     self.assertItemsEqual(trek.pois, [poi])
     poi.delete()
     self.assertItemsEqual(trek.pois, [])
Ejemplo n.º 26
0
 def test_deleted_pois(self):
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     trek = TrekFactory.create(no_path=True)
     trek.add_path(p1)
     poi = POIFactory.create(no_path=True)
     poi.add_path(p1, start=0.6, end=0.6)
     self.assertItemsEqual(trek.pois, [poi])
     poi.delete()
     self.assertItemsEqual(trek.pois, [])
Ejemplo n.º 27
0
    def test_helpers_nds(self):
        trek = TrekFactory.create(geom=LineString((2, 2), (8, 8)))
        poi = POIFactory.create(geom=Point(2.4, 2.4))
        poi2 = POIFactory.create(geom=Point(2.4, 2.4))
        service = ServiceFactory.create(geom=Point(2.8, 2.8))
        service.type.practices.add(trek.practice)
        trek.pois_excluded.add(poi2.pk)

        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))
        # Ensure related objects are accessible
        self.assertCountEqual(trek.pois_excluded.all(), [poi2])
        self.assertCountEqual(trek.all_pois, [poi, poi2])
        self.assertCountEqual(trek.pois, [poi])
        self.assertCountEqual(trek.services, [service])
        self.assertCountEqual(poi.treks, [trek])
        self.assertCountEqual(service.treks, [trek])
        self.assertCountEqual(trek.districts, [d1])
Ejemplo n.º 28
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)))
     POIFactory.create(paths=[(path_1, 0, 0)], name="POI_1")
     InfrastructureFactory.create(paths=[(path_1, 0, 1)], name="INFRA_1")
     signage = SignageFactory.create(paths=[(path_1, 0, 1)], name="SIGNA_1")
     TrailFactory.create(paths=[(path_2, 0, 1)], name="TRAIL_1")
     ServiceFactory.create(paths=[(path_2, 0, 1)])
     InterventionFactory.create(target=signage, name="INTER_1")
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertContains(response, "POI_1")
     self.assertContains(response, "INFRA_1")
     self.assertContains(response, "SIGNA_1")
     self.assertContains(response, "TRAIL_1")
     self.assertContains(response, "Service type")
     self.assertContains(response, "INTER_1")
     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.º 29
0
    def test_helpers(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        poi = POIFactory.create(no_path=True)
        poi2 = POIFactory.create(no_path=True)
        service = ServiceFactory.create(no_path=True)
        service.type.practices.add(trek.practice)
        trek.add_path(path=p1, start=0.5, end=1)
        trek.add_path(path=p2, start=0, end=1)
        poi.add_path(path=p1, start=0.6, end=0.6)
        poi2.add_path(path=p1, start=0.6, end=0.6)
        service.add_path(path=p1, start=0.7, end=0.7)
        trek.pois_excluded.add(poi2.pk)

        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))
        # Ensure related objects are accessible
        self.assertItemsEqual(trek.pois_excluded.all(), [poi2])
        self.assertItemsEqual(trek.all_pois, [poi, poi2])
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(trek.services, [service])
        self.assertItemsEqual(poi.treks, [trek])
        self.assertItemsEqual(service.treks, [trek])
        self.assertItemsEqual(trek.districts, [d1])

        # Ensure there is no duplicates

        trek.add_path(path=p1, start=0.5, end=1)
        self.assertItemsEqual(trek.pois_excluded.all(), [poi2])
        self.assertItemsEqual(trek.all_pois, [poi, poi2])
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(trek.services, [service])
        self.assertItemsEqual(poi.treks, [trek])
        self.assertItemsEqual(service.treks, [trek])

        d2 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
        self.assertItemsEqual(trek.districts, [d1, d2])
Ejemplo n.º 30
0
    def setUp(self):
        geom_1 = LineString((0, 0), (1, 0), (2, 0))
        self.p1 = Path.objects.create(name='First Path', geom=geom_1)
        self.p2 = Path.objects.create(name='Second Path', geom=geom_1)

        geom_2 = LineString((0, 2), (1, 2), (2, 2))
        self.p3 = Path.objects.create(name='Third Path', geom=geom_2)
        self.p4 = Path.objects.create(name='Fourth Path', geom=geom_2)

        geom_3 = LineString((2, 2), (1, 2), (0, 2))
        self.p5 = Path.objects.create(name='Fifth Path', geom=geom_3)

        geom_4 = LineString((4, 0), (6, 0))

        self.p6 = Path.objects.create(name='Sixth Path', geom=geom_4)
        self.p7 = Path.objects.create(name='Seventh Path', geom=geom_4)

        geom_5 = LineString((0, 6), (1, 6), (2, 6))

        self.p8 = Path.objects.create(name='Eighth Path', geom=geom_5)
        self.p9 = Path.objects.create(name='Nineth Path', geom=geom_5)

        POIFactory.create(name='POI1', paths=[(self.p1, 0.5, 0.5)])
        POIFactory.create(name='POI2', paths=[(self.p2, 0.5, 0.5)])
        POIFactory.create(name='POI3', paths=[(self.p4, 0.5, 0.5)])
Ejemplo n.º 31
0
    def test_pois_should_be_ordered_by_progression(self):
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        self.trek = TrekFactory.create(no_path=True)
        self.trek.add_path(p1)
        self.trek.add_path(p2, order=1)

        self.trek_reverse = TrekFactory.create(no_path=True)
        self.trek_reverse.add_path(p2, start=0.8, end=0, order=0)
        self.trek_reverse.add_path(p1, start=1, end=0.2, order=1)

        self.poi1 = POIFactory.create(no_path=True)
        self.poi1.add_path(p1, start=0.8, end=0.8)
        self.poi2 = POIFactory.create(no_path=True)
        self.poi2.add_path(p1, start=0.3, end=0.3)
        self.poi3 = POIFactory.create(no_path=True)
        self.poi3.add_path(p2, start=0.5, end=0.5)

        pois = self.trek.pois
        self.assertEqual([self.poi2, self.poi1, self.poi3], list(pois))
        pois = self.trek_reverse.pois
        self.assertEqual([self.poi3, self.poi1, self.poi2], list(pois))
Ejemplo n.º 32
0
    def test_pois_should_be_ordered_by_progression(self):
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        self.trek = TrekFactory.create(no_path=True)
        self.trek.add_path(p1)
        self.trek.add_path(p2, order=1)

        self.trek_reverse = TrekFactory.create(no_path=True)
        self.trek_reverse.add_path(p2, start=0.8, end=0, order=0)
        self.trek_reverse.add_path(p1, start=1, end=0.2, order=1)

        self.poi1 = POIFactory.create(no_path=True)
        self.poi1.add_path(p1, start=0.8, end=0.8)
        self.poi2 = POIFactory.create(no_path=True)
        self.poi2.add_path(p1, start=0.3, end=0.3)
        self.poi3 = POIFactory.create(no_path=True)
        self.poi3.add_path(p2, start=0.5, end=0.5)

        pois = self.trek.pois
        self.assertEqual([self.poi2, self.poi1, self.poi3], list(pois))
        pois = self.trek_reverse.pois
        self.assertEqual([self.poi3, self.poi1, self.poi2], list(pois))
Ejemplo n.º 33
0
    def setUp(self):
        self.user = SuperUserFactory.create(password='******')
        self.content = POIFactory.create(geom='SRID=%s;POINT(1 1)' %
                                         settings.SRID)

        self.picture = AttachmentFactory(
            content_object=self.content,
            attachment_file=get_dummy_uploaded_image(),
        )
        self.trek = TrekFactory.create(
            geom='SRID=%s;LINESTRING(0 0, 1 0, 2 0)' % settings.SRID)
        self.picture_2 = AttachmentFactory(
            content_object=self.trek,
            attachment_file=get_dummy_uploaded_image(),
        )
Ejemplo n.º 34
0
    def test_remove_poi(self):
        """
        poi is linked with AB

            poi
             +                D
             *                |
             *                |
        A---------B           C
             |----|
               e1

        we got after remove AB :

             poi
              + * * * * * * * D
                              |
                              |
                              C

        poi is linked with DC and e1 is deleted
        """
        ab = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
        PathFactory.create(name="CD", geom=LineString((2, 0), (2, 1)))
        poi = POIFactory.create(no_path=True, offset=1)
        e1 = TopologyFactory.create(no_path=True)
        PathAggregationFactory.create(path=ab,
                                      topo_object=e1,
                                      start_position=0.5,
                                      end_position=1)
        poi.add_path(ab, start=0.5, end=0.5)
        poi.save()

        self.assertTrue(almostequal(1, poi.offset))

        self.assertEqual(poi.geom, Point(0.5, 1.0, srid=2154))

        ab.delete()
        poi.reload()
        e1.reload()

        self.assertEqual(len(Path.objects.all()), 1)

        self.assertEqual(e1.deleted, True)
        self.assertEqual(poi.deleted, False)

        self.assertTrue(almostequal(1.5, poi.offset))
Ejemplo n.º 35
0
    def setUp(self):
        self.user = SuperUserFactory.create(password='******')
        self.content = POIFactory.create(geom='SRID=%s;POINT(1 1)' %
                                         settings.SRID)

        self.picture = AttachmentFactory(
            content_object=self.content,
            title='img1',
            attachment_file=get_dummy_uploaded_image())
        self.trek = TrekFactory.create(
            geom='SRID=%s;LINESTRING(0 0, 1 0, 2 0)' % settings.SRID)
        self.picture_2 = AttachmentFactory(
            content_object=self.trek,
            title='img2',
            attachment_file=get_dummy_uploaded_image())
        if os.path.exists(settings.MEDIA_ROOT):
            shutil.rmtree(settings.MEDIA_ROOT)
        os.makedirs(settings.MEDIA_ROOT)
Ejemplo n.º 36
0
    def test_remove_poi(self):
        """
        poi is linked with AB

            poi
             +                D
             *                |
             *                |
        A---------B           C
             |----|
               e1

        we got after remove AB :

             poi
              + * * * * * * * D
                              |
                              |
                              C

        poi is linked with DC and e1 is deleted
        """
        ab = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
        PathFactory.create(name="CD", geom=LineString((2, 0), (2, 1)))
        poi = POIFactory.create(no_path=True, offset=1)
        e1 = TopologyFactory.create(no_path=True)
        PathAggregationFactory.create(path=ab, topo_object=e1, start_position=0.5, end_position=1)
        poi.add_path(ab, start=0.5, end=0.5)
        poi.save()

        self.assertTrue(almostequal(1, poi.offset))

        self.assertEqual(poi.geom, Point(0.5, 1.0, srid=2154))

        ab.delete()
        poi.reload()
        e1.reload()

        self.assertEqual(len(Path.objects.all()), 1)

        self.assertEqual(e1.deleted, True)
        self.assertEqual(poi.deleted, False)

        self.assertTrue(almostequal(1.5, poi.offset))
Ejemplo n.º 37
0
    def setUp(self):
        self.login()

        polygon = 'SRID=%s;MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0)))' % settings.SRID
        self.city = CityFactory(geom=polygon)
        self.district = DistrictFactory(geom=polygon)

        self.poi = POIFactory.create(geom=Point(0, 0, srid=settings.SRID))

        self.attachment = AttachmentFactory.create(obj=self.poi,
                                                   attachment_file=get_dummy_uploaded_image())

        self.touristic_content = tourism_factories.TouristicContentFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
        self.touristic_event = tourism_factories.TouristicEventFactory(geom='SRID=%s;POINT(2 2)' % settings.SRID)

        self.pk = self.poi.pk
        url = '/api/pois/%s/' % self.pk
        self.response = self.client.get(url)
        self.result = json.loads(self.response.content)
Ejemplo n.º 38
0
 def test_remove_thumbnails(self):
     output = StringIO()
     self.content = POIFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
     self.picture = AttachmentFactory(
         content_object=self.content,
         attachment_file=get_dummy_uploaded_image())
     self.assertIsNotNone(self.content.thumbnail)
     self.assertTrue(os.path.exists(self.picture.attachment_file.path))
     self.assertTrue(
         os.path.exists("{path}.120x120_q85_crop.png".format(
             path=self.picture.attachment_file.path)))
     self.assertEqual(
         Thumbnail.objects.first().name,
         "{name}.120x120_q85_crop.png".format(
             name=self.picture.attachment_file.name))
     call_command('remove_thumbnails', stdout=output)
     self.assertTrue(os.path.exists(self.picture.attachment_file.path))
     self.assertFalse(
         os.path.exists("{name}.120x120_q85_crop.png".format(
             name=self.picture.attachment_file.path)))
     self.assertEqual(Thumbnail.objects.count(), 0)
Ejemplo n.º 39
0
 def test_poi_geojson_translation(self):
     # Create a Trek with a POI
     trek = TrekFactory.create(no_path=True)
     p1 = PathFactory.create(geom=LineString((0, 0, 0), (4, 4, 2)))
     poi = POIFactory.create(no_path=True)
     poi.name_fr = "Chapelle"
     poi.name_it = "Capela"
     poi.save()
     PathAggregationFactory.create(topo_object=trek, path=p1,
                                   start_position=0.5)
     PathAggregationFactory.create(topo_object=poi, path=p1,
                                   start_position=0.6, end_position=0.6)
     # Check that it applies to GeoJSON also :
     self.assertEqual(len(trek.pois), 1)
     poi = trek.pois[0]
     for lang, expected in [('fr-FR', poi.name_fr), ('it-IT', poi.name_it)]:
         url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
         response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=lang)
         obj = json.loads(response.content)
         jsonpoi = obj.get('features', [])[0]
         self.assertEqual(jsonpoi.get('properties', {}).get('name'), expected)
Ejemplo n.º 40
0
    def test_remove_poi(self):
        """
        poi is linked with AB

            poi
             +                D
             *                |
             *                |
        A---------B           C
             |----|
               e1

        we got after remove AB :

             poi
              + * * * * * * * D
                              |
                              |
                              C

        poi is linked with DC and e1 is deleted
        """
        ab = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
        PathFactory.create(name="CD", geom=LineString((2, 0), (2, 1)))
        poi = POIFactory.create(paths=[(ab, 0.5, 0.5)], offset=1)
        e1 = TopologyFactory.create(paths=[(ab, 0.5, 1)])

        self.assertAlmostEqual(1, poi.offset)
        self.assertEqual(poi.geom, Point(0.5, 1.0, srid=2154))

        ab.delete()
        poi.reload()
        e1.reload()

        self.assertEqual(len(Path.objects.all()), 1)

        self.assertEqual(e1.deleted, True)
        self.assertEqual(poi.deleted, False)

        self.assertAlmostEqual(1.5, poi.offset)
Ejemplo n.º 41
0
    def setUpClass(cls):
        super(SyncRandoTestCase, cls).setUpClass()
        cls.practice_dive = PracticeFactory.create(order=0)
        cls.dive = DiveFactory.create(practice=cls.practice_dive, published=True,
                                      geom='SRID=2154;POINT(700001 6600001)')
        cls.attachment_dive = AttachmentFactory.create(content_object=cls.dive,
                                                       attachment_file=get_dummy_uploaded_image())
        cls.poi_dive = POIFactory.create(name="dive_poi", published=True)
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.poi_dive,
                                 attachment_file=get_dummy_uploaded_file())
        cls.touristic_content = TouristicContentFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.touristic_event = TouristicEventFactory(
            geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True)
        cls.attachment_touristic_content = AttachmentFactory.create(content_object=cls.touristic_content,
                                                                    attachment_file=get_dummy_uploaded_image())
        cls.attachment_touristic_event = AttachmentFactory.create(content_object=cls.touristic_event,
                                                                  attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_content,
                                 attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=cls.touristic_event,
                                 attachment_file=get_dummy_uploaded_image())
        cls.source_a = RecordSourceFactory()
        cls.source_b = RecordSourceFactory()

        cls.portal_a = TargetPortalFactory()
        cls.portal_b = TargetPortalFactory()
        cls.dive_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True,
                                                    geom='SRID=2154;POINT(700002 6600002)',
                                                    portals=(cls.portal_a,), sources=(cls.source_a,))
        cls.dive_other_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True,
                                                          geom='SRID=2154;POINT(700002 6600002)',
                                                          portals=(cls.portal_b,), sources=(cls.source_b,))
Ejemplo n.º 42
0
 def test_poi_geojson_translation(self):
     # Create a Trek with a POI
     trek = TrekFactory.create(no_path=True)
     p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
     poi = POIFactory.create(no_path=True)
     poi.name_fr = "Chapelle"
     poi.name_en = "Chapel"
     poi.name_it = "Capela"
     poi.save()
     trek.add_path(p1, start=0.5)
     poi.add_path(p1, start=0.6, end=0.6)
     # Check that it applies to GeoJSON also :
     self.assertEqual(len(trek.pois), 1)
     poi = trek.pois[0]
     for lang, expected in [('fr-FR', poi.name_fr), ('it-IT', poi.name_it)]:
         url = reverse('trekking:trek_poi_geojson', kwargs={'pk': trek.pk})
         self.login()
         response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=lang)
         self.assertEqual(response.status_code, 200)
         obj = json.loads(response.content)
         jsonpoi = obj.get('features', [])[0]
         self.assertEqual(
             jsonpoi.get('properties', {}).get('name'), expected)
         self.client.logout()  # Django 1.6 keeps language in session
Ejemplo n.º 43
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.practice_trek = PracticeTrekFactory.create(order=1)
        self.practice_trek_first = PracticeTrekFactory.create(order=0)
        self.trek_1 = TrekWithPublishedPOIsFactory.create(practice=self.practice_trek, 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(practice=self.practice_trek, portals=(self.portal_a,),
                                         published=True)
        self.trek_5 = TrekFactory.create(practice=self.practice_trek_first, portals=(self.portal_a,),
                                         published=True, name="other")

        self.practice_dive = PracticeDiveFactory.create(order=0)

        self.dive_1 = DiveFactory.create(practice=self.practice_dive, sources=(self.source_a,),
                                         portals=(self.portal_b,),
                                         published=True, geom='SRID=2154;POINT(700001 6600001)')
        self.attachment_dive = AttachmentFactory.create(content_object=self.dive_1,
                                                        attachment_file=get_dummy_uploaded_image())
        self.dive_2 = DiveFactory.create(sources=(self.source_b,),
                                         published=True, geom='SRID=2154;LINESTRING (700000 6600000, 700100 6600100)')
        self.dive_3 = DiveFactory.create(portals=(self.portal_b,
                                                  self.portal_a),
                                         published=True, geom='POLYGON((700000 6600000, 700000 6600100, '
                                                              '700100 6600100, 700100 6600000, 700000 6600000))')
        self.dive_4 = DiveFactory.create(practice=self.practice_dive, portals=(self.portal_a,),
                                         published=True)
        self.poi_1 = trek_models.POI.objects.first()
        self.poi_dive = POIFactory.create(name="dive_poi", published=True)
        self.attachment_poi_image_1 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=self.poi_dive,
                                 attachment_file=get_dummy_uploaded_image())
        self.attachment_poi_image_2 = AttachmentFactory.create(content_object=self.poi_1,
                                                               attachment_file=get_dummy_uploaded_image())
        AttachmentFactory.create(content_object=self.poi_dive,
                                 attachment_file=get_dummy_uploaded_file())
        self.attachment_poi_file = AttachmentFactory.create(content_object=self.poi_1,
                                                            attachment_file=get_dummy_uploaded_file())
        if settings.TREKKING_TOPOLOGY_ENABLED:
            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)
        else:
            InfrastructureFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="INFRA_1")
            SignageFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="SIGNA_1")
        area = SensitiveAreaFactory.create(published=True)
        area.species.practices.add(SportPracticeFactory.create(name='Terrestre'))
        area.save()
        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.º 44
0
 def setUp(self):
     self.content = POIFactory(geom='SRID=%s;POINT(1 1)' % settings.SRID)
     self.picture = AttachmentFactory(
         content_object=self.content,
         attachment_file=get_dummy_uploaded_image())
Ejemplo n.º 45
0
 def test_show_delete_multiple_path_in_list(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     POIFactory.create(paths=[(path_1, 0, 0)])
     response = self.client.get(reverse('core:path_list'))
     self.assertContains(response, '<a href="#delete" id="btn-delete" role="button">')
Ejemplo n.º 46
0
 def test_deleted_pois_nds(self):
     trek = TrekFactory.create(geom=LineString((0, 0), (4, 4)))
     poi = POIFactory.create(geom=Point(2.4, 2.4))
     self.assertCountEqual(trek.pois, [poi])
     poi.delete()
     self.assertCountEqual(trek.pois, [])