コード例 #1
0
    def test_couches_sig_link(self):
        """
        +-----------------+    -
        |                 |ra2  |
        |    +-------+    |     |
        | _ _|  _ _ _|_ _ |      - C
        |    |p      |    |     |
        |    O       O    |     |
        |                 |ra1  |
        +-----------------+    -
        """
        # Fake restricted areas
        RestrictedAreaFactory.create(
            geom=MultiPolygon(Polygon(((0, 0), (2, 0), (2, 1), (0, 1), (0,
                                                                        0)))))
        RestrictedAreaFactory.create(
            geom=MultiPolygon(Polygon(((0, 1), (2, 1), (2, 2), (0, 2), (0,
                                                                        1)))))

        # Fake city
        c = City(code='005178',
                 name='Trifouillis-les-marmottes',
                 geom=MultiPolygon(
                     Polygon(((0, 0), (2, 0), (2, 2), (0, 2), (0, 0)),
                             srid=settings.SRID)))
        c.save()

        # Fake paths in these areas
        p = PathFactory(
            geom=LineString((0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5)))
        p.save()

        self.assertEqual(len(p.areas), 2)
        self.assertEqual(len(p.cities), 1)
コード例 #2
0
 def test_unpublish_area(self):
     self.login()
     RestrictedAreaFactory.create(published=True)
     RestrictedAreaFactory.create(published=False)
     data = {
         'action':
         'unpublish',
         '_selected_action':
         RestrictedArea.objects.all().values_list('pk', flat=True)
     }
     self.client.post(reverse("admin:zoning_restrictedarea_changelist"),
                      data,
                      follow=True)
     self.assertEqual(
         RestrictedArea.objects.filter(published=False).count(), 2)
コード例 #3
0
    def test_areas(self):
        area = RestrictedAreaFactory.create(published=False,
                                            geom=self.geom_2_wkt)

        self.assertQuerysetEqual(self.path.areas,
                                 [repr(self.area), repr(area)])
        self.assertEqual(len(self.path.areas), 2)
        self.assertQuerysetEqual(self.path.published_areas,
                                 [repr(self.area), repr(area)])
        self.assertEqual(len(self.path.published_areas), 2)

        self.assertQuerysetEqual(self.trek.areas,
                                 [repr(self.area), repr(area)])
        self.assertEqual(len(self.trek.areas), 2)
        self.assertQuerysetEqual(self.trek.published_areas, [repr(self.area)])
        self.assertEqual(len(self.trek.published_areas), 1)

        # Check reverse order
        self.path.reverse()
        self.path.save()

        self.assertQuerysetEqual(self.path.areas,
                                 [repr(area), repr(self.area)])
        self.assertEqual(len(self.path.areas), 2)
        self.assertQuerysetEqual(self.path.published_areas,
                                 [repr(area), repr(self.area)])
        self.assertEqual(len(self.path.published_areas), 2)
コード例 #4
0
 def test_restricted_area(self):
     area_type = RestrictedAreaTypeFactory.create(name="Test")
     restricted_area = RestrictedAreaFactory.create(
         area_type=area_type,
         name="Tel",
         geom=MultiPolygon(
             Polygon(((201, 0), (300, 0), (300, 100), (200, 100), (201, 0)),
                     srid=settings.SRID)))
     self.assertEqual(str(restricted_area), "Test - Tel")
コード例 #5
0
 def setUpClass(cls):
     super(ZoningPropertiesMixinTest, cls).setUpClass()
     cls.geom_1_wkt = 'SRID=2154;MULTIPOLYGON(((200000 300000, 900000 300000, 900000 1200000, 200000 1200000, ' \
                      '200000 300000)))'
     cls.geom_2_wkt = 'SRID=2154;MULTIPOLYGON(((900000 300000, 1100000 300000, 1100000 1200000, 900000 1200000, ' \
                      '900000 300000)))'
     cls.city = CityFactory.create(geom=cls.geom_1_wkt)
     cls.district = DistrictFactory.create(geom=cls.geom_1_wkt)
     cls.area = RestrictedAreaFactory.create(geom=cls.geom_1_wkt)
