コード例 #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])
コード例 #2
0
ファイル: test_models.py プロジェクト: Babawah/Geotrek
    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])
コード例 #3
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])
コード例 #4
0
ファイル: test_views.py プロジェクト: numahell/Geotrek-admin
 def test_sum_path_filter_districts(self):
     self.login()
     p1 = PathFactory(geom=LineString((0, 0), (0, 1000), srid=settings.SRID))
     district = DistrictFactory(geom=MultiPolygon(Polygon(((200, 0), (300, 0), (300, 100), (200, 100), (200, 0)), srid=settings.SRID)))
     district2 = DistrictFactory(geom=MultiPolygon(
         Polygon(((0, 0), (1000, 0), (1000, 1000), (0, 1000), (0, 0)), srid=settings.SRID)))
     self.assertEqual(p1.aggregations.count(), 1)
     response = self.client.get('/api/path/paths.json?district=%s' % district.pk)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json()['sumPath'], 0.0)
     response = self.client.get('/api/path/paths.json?district=%s' % district2.pk)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json()['sumPath'], 1.0)
コード例 #5
0
 def test_unpublish_district(self):
     self.login()
     DistrictFactory.create(published=True)
     DistrictFactory.create(published=False)
     data = {
         'action': 'unpublish',
         '_selected_action': District.objects.all().values_list('pk',
                                                                flat=True)
     }
     self.client.post(reverse("admin:zoning_district_changelist"),
                      data,
                      follow=True)
     self.assertEqual(District.objects.filter(published=False).count(), 2)
コード例 #6
0
    def test_districts(self):
        district = DistrictFactory.create(published=False,
                                          geom=self.geom_2_wkt)

        self.assertQuerysetEqual(
            self.path.districts,
            [repr(self.district), repr(district)])
        self.assertEqual(len(self.path.districts), 2)
        self.assertQuerysetEqual(
            self.path.published_districts,
            [repr(self.district), repr(district)])
        self.assertEqual(len(self.path.published_districts), 2)

        self.assertQuerysetEqual(
            self.trek.districts,
            [repr(self.district), repr(district)])
        self.assertEqual(len(self.trek.districts), 2)
        self.assertQuerysetEqual(self.trek.published_districts,
                                 [repr(self.district)])
        self.assertEqual(len(self.trek.published_districts), 1)

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

        self.assertQuerysetEqual(
            self.path.districts,
            [repr(district), repr(self.district)])
        self.assertEqual(len(self.path.districts), 2)
        self.assertQuerysetEqual(
            self.path.published_districts,
            [repr(district), repr(self.district)])
        self.assertEqual(len(self.path.published_districts), 2)
コード例 #7
0
 def test_filter_out_district(self):
     filter = ProjectFilterSet(
         data={'district': [DistrictFactory.create(geom=self.geom_zoning)]})
     project_out = ProjectFactory.create()
     project_out.interventions.add(self.intervention_out)
     self.assertTrue(filter.is_valid())
     self.assertEqual(len(filter.qs), 0)
コード例 #8
0
 def test_district(self):
     district = DistrictFactory.create(name="Lil",
                                       geom=MultiPolygon(
                                           Polygon(((201, 0), (300, 0),
                                                    (300, 100), (200, 100),
                                                    (201, 0)),
                                                   srid=settings.SRID)))
     self.assertEqual(str(district), "Lil")
コード例 #9
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)
コード例 #10
0
ファイル: test_models.py プロジェクト: makinacorpus/Geotrek
    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])
コード例 #11
0
ファイル: test_views.py プロジェクト: Babawah/Geotrek
    def test_listing_number_queries(self):
        self.login()
        # Create many instances
        for i in range(100):
            self.modelfactory.create()
        for i in range(10):
            DistrictFactory.create()

        # Enable query counting
        settings.DEBUG = True

        for url in [self.model.get_jsonlist_url(),
                    self.model.get_format_list_url()]:

            num_queries_old = len(connection.queries)
            self.client.get(url)
            num_queries_new = len(connection.queries)

            nb_queries = num_queries_new - num_queries_old
            self.assertTrue(0 < nb_queries < 100, '%s queries !' % nb_queries)

        settings.DEBUG = False
コード例 #12
0
    def test_listing_number_queries(self):
        self.login()
        # Create many instances
        for i in range(100):
            self.modelfactory.create()
        for i in range(10):
            DistrictFactory.create()

        # Enable query counting
        settings.DEBUG = True

        for url in [
                self.model.get_jsonlist_url(),
                self.model.get_format_list_url()
        ]:

            num_queries_old = len(connection.queries)
            self.client.get(url)
            num_queries_new = len(connection.queries)

            nb_queries = num_queries_new - num_queries_old
            self.assertTrue(0 < nb_queries < 100, '%s queries !' % nb_queries)

        settings.DEBUG = False
コード例 #13
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])