-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_6_booking_delete.py
80 lines (67 loc) · 3.31 KB
/
test_6_booking_delete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import allure
import requests
import pytest
import test_1_booking_token
import test_2_booking_create
@allure.feature('Booking Feature')
@allure.suite('Delete Booking Suite')
@allure.title('Test Delete Booking by ID with Valid Token')
@allure.description('Test to delete a booking by ID using a valid token and verify the response.')
@allure.severity(allure.severity_level.CRITICAL)
@pytest.mark.smoke
@pytest.mark.regression
def test_delete_booking_by_id_valid_token():
headers = {
'Content-Type': 'application/json',
'Cookie': f'token={test_1_booking_token.my_token}'
}
with allure.step('Send DELETE request to delete a booking by ID using a valid token'):
response = requests.delete(
f'https://restful-booker.herokuapp.com/booking/{test_2_booking_create.my_bookingid}',
headers=headers
)
with allure.step('Verify response status code is 201'):
assert response.status_code == 201, f'Expected status code 201, but got {response.status_code}'
# # Note: After deletion by ID with a valid token, this test is expected to fail
# # because the resource has been successfully removed. Ensure that the test accounts
# # for this scenario and validates the appropriate error response or status.
# # Recommendation: Comment out the test_delete_booking_by_id_valid_token function
# # and re-run the test suite to ensure that the rest of the tests function correctly.
@allure.feature('Booking Feature')
@allure.suite('Delete Booking Suite')
@allure.title('Test Delete Booking with Basic Authorization')
@allure.description('Test to delete a booking delete using Basic Authorization and expects a status code of 201 for successful deletion.')
@allure.severity(allure.severity_level.CRITICAL)
@pytest.mark.smoke
@pytest.mark.regression
def test_delete_booking_by_id_basic_auth():
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic YWRtaW46cGFzc3dvcmQxMjM='
}
with allure.step('Send DELETE request to delete a booking by ID using Basic Authorization'):
response = requests.delete(
f'https://restful-booker.herokuapp.com/booking/{test_2_booking_create.my_bookingid}',
headers=headers
)
with allure.step('Verify the response status code is 201'):
assert response.status_code == 201, f'Expected status code 201, but got {response.status_code}'
@allure.feature('Booking Feature')
@allure.suite('Delete Booking Suite')
@allure.title('Test Delete Booking by ID with Error Status Code')
@allure.description('This test is intentionally designed to verify handling of an error status code (403) when attempting to delete a booking.')
@allure.severity(allure.severity_level.CRITICAL)
@pytest.mark.smoke
@pytest.mark.regression
def test_delete_booking_with_incorrect_response_status_code():
headers = {
'Content-Type': 'application/json',
'Cookie': f'token={test_1_booking_token.my_token}'
}
with allure.step('Send DELETE request to delete a booking by ID'):
response = requests.delete(
f'https://restful-booker.herokuapp.com/booking/{test_2_booking_create.my_bookingid}',
headers=headers
)
with allure.step('Verify response status code is 200'):
assert response.status_code == 200, f' Expected status code 200, but got {response.status_code}'