def test_it_sets_coordinates_filters( self, input_coordinates: Dict, expected_area_filter: Dict ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params=input_coordinates) filters = query.search.get_filters()['filters'] assert filters['location']['area'] == expected_area_filter
def test_it_sets_keywords_filters( self, input_keywords_params: Dict, expected_keywords_filters: Dict ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params=input_keywords_params) filters = query.search.get_filters()['filters'] assert filters['keywords'] == expected_keywords_filters
def test_it_sets_square_filters( self, input_square_params: Dict, expected_square_filters: Dict ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params=input_square_params) filters = query.search.get_filters()['filters'] assert filters['ranges']['square'] == expected_square_filters
def test_it_sets_cities_filters( self, cities: str, expected_cities_filters: List ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params={'cities': cities}) filters = query.search.get_filters()['filters'] assert filters['location']['locations'] == expected_cities_filters
def test_it_sets_sort_options( self, input_sort_params: Dict, expected_sort_filters: Dict ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params=input_sort_params) filters = query.search.get_filters() assert filters['sort_by'] == expected_sort_filters['sort_by'] assert filters['sort_order'] == expected_sort_filters['sort_order']
def test_it_sets_departments_filters( self, departments: str, expected_departments_filters: List ) -> None: query = LBCQuery(category='locations') query.add_search_parameters(params={'departments': departments}) filters = query.search.get_filters()['filters'] assert filters['location']['departments'] == departments.split('|') assert filters['location']['locations'] == expected_departments_filters
def test_it_raises_error_if_a_coordinate_is_missing( self, coordinate: str, expected_coordinate: str ) -> None: query = LBCQuery(category='locations') with pytest.raises( InvalidParameters, match=f'Missing coordinate, get only {expected_coordinate}.', ): query.add_search_parameters(params={coordinate: 1})
def test_it_raises_error_if_city_is_incorrect(self, cities: str) -> None: query = LBCQuery(category='locations') with pytest.raises( InvalidParameters, match=( r'A city must contain a name and a valid zip code \(5 digits\)' r', separated with a comma.' ), ): query.add_search_parameters(params={'cities': cities})
def ads_feed(category: str) -> Tuple[str, int]: try: query = LBCQuery(category=category) except InvalidCategory: return 'Invalid category.', 404 try: params = dict(request.args.copy()) query.add_search_parameters(params) except InvalidParameters as error_message: return str(error_message), 400 results = query.get_results() return generate_ads_feed(category, results, params), 200
def test_it_raises_error_if_sort_is_incorrect(self, sort: str) -> None: query = LBCQuery(category='locations') with pytest.raises( InvalidParameters, match='Invalid sort order.', ): query.add_search_parameters(params={'order_by': sort})
def test_it_raises_error_with_invalid_real_estate_type(self) -> None: query = LBCQuery(category='locations') with pytest.raises( InvalidParameters, match='Invalid real estate types.' ): query.add_search_parameters(params={'types': uuid4().hex})