Skip to content

Commit

Permalink
tests: test_create_users_to_http, test_post_create_user_response_is_n…
Browse files Browse the repository at this point in the history
…ot_empty
  • Loading branch information
Nat754 committed Feb 20, 2024
1 parent f1ed891 commit 31f2219
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions base/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ def assert_key_value_is_in_response(response: Response, data, key_name):
expected_key = data[key_name]
with allure.step(f'Actual key is {expected_key}'):
assert actual_key == expected_key, f'Actual key {expected_key} is not in response'

@staticmethod
def assert_response_is_not_empty(response: Response):
"""Check response has json format and is not empty"""
with allure.step('Response has JSON format and is not empty'):
assert 'application/json' in response.headers.get('Content-Type', '') and 'application/json' != {}, \
'Error: Response is not in JSON format'
14 changes: 13 additions & 1 deletion tests/create_users_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import allure
import pytest
import requests

from base.assertions import Assertions
from data.constant import StatusCode, Data, Constant
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_get_create_user(self):
Assertions.assert_code_status(response, self.status.STATUS_CODE_200)

@pytest.mark.xfail(reason='Bag')
@allure.title('POST Создать пользователя без тела запроса')
@allure.title('POST Create user without request body')
def test_post_create_user_without_body(self):
response = BaseRequests.post(url='api/users')
Assertions.assert_is_not_code_status(response, self.status.STATUS_CODE_201)
Expand Down Expand Up @@ -78,3 +79,14 @@ def test_post_create_user_with_none_name(self):
def test_post_create_user_as_none(self):
response = BaseRequests.post(url='api/users', headers={})
Assertions.assert_is_not_code_status(response, self.status.STATUS_CODE_201)

@pytest.mark.xfail(reason='Bag')
@allure.title("POST Create user get to http")
def test_create_users_to_http(self):
response = requests.post(url=f'{self.constant.WRONG_URL}api/users', headers=self.data.CREATE_USER)
Assertions.assert_is_not_code_status(response, self.status.STATUS_CODE_200)

@allure.title('POST Create user response is not empty')
def test_post_create_user_response_is_not_empty(self):
response = BaseRequests.post(url='api/users', headers=self.data.CREATE_USER)
Assertions.assert_response_is_not_empty(response)

0 comments on commit 31f2219

Please sign in to comment.