예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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']
예제 #6
0
 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
예제 #7
0
 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})
예제 #8
0
 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})
예제 #9
0
파일: __init__.py 프로젝트: SamR1/lbc2rss
    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
예제 #10
0
 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})
예제 #11
0
 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})