Skip to content

Добавлены тесты#1

Open
julia7774 wants to merge 3 commits intomainfrom
develop
Open

Добавлены тесты#1
julia7774 wants to merge 3 commits intomainfrom
develop

Conversation

@julia7774
Copy link
Owner

No description provided.

if response.status_code != 200:
pytest.fail("Ошибка авторизации тестового курьера")

response = ScooterClient.courier_delete(response.json()["id"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему курьер удаляется в предусловии, вероятно нужно после теста это делать?
также имеет смысл выделить фикстуру удаления отдельно, она будет нужна для тестов на создание курьера

assert response.status_code == 201
assert response.json() == {"ok": True}

with allure.step("Отправить POST запрос на авторизацию созданного курьера"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно исправить: этот код уже был, стоит реализовать фикстурой, т.к мы хотим в любом случае попытаться очистить бд, даже если не создан курьер


response = ScooterClient.courier_login(login, password)
if response.status_code != 200:
pytest.fail("Ошибка авторизации тестового курьера")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это постусловие, отмечать тест упавшим из-за постусловия - это немного слишком

"empty"
],
)
def test_missing(self, courier, use_login, use_password, step):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно исправить: название теста непонятное


class TestCourierLogin:
@allure.title("Проверка авторизации курьера")
def test(self, courier):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно исправить везде: проследи что из названия теста ясно что проверяем и на какой результат

login, password = courier

with allure.step(f"Отправить POST запрос на авторизацию курьера без указания: {step}"):
response = ScooterClient.courier_login(login if use_login else None, password if use_password else None)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: условий в тестах быть не может, тест всегда однозначен. Если это не вписывается в параметризацию, значит ее быть не должно и это просто несколько отдельных тестовых методов

response = ScooterClient.courier_login(login if use_login else None, password if use_password else None)

if response.status_code == 504:
pytest.skip("Некорректная работа API")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ошибки должны обрабатываться в assert, если код неверный то это фейл

]
)
def test_with_missing_fields(self, login, password, firstName, step):
with allure.step(f"Отправить POST запрос на создание курьера без указания: {step}"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отлично: понятные описания шагов для отчета

client.py Outdated
@staticmethod
def courier_create(login, password, firstName):
payload = {}
if login:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: условий в тестах быть не должно, мы хотим точно знать какие были шаги

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот класс не является частью теста. Это просто класс-клиент в котором описаны запросы в api, чтобы их не приходилось копировать в каждом тесте

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот класс вместе со всем ветвлением вызывается в тесте. от того что мы перенесли ветвление и спрятали его внутрь вызываемого метода оно не исчезло

client.py Outdated
@staticmethod
def courier_login(login, password):
payload = {}
if login:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно убрать условия из тестов

client.py Outdated
@staticmethod
def order_list(courierId, nearestStation, limit, page):
params = {}
if courierId:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up


assert response.status_code == 201
assert response.json() == {"ok": True}
courier_delete(login, password)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: фикстура выполнится сама если в ней есть yield

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь не используется фикстура в которой есть yield, так как здесь мы внутри теста создаем нового курьера и вызываем отдельно фикстуру для удаления курьера (очищение данных)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мы можем передавать данные курьера которого создали в тесте обратно в фикстуру

)
def test_with_missing_fields(self, login, password, firstName, step):
with allure.step(f"Отправить POST запрос на создание курьера без указания: {step}"):
response = ScooterClient.courier_create(login, password, firstName)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не исправлено - ветвление кода осталось

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь нет ветвления кода, просто 6 наборов входных параметров

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в методе courier_create есть ветвление и оно вызывается внутри теста. пейлоад формируется внутри теста, а не передается входными параметрами.

Мы действительно можем в этом тесте передать 6 пейлоадов для теста и это будет работать. но сейчас реализовано так что внутри теста есть условия и нелинейное поведение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments