Example #1
0
def test_patch_part_fields(booker_api, first, last):
    """Тестовая функция для проверки вызова patch запроса с передаваемым телом.
    Проверяются позитивные варианты через параметризацию -
    обновление значений "firstname", "lastname".
    Обращение напрямую к определенному id в урле.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    :param first: передаваемый в теле запроса firstname
    :param last: передаваемый в теле запроса lastname
    """
    id_to_do_request = body_id_data.create_test_entity(booker_api)

    with allure.step("Получаем все данные сущности"):
        data_for_id = body_id_data.TestDictForRequests().return_dict_other()

    data = {"firstname": first, "lastname": last}

    with allure.step(allure_steps.send_patch_request(data, id_to_do_request)):
        response = booker_api.patch(path=id_to_do_request,
                                    data=json.dumps(data))

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(allure_steps.check_firstname(first)):
        assert response.json()["firstname"] == first, \
            f"Имя - '{response.json()['firstname']}'"

    with allure.step(allure_steps.check_lastname(last)):
        assert response.json()["lastname"] == last, \
            f"Фамилия - '{response.json()['lastname']}'"

    with allure.step(allure_steps.check_totalprice(data_for_id['totalprice'])):
        assert response.json()["totalprice"] == data_for_id["totalprice"], \
            f"Итоговая цена - '{response.json()['totalprice']}'"

    with allure.step(allure_steps.check_depositpaid(
            data_for_id['depositpaid'])):
        assert response.json()["depositpaid"] == data_for_id["depositpaid"], \
            f"Депозит - '{response.json()['depositpaid']}'"

    with allure.step(
            allure_steps.check_checkin(
                data_for_id['bookingdates']['checkin'])):
        assert response.json()["bookingdates"]["checkin"] == \
            data_for_id["bookingdates"]["checkin"], \
            f"Дата заезда - '{response.json()['bookingdates']['checkin']}'"

    with allure.step(
            allure_steps.check_checkout(
                data_for_id['bookingdates']['checkout'])):
        assert response.json()["bookingdates"]["checkout"] == \
            data_for_id["bookingdates"]["checkout"], \
            f"Дата выезда - '{response.json()['bookingdates']['checkout']}'"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)
Example #2
0
def test_put_all_fields(booker_api):
    """Тестовая функция для проверки вызова put запроса с передаваемым телом.
    Проверяется обновление всех значений.
    Обращение напрямую к определенному id в урле.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    """
    data = body_id_data.TestDictForRequests().return_dict()

    id_to_do_request = body_id_data.create_test_entity(booker_api)

    with allure.step(allure_steps.send_put_request(data, id_to_do_request)):
        response = booker_api.put(path=id_to_do_request, data=json.dumps(data))

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(allure_steps.check_firstname(data['firstname'])):
        assert response.json()["firstname"] == data['firstname'], \
            f"Имя - '{response.json()['firstname']}'"

    with allure.step(allure_steps.check_lastname(data['lastname'])):
        assert response.json()["lastname"] == data['lastname'], \
            f"Фамилия - '{response.json()['lastname']}'"

    with allure.step(allure_steps.check_totalprice(data['totalprice'])):
        assert response.json()["totalprice"] == data['totalprice'], \
            f"Итоговая цена - '{response.json()['totalprice']}'"

    with allure.step(allure_steps.check_depositpaid(data['depositpaid'])):
        assert response.json()["depositpaid"] == data['depositpaid'], \
            f"Депозит - '{response.json()['depositpaid']}'"

    with allure.step(
            allure_steps.check_checkin(data['bookingdates']['checkin'])):
        assert response.json()["bookingdates"]["checkin"] ==\
               data['bookingdates']['checkin'], \
               f"Дата заезда - '{response.json()['bookingdates']['checkin']}'"

    with allure.step(
            allure_steps.check_checkout(data['bookingdates']['checkout'])):
        assert response.json()["bookingdates"]["checkout"] == \
               data['bookingdates']['checkout'], \
               f"Дата выезда - '{response.json()['bookingdates']['checkout']}'"

    with allure.step(allure_steps.check_addneeds(data['additionalneeds'])):
        assert response.json()["additionalneeds"] == \
               data['additionalneeds'], \
               f"Депозит - '{response.json()['additionalneeds']}'"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)
