def get_residence_id(x_request_id: str, driver: any) -> int:
    """
    Function responsible for return id of residence.

    Parameters:
            x_request_id: unique id
            driver: google chrome instance
    Returns:
        int
    """
    send_log(x_request_id=x_request_id,
             message="Searching for the residence id...")
    sleep(number=2)
    try:
        residence_id = driver.find_element_by_xpath(
            "/html/body/div[1]/div/main/section/div/div[1]/nav/ol/li[5]/a")

        if residence_id:
            send_log(
                x_request_id=x_request_id,
                message="Found id of residence...",
            )

            residence_id_text = residence_id.text

            # Start verification if has digit
            # then going to return. If do not have then return 0.
            return (int(re.findall(r"\d+", residence_id_text)[0])
                    if verification_string_has_digit(x_request_id=x_request_id,
                                                     text=residence_id_text)
                    else 0)
    except (AttributeError, NoSuchElementException) as exception:
        error_handler(x_request_id=x_request_id, exception=exception)
Example #2
0
def residence_size(x_request_id: str, driver) -> int:
    """
        Function responsible for return the size of the residence.

        Parameters:
                x_request_id: unique id
                driver: google chrome instance
    Returns:
        int: size of residence
    """
    send_log(
        x_request_id=x_request_id,
        message="Searching for the number of bedrooms...",
    )
    sleep(number=2)
    try:
        size_residence_data = driver.find_element_by_xpath(
            "/html/body/div[1]/div/main/section/div/div[1]/div/div[3]/div/div[1]/div/div/span"
        )
        if size_residence_data:
            send_log(
                x_request_id=x_request_id,
                message="Found information about bedrooms...",
            )

            size_residence = size_residence_data.text
            # Start verification if has digit
            # then going to return. If do not have then return 0.
            return (int(re.findall(r"\d+", size_residence)[0]) if
                    verification_string_has_digit(x_request_id=x_request_id,
                                                  text=size_residence) else 0)
    except (AttributeError, NoSuchElementException) as exception:
        error_handler(x_request_id=x_request_id, exception=exception)
def number_of_rooms(x_request_id: str, driver) -> int:
    """
        Function responsible for return number of rooms.

        Parameters:
                x_request_id: unique id
                driver: google chrome instance
    Returns:
        Bool <True or False>
    """
    send_log(x_request_id=x_request_id,
             message="Searching for number of rooms...")
    sleep(number=2)
    try:
        number_rooms_data = driver.find_element_by_xpath(
            "/html/body/div[1]/div/main/section/div/div[1]/div/div[3]/div/div[2]/div/div"
        )

        if number_rooms_data:
            send_log(
                x_request_id=x_request_id,
                message="Found information about number of rooms...",
            )

            number_rooms = number_rooms_data.text

            # Start verification if has digit
            # then going to return. If do not have then return 0.
            return (int(re.findall(r"\d+", number_rooms)[0])
                    if verification_string_has_digit(x_request_id=x_request_id,
                                                     text=number_rooms) else 0)
    except (AttributeError, NoSuchElementException) as exception:
        error_handler(x_request_id=x_request_id, exception=exception)
def test_verification_string_has_digit_should_return_true():
    """Should return True in case of have digit in text"""
    text = "1batata"
    response = verification_string_has_digit(x_request_id="", text=text)
    assert response is True
    assert type(response) is bool
def test_verification_string_has_digit_should_return_false_in_case_of_none():
    "Should return False in case of text is None"
    text = None
    response = verification_string_has_digit(x_request_id="", text=text)
    assert response is False
    assert type(response) is bool
def test_verification_string_has_digit_should_return_false():
    "Should return False in case of not have any digit in text"
    text = "batata"
    response = verification_string_has_digit(x_request_id="", text=text)
    assert response is False
    assert type(response) is bool