Beispiel #1
0
 def test_get_rental_listings(self):
     '''
     Gets the test variables
     '''
     test_case = self.success_test_params
     with mock.patch("requests.request", self.mock_request):
         with mock.patch("walkscore_api.get_walkscore_info",
                         self.mock_get_walkscore_info):
             with mock.patch("google_maps_api.get_place_id",
                             self.mock_get_place_id):
                 with mock.patch(
                         "google_maps_api.generate_iframe_url",
                         self.mock_generate_iframe_url,
                 ):
                     with mock.patch("googlemaps.Client.directions",
                                     self.mock_directions):
                         input_case = test_case[KEY_INPUT]
                         result = rental_listings_api.get_rental_listings(
                             input_case[CITY],
                             input_case[STATE_CODE],
                             input_case[MIN_PRICE],
                             input_case[MAX_PRICE],
                             input_case[ABSOLUTE_ADDRESS],
                         )
                         # for result in results:
                         self.assertDictEqual(result[0],
                                              test_case[KEY_EXPECTED][0])
Beispiel #2
0
def parsing_search_parameters(data):
    """
    Main Function
    """
    print("bodyfadfyadfya")
    print(data)
    street_address = data["address"]
    city = data["city"]
    state = data["state"]
    min_price = data["min_price"]
    max_price = data["max_price"]
    absolute_address = street_address + ", " + city + ", " + state
    purchase_type = data["purchase_type"]

    print(data)
    invalid_input_errors = []
    if min_price < 0:
        invalid_input_errors.append(
            "The min price cannot be a negative number")
    if max_price < 0:
        invalid_input_errors.append(
            "The max price cannot be a negative number")

    if min_price > max_price:
        invalid_input_errors.append(
            "Min price cannot be bigger than max price")

    if len(invalid_input_errors) == 0:
        send_to_database(
            EMAIL_CLASS.value_of(),
            absolute_address,
            min_price,
            max_price,
            city,
            state,
            purchase_type,
        )
        listings = ""
        if purchase_type == "sale":
            listings = apifunctions.get_homes(city, state, min_price,
                                              max_price, absolute_address)
        if purchase_type == "rent":
            listings = rental_listings_api.get_rental_listings(
                city, state, str(min_price), str(max_price), absolute_address)
        print("Final listings outputted: " + str(listings))
        tuple_checking = (-1, None)
        if listings in tuple_checking:
            SOCKETIO.emit("sending listing", [])
        else:
            SOCKETIO.emit("sending listing", listings)
    if len(invalid_input_errors) > 0:
        SOCKETIO.emit("Invalid search input", invalid_input_errors)
        print("Errors sent")
        print(invalid_input_errors)
        invalid_input_errors = []
Beispiel #3
0
 def test_get_rental_listings_key_error(self):
     '''
     Checks key error handling
     '''
     test_case = self.success_test_params
     with mock.patch("requests.request") as mock_err:
         mock_err.side_effect = KeyError
         input_case = test_case[KEY_INPUT]
         result = rental_listings_api.get_rental_listings(
             input_case[CITY],
             input_case[STATE_CODE],
             input_case[MIN_PRICE],
             input_case[MAX_PRICE],
             input_case[ABSOLUTE_ADDRESS],
         )
Beispiel #4
0
 def test_get_rental_listings_request_exception(self):
     '''
     Checks a genenic bad request handling
     '''
     test_case = self.success_test_params
     with mock.patch("requests.request") as mock_err:
         mock_err.side_effect = requests.exceptions.RequestException
         input_case = test_case[KEY_INPUT]
         result = rental_listings_api.get_rental_listings(
             input_case[CITY],
             input_case[STATE_CODE],
             input_case[MIN_PRICE],
             input_case[MAX_PRICE],
             input_case[ABSOLUTE_ADDRESS],
         )