コード例 #6
0
ファイル: test_views.py プロジェクト: numahell/Geotrek-admin
    def test_restricted_area_urls_fragment(self):
        area_type = RestrictedAreaTypeFactory(name="Test")
        self.login()
        obj = self.modelfactory()
        response = self.client.get(obj.get_detail_url())
        self.assertNotContains(response, '/api/restrictedarea/type/{}/restrictedarea.geojson'.format(area_type.pk))

        self.restricted_area = RestrictedAreaFactory(area_type=area_type, name="Tel",
                                                     geom=MultiPolygon(Polygon(((0, 0), (300, 0), (300, 100), (200, 100), (0, 0)),
                                                                               srid=settings.SRID)))
        response = self.client.get(obj.get_detail_url())
        self.assertContains(response, '/api/restrictedarea/type/{}/restrictedarea.geojson'.format(area_type.pk))
コード例 #7
0
    def test_couches_sig_link(self):
        # Fake restricted areas
        ra1 = RestrictedAreaFactory.create(
            geom=MultiPolygon(Polygon(((0, 0), (2, 0), (2, 1), (0, 1), (0,
                                                                        0)))))
        ra2 = RestrictedAreaFactory.create(
            geom=MultiPolygon(Polygon(((0, 1), (2, 1), (2, 2), (0, 2), (0,
                                                                        1)))))

        # Fake city
        c = City(code='005178',
                 name='Trifouillis-les-marmottes',
                 geom=MultiPolygon(
                     Polygon(((0, 0), (2, 0), (2, 2), (0, 2), (0, 0)),
                             srid=settings.SRID)))
        c.save()

        # Fake paths in these areas
        p = PathFactory(
            geom=LineString((0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5)))
        p.save()

        # This should results in 3 PathAggregation (2 for RA1, 1 for RA2, 1 for City)
        self.assertEquals(p.aggregations.count(), 4)
        self.assertEquals(p.topology_set.count(), 4)

        # PathAgg is plain for City
        t_c = c.cityedge_set.get().topo_object
        pa = c.cityedge_set.get().aggregations.get()
        self.assertEquals(pa.start_position, 0.0)
        self.assertEquals(pa.end_position, 1.0)

        # PathAgg is splitted for RA
        self.assertEquals(ra1.restrictedareaedge_set.count(), 2)
        self.assertEquals(ra2.restrictedareaedge_set.count(), 1)
        rae1a = ra1.restrictedareaedge_set.filter(
            aggregations__start_position=0).get()
        rae1b = ra1.restrictedareaedge_set.filter(
            aggregations__end_position=1).get()
        pa1a = rae1a.aggregations.get()
        pa1b = rae1b.aggregations.get()
        t_ra1a = rae1a.topo_object
        t_ra1b = rae1b.topo_object
        pa2 = ra2.restrictedareaedge_set.get().aggregations.get()
        t_ra2 = ra2.restrictedareaedge_set.get().topo_object
        self.assertAlmostEqual(pa1a.start_position, 0.0)
        self.assertAlmostEqual(pa1a.end_position, 0.5 / 3)
        self.assertAlmostEqual(pa1b.start_position, 2.5 / 3)
        self.assertAlmostEqual(pa1b.end_position, 1.0)
        self.assertAlmostEqual(pa2.start_position, 0.5 / 3)
        self.assertAlmostEqual(pa2.end_position, 2.5 / 3)

        # Ensure everything is in order after update
        p.geom = LineString((0.5, 0.5), (1.5, 0.5))
        p.save()
        self.assertEquals(p.aggregations.count(), 2)
        self.assertEquals(p.topology_set.count(), 2)
        # Topology are re-created at DB-level after any update
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get,
                          pk=t_c.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get,
                          pk=t_ra1a.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get,
                          pk=t_ra1b.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get,
                          pk=t_ra2.pk)
        self.assertEquals(ra1.restrictedareaedge_set.count(), 1)
        # a new association exists for C
        t_c = c.cityedge_set.get().topo_object
        self.assertEquals(Topology.objects.filter(pk=t_c.pk).count(), 1)
        # a new association exists for RA1
        t_ra1 = ra1.restrictedareaedge_set.get().topo_object
        self.assertEquals(Topology.objects.filter(pk=t_ra1.pk).count(), 1)
        pa1 = ra1.restrictedareaedge_set.get().aggregations.get()
        self.assertEquals(pa1.start_position, 0.0)
        self.assertEquals(pa1.end_position, 1.0)
        # RA2 is not connected anymore
        self.assertEquals(ra2.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra2.pk).count(), 0)

        # All intermediary objects should be cleaned on delete
        p.delete()
        self.assertEquals(c.cityedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_c.pk).count(), 0)
        self.assertEquals(ra1.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra1.pk).count(), 0)
        self.assertEquals(ra2.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra2.pk).count(), 0)
コード例 #8
0
ファイル: test_models.py プロジェクト: Pitchs/Geotrek
    def test_couches_sig_link(self):
        # Fake restricted areas
        ra1 = RestrictedAreaFactory.create(geom=MultiPolygon(
            Polygon(((0, 0), (2, 0), (2, 1), (0, 1), (0, 0)))))
        ra2 = RestrictedAreaFactory.create(geom=MultiPolygon(
            Polygon(((0, 1), (2, 1), (2, 2), (0, 2), (0, 1)))))

        # Fake city
        c = City(code='005178', name='Trifouillis-les-marmottes',
                 geom=MultiPolygon(Polygon(((0, 0), (2, 0), (2, 2), (0, 2), (0, 0)),
                                   srid=settings.SRID)))
        c.save()

        # Fake paths in these areas
        p = PathFactory(geom=LineString((0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5)))
        p.save()

        # This should results in 3 PathAggregation (2 for RA1, 1 for RA2, 1 for City)
        self.assertEquals(p.aggregations.count(), 4)
        self.assertEquals(p.topology_set.count(), 4)

        # PathAgg is plain for City
        t_c = c.cityedge_set.get().topo_object
        pa = c.cityedge_set.get().aggregations.get()
        self.assertEquals(pa.start_position, 0.0)
        self.assertEquals(pa.end_position, 1.0)

        # PathAgg is splitted for RA
        self.assertEquals(ra1.restrictedareaedge_set.count(), 2)
        self.assertEquals(ra2.restrictedareaedge_set.count(), 1)
        rae1a = ra1.restrictedareaedge_set.filter(aggregations__start_position=0).get()
        rae1b = ra1.restrictedareaedge_set.filter(aggregations__end_position=1).get()
        pa1a = rae1a.aggregations.get()
        pa1b = rae1b.aggregations.get()
        t_ra1a = rae1a.topo_object
        t_ra1b = rae1b.topo_object
        pa2 = ra2.restrictedareaedge_set.get().aggregations.get()
        t_ra2 = ra2.restrictedareaedge_set.get().topo_object
        self.assertAlmostEqual(pa1a.start_position, 0.0)
        self.assertAlmostEqual(pa1a.end_position, 0.5 / 3)
        self.assertAlmostEqual(pa1b.start_position, 2.5 / 3)
        self.assertAlmostEqual(pa1b.end_position, 1.0)
        self.assertAlmostEqual(pa2.start_position, 0.5 / 3)
        self.assertAlmostEqual(pa2.end_position, 2.5 / 3)

        # Ensure everything is in order after update
        p.geom = LineString((0.5, 0.5), (1.5, 0.5))
        p.save()
        self.assertEquals(p.aggregations.count(), 2)
        self.assertEquals(p.topology_set.count(), 2)
        # Topology are re-created at DB-level after any update
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get, pk=t_c.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get, pk=t_ra1a.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get, pk=t_ra1b.pk)
        self.assertRaises(Topology.DoesNotExist,
                          Topology.objects.get, pk=t_ra2.pk)
        self.assertEquals(ra1.restrictedareaedge_set.count(), 1)
        # a new association exists for C
        t_c = c.cityedge_set.get().topo_object
        self.assertEquals(Topology.objects.filter(pk=t_c.pk).count(), 1)
        # a new association exists for RA1
        t_ra1 = ra1.restrictedareaedge_set.get().topo_object
        self.assertEquals(Topology.objects.filter(pk=t_ra1.pk).count(), 1)
        pa1 = ra1.restrictedareaedge_set.get().aggregations.get()
        self.assertEquals(pa1.start_position, 0.0)
        self.assertEquals(pa1.end_position, 1.0)
        # RA2 is not connected anymore
        self.assertEquals(ra2.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra2.pk).count(), 0)

        # All intermediary objects should be cleaned on delete
        p.delete()
        self.assertEquals(c.cityedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_c.pk).count(), 0)
        self.assertEquals(ra1.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra1.pk).count(), 0)
        self.assertEquals(ra2.restrictedareaedge_set.count(), 0)
        self.assertEquals(Topology.objects.filter(pk=t_ra2.pk).count(), 0)