@@ -63,7 +63,7 @@ def setUpClass(cls):
6363
6464 @pytest .mark .webtest
6565 def test_field_filter_geo_distance (self ):
66- """Field filter term .
66+ """Field filter geo-distance .
6767
6868 Example:
6969
@@ -87,6 +87,69 @@ def test_field_filter_geo_distance(self):
8787 # Should contain only 6 results
8888 self .assertEqual (len (response .data ['results' ]), self .geo_in_count + 1 )
8989
90+ @pytest .mark .webtest
91+ def test_field_filter_geo_polygon (self ):
92+ """Field filter geo-polygon.
93+
94+ Example:
95+
96+ http://localhost:8000/api/articles/
97+ ?location__geo_polygon=3.51,-71.46|-47.63,41.64|62.05,29.22
98+ """
99+ self .authenticate ()
100+
101+ __params = '{},{}|{},{}|{},{}' .format (
102+ 3.51 ,
103+ - 71.46 ,
104+ - 47.63 ,
105+ 41.64 ,
106+ 62.05 ,
107+ 29.22 ,
108+ )
109+
110+ valid_points = [
111+ (- 23.37 , 47.51 ),
112+ (- 2.81 , 63.15 ),
113+ (15.99 , 46.31 ),
114+ (26.54 , 42.42 ),
115+ ]
116+
117+ invalid_points = [
118+ (- 82.79 , 72.34 ),
119+ (54.31 , 72.34 ),
120+ (- 6.50 , 78.42 ),
121+ # (-56.42, 82.78),
122+ ]
123+ valid_publishers = []
124+ invalid_publishers = []
125+
126+ for __lat , __lon in valid_points :
127+ valid_publishers .append (
128+ factories .PublisherFactory (
129+ latitude = __lat ,
130+ longitude = __lon ,
131+ )
132+ )
133+
134+ for __lat , __lon in invalid_points :
135+ invalid_publishers .append (
136+ factories .PublisherFactory (
137+ latitude = __lat ,
138+ longitude = __lon ,
139+ )
140+ )
141+
142+ url = self .base_publisher_url [:] + '?{}={}' .format (
143+ 'location__geo_polygon' ,
144+ __params
145+ )
146+
147+ data = {}
148+ response = self .client .get (url , data )
149+ self .assertEqual (response .status_code , status .HTTP_200_OK )
150+ # Should contain only 4 results
151+ self .assertEqual (len (response .data ['results' ]), 4 )
152+
90153
91154if __name__ == '__main__' :
92155 unittest .main ()
0 commit comments