def _test_field_filter_geo_bounding_box(self, points, count): """Private helper test field filter geo-bounding-box. For testing use http://bboxfinder.com/#40.070000,43.870000,41.110000,44.870000 Example: http://localhost:8000/api/articles/ ?location__geo_bounding_box=44.87,40.07__43.87,41.11 :param points: :param count: :type points: :type count: :return: :rtype: """ self.authenticate() __params = '{val1},{val2}{sep}{val3},{val4}'.format( val1=44.87, val2=40.07, val3=43.87, val4=41.11, sep=SEPARATOR_LOOKUP_COMPLEX_VALUE) publishers = [] url = self.base_publisher_url[:] + '?{}={}'.format( 'location__geo_bounding_box', __params) data = {} for __lat, __lon in points: publishers.append( factories.PublisherFactory( latitude=__lat, longitude=__lon, )) call_command('search_index', '--rebuild', '-f') sleep(WAIT_FOR_INDEX) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), count) return publishers
def _test_field_filter_geo_polygon(self, field_name, points, count): """Private helper test field filter geo-polygon. Example: http://localhost:8000/api/articles/ ?location__geo_polygon=3.51,71.46__-47.63,41.64__62.05,29.22 :param points: :param count: :type points: :type count: :return: :rtype: """ self.authenticate() __params = '{val1},{val2}{sep}{val3},{val4}{sep}{val5},{val6}'.format( val1=3.51, val2=71.46, val3=-47.63, val4=41.64, val5=62.05, val6=29.22, sep=SEPARATOR_LOOKUP_COMPLEX_VALUE) publishers = [] url = self.base_publisher_url[:] + '?{}={}'.format( field_name, __params) data = {} for __lat, __lon in points: publishers.append( factories.PublisherFactory( latitude=__lat, longitude=__lon, )) call_command('search_index', '--rebuild', '-f') sleep(WAIT_FOR_INDEX) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), count) return publishers
def _test_field_filter_geo_polygon(self, field_name, points, count): """Private helper test field filter geo-polygon. Example: http://localhost:8000/api/articles/ ?location__geo_polygon=3.51,71.46|-47.63,41.64|62.05,29.22 :param points: :param count: :type points: :type count: :return: :rtype: """ self.authenticate() __params = '{},{}|{},{}|{},{}'.format( 3.51, 71.46, -47.63, 41.64, 62.05, 29.22, ) publishers = [] url = self.base_publisher_url[:] + '?{}={}'.format( field_name, __params) data = {} for __lat, __lon in points: publishers.append( factories.PublisherFactory( latitude=__lat, longitude=__lon, )) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), count) return publishers
def _test_field_filter_geo_bounding_box(self, points, count): """Private helper test field filter geo-bounding-box. Example: http://localhost:8000/api/articles/ ?location__geo_bounding_box=44.87,40.07|43.87,41.11 :param points: :param count: :type points: :type count: :return: :rtype: """ self.authenticate() __params = '{},{}|{},{}'.format( 44.87, 40.07, 43.87, 41.11, ) publishers = [] url = self.base_publisher_url[:] + '?{}={}'.format( 'location__geo_bounding_box', __params) data = {} for __lat, __lon in points: publishers.append( factories.PublisherFactory( latitude=__lat, longitude=__lon, )) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), count) return publishers
def setUpClass(cls): """Set up class.""" cls.publishers = [] cls.publishers.append( factories.PublisherFactory( name='Addison–Wesley', city='Brighton & Hove', state_province='East Midlands', country='Armenia', )) cls.publishers.append( factories.PublisherFactory( name='Adis International', city='Bristol', state_province='East of England', country='Argentina', )) cls.publishers.append( factories.PublisherFactory( name='Atlantic Books', city='Cardiff', state_province='North East', country='Belgium', )) cls.publishers.append( factories.PublisherFactory( name='Atlas Press', city='Carlisle', state_province='North West', country='Belarus', )) cls.publishers.append( factories.PublisherFactory( name='Book League of America', city='Chelmsford', state_province='South East', country='Burkina Faso', )) cls.publishers.append( factories.PublisherFactory( name='Book Works', city='Chester', state_province='South West', country='Burundi', )) cls.publishers.append( factories.PublisherFactory( name='Booktrope', city='Chichester', state_province='West Midlands', country='Netherlands', )) cls.publishers_url = reverse('publisherdocument-suggest', kwargs={}) cls.books = [] cls.books.append( factories.BookFactory( title='Aaaaa Bbbb', summary='`Twas brillig, and the slithy toves ' 'Did gyre and gimble in the wabe. ' 'All mimsy were the borogoves ' 'And the mome raths outgrabe.', publisher__name='Antares', publisher__country='Armenia', )) cls.books.append( factories.BookFactory( title='Aaaaa Cccc', summary='"Beware the Jabberwock, my son! ' 'The jaws that bite, the claws that catch! ' 'Beware the Jubjub bird, and shun ' 'The frumious Bandersnatch!', publisher__name='Antares', publisher__country='Armenia', )) cls.books.append( factories.BookFactory( title='Aaaaa Dddd', summary='He took his vorpal sword in his hand,' 'Long time the manxome foe he sought --' 'So rested he by the Tumtum tree,' 'And stood awhile in thought.', publisher__name='Antares', publisher__country='Armenia', )) cls.books += factories.BookFactory.create_batch( 10, publisher__name='Oxford University Press', publisher__city='Yerevan', publisher__state_province='Ararat', publisher__country='Ireland', ) cls.books_url = reverse('bookdocument-suggest', kwargs={}) cls.authors = [] cls.authors.append( factories.AuthorFactory( name='John Doe', salutation='Aaa Bbb', )) cls.authors.append( factories.AuthorFactory( name='Jane Doe', salutation='Aaa Ccc', )) cls.authors.append( factories.AuthorFactory( name='Armen Doe', salutation='Bbb Ccc', )) cls.authors_url = reverse('authordocument-suggest', kwargs={}) cls.created_addresses() call_command('search_index', '--rebuild', '-f')
def _test_field_filter_geo_shape(self, points, count, gs_data): """Private helper test field filter geo-shape. For testing use Box: http://bboxfinder.com/#48.643798,5.630493,49.344809,6.643982 Circle: https://www.mapdevelopers.com/draw-circle-tool.php?circles=%5B%5B10000%2C49.1196964%2C6.1763552%2C%22%23AAAAAA%22%2C%22%23000000%22%2C0.4%5D%5D Examples: http://localhost:8000/search/publishers/ ?location_point__geo_shape=49.344809,6.643982 __48.643798,5.630493 __relation,within __type,envelope http://localhost:8000/search/publishers/ ?location_point__geo_shape=49.119696,6.176355 __radius,10km __relation,within __type,circle http://localhost:8000/search/publishers/ ?location_circle__geo_shape=49.119696,6.176355 __radius,15km __relation,intersects __type,circle :param points: :param count: :param gs_data: contains geo_shape query data (type, relation, radius etc) :type points: list :type count: int :type gs_data: dict :return: :rtype: """ self.authenticate() gs_coordinates = gs_data.get('coordinates') __params = ','.join(gs_coordinates[0]) for coord in gs_coordinates[1:]: __params = '{}{}{}'.format(__params, SEPARATOR_LOOKUP_COMPLEX_VALUE, ','.join(coord)) __params = '{}{sep}relation,{}{sep}type,{}'.format( __params, gs_data.get('relation'), gs_data.get('type'), sep=SEPARATOR_LOOKUP_COMPLEX_VALUE) gs_extra = gs_data.get('extra') if gs_extra: __params = '{}{}{}'.format(__params, SEPARATOR_LOOKUP_COMPLEX_VALUE, gs_extra) url = self.base_publisher_url[:] + '?{field}{}={}'.format( '__geo_shape', __params, field=gs_data.get('field')) publishers = [] for __lat, __lon in points: publishers.append( factories.PublisherFactory( latitude=__lat, longitude=__lon, )) call_command('search_index', '--rebuild', '-f') self.sleep() response = self.client.get(url, {}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), count) return publishers