Skip to content

Commit b0db62b

Browse files
committed
Added timeouts to requests calls
1 parent 5964d9b commit b0db62b

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

features/steps/pets_steps.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######################################################################
2-
# Copyright 2016, 2023 John J. Rofrano. All Rights Reserved.
2+
# Copyright 2016, 2024 John J. Rofrano. All Rights Reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,24 +23,29 @@
2323
https://selenium-python.readthedocs.io/waits.html
2424
"""
2525
import requests
26-
from behave import given
26+
from compare3 import expect
27+
from behave import given # pylint: disable=no-name-in-module
2728

2829
# HTTP Return Codes
2930
HTTP_200_OK = 200
3031
HTTP_201_CREATED = 201
3132
HTTP_204_NO_CONTENT = 204
3233

34+
WAIT_TIMEOUT = 60
35+
36+
3337
@given('the following pets')
3438
def step_impl(context):
3539
""" Delete all Pets and load new ones """
3640

37-
# List all of the pets and delete them one by one
41+
# Get a list all of the pets
3842
rest_endpoint = f"{context.base_url}/pets"
39-
context.resp = requests.get(rest_endpoint)
40-
assert(context.resp.status_code == HTTP_200_OK)
43+
context.resp = requests.get(rest_endpoint, timeout=WAIT_TIMEOUT)
44+
expect(context.resp.status_code).equal_to(HTTP_200_OK)
45+
# and delete them one by one
4146
for pet in context.resp.json():
42-
context.resp = requests.delete(f"{rest_endpoint}/{pet['id']}")
43-
assert(context.resp.status_code == HTTP_204_NO_CONTENT)
47+
context.resp = requests.delete(f"{rest_endpoint}/{pet['id']}", timeout=WAIT_TIMEOUT)
48+
expect(context.resp.status_code).equal_to(HTTP_204_NO_CONTENT)
4449

4550
# load the database with new pets
4651
for row in context.table:
@@ -51,5 +56,5 @@ def step_impl(context):
5156
"gender": row['gender'],
5257
"birthday": row['birthday']
5358
}
54-
context.resp = requests.post(rest_endpoint, json=payload)
55-
assert(context.resp.status_code == HTTP_201_CREATED)
59+
context.resp = requests.post(rest_endpoint, json=payload, timeout=WAIT_TIMEOUT)
60+
expect(context.resp.status_code).equal_to(HTTP_201_CREATED)

features/steps/web_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######################################################################
2-
# Copyright 2016, 2023 John J. Rofrano. All Rights Reserved.
2+
# Copyright 2016, 2024 John J. Rofrano. All Rights Reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
https://selenium-python.readthedocs.io/waits.html
2626
"""
2727
import logging
28-
from behave import when, then
28+
from behave import when, then # pylint: disable=no-name-in-module
2929
from selenium.webdriver.common.by import By
3030
from selenium.webdriver.support.ui import Select, WebDriverWait
3131
from selenium.webdriver.support import expected_conditions

0 commit comments

Comments
 (0)