Example #3
0
def test_patch_empty_body(booker_api):
    """Тестовая функция для проверки вызова patch запроса с передаваемым телом.
    Проверяется передача пустого тела.
    Обращение напрямую к определенному id в урле.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    """
    id_to_do_request = body_id_data.create_test_entity(booker_api)

    with allure.step("Получаем все данные сущности"):
        data_for_id = body_id_data.TestDictForRequests().return_dict_other()

    with allure.step(
            f"Отправляем patch запрос с пустым телом и id {id_to_do_request}"):
        response = booker_api.patch(path=id_to_do_request, data={})

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(allure_steps.check_firstname(data_for_id['firstname'])):
        assert response.json()["firstname"] == data_for_id["firstname"], \
            f"Имя - '{response.json()['firstname']}'"

    with allure.step(allure_steps.check_lastname(data_for_id['lastname'])):
        assert response.json()["lastname"] == data_for_id["lastname"], \
            f"Фамилия - '{response.json()['lastname']}'"

    with allure.step(allure_steps.check_totalprice(data_for_id['totalprice'])):
        assert response.json()["totalprice"] == data_for_id["totalprice"], \
            f"Итоговая цена - '{response.json()['totalprice']}'"

    with allure.step(allure_steps.check_depositpaid(
            data_for_id['depositpaid'])):
        assert response.json()["depositpaid"] == data_for_id["depositpaid"], \
            f"Депозит - '{response.json()['depositpaid']}'"

    with allure.step(
            allure_steps.check_checkin(
                data_for_id['bookingdates']['checkin'])):
        assert response.json()["bookingdates"]["checkin"] == \
            data_for_id["bookingdates"]["checkin"], \
            f"Дата заезда - '{response.json()['bookingdates']['checkin']}'"

    with allure.step(
            allure_steps.check_checkout(
                data_for_id['bookingdates']['checkout'])):
        assert response.json()["bookingdates"]["checkout"] == \
            data_for_id["bookingdates"]["checkout"], \
            f"Дата выезда - '{response.json()['bookingdates']['checkout']}'"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)
def test_delete_by_id_positive(booker_api):
    """Тестовая функция для проверки вызова delete запроса.
    Проверяются позитивные варианты через параметризацию - существующие id.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    """
    id_to_do_request = body_id_data.create_test_entity(booker_api)

    with allure.step(allure_steps.send_delete_request(id_to_do_request)):
        response = booker_api.delete(path=id_to_do_request)

    with allure.step(allure_steps.check_201_status_code()):
        assert response.status_code == 201, f"Код ответа - {response.status_code}"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)
def test_get_by_id_positive(booker_api):
    """Тестовая функция для проверки вызова get запроса.
    Проверяются позитивные варианты для id через параметризацию.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    """
    id_to_do_request = body_id_data.create_test_entity(booker_api)

    with allure.step(allure_steps.send_get_request(id_to_do_request)):
        response = booker_api.get(path=id_to_do_request)

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(f"Проверяем длину тела ответа сущности с id {id_to_do_request}"):
        assert len(response.json()) != 0, "Такой сущности не существует"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)
Example #6
0
def test_post_lastname(booker_api, param):
    """Тестовая функция для проверки вызова post запроса.
    Проверяются позитивные варианты для "lastname" через параметризацию.

    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    :param param: передаваемые в теле запроса варианты для "lastname"
    """
    data = body_id_data.TestDictForRequests().return_dict_with_lastname(param)

    with allure.step(f"Отправляем post запрос с lastname - '{param}'"):
        response = booker_api.post(data=json.dumps(data))

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(allure_steps.check_lastname(param)):
        assert response.json()["booking"]["lastname"] == param, \
            f"Фамилия - '{response.json()['booking']['lastname']}'"

    body_id_data.delete_test_entity(booker_api, response.json()['bookingid'])
Example #7
0
def test_get_by_lastname_positive(booker_api, param):
    """Тестовая функция для проверки вызова get запроса с передаваемым в урле параметром.
    Проверяются позитивные варианты через параметризацию -
    для передачи параметра lastname в урле.
    :param booker_api: фикстура, создающая и возвращающая экземпляр класса ApiClient
    :param param: передаваемый в урле параметр lastname
    """
    id_to_do_request = body_id_data.create_test_entity(booker_api)
    payload = {"lastname": param}

    with allure.step(allure_steps.send_get_request_with_param(payload)):
        response = booker_api.get(params=payload)

    with allure.step(allure_steps.check_200_status_code()):
        assert response.status_code == 200, f"Код ответа - {response.status_code}"

    with allure.step(f"Проверяем, что у '{param}' есть бронь"):
        assert len(response.json()) != 0, f"У '{param}' нет брони"

    body_id_data.delete_test_entity(booker_api, id_to_do_request)