Skip to content

Commit 750331b

Browse files
authored
Merge pull request #6 from chilispa/retry-status
Retry request for specific HTTP status codes
2 parents e8bafc1 + 4100ddf commit 750331b

File tree

7 files changed

+311
-180
lines changed

7 files changed

+311
-180
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pip install -U requests
1212
pip install -U robotframework-requests
1313
```
1414

15-
Here is a sample test case.
15+
Here is a sample test case:
1616

1717
| | | | | |
1818
| ---------------- | ------------------------------- | ------------------- | --------------------- | ------------- |

doc/RequestsLibrary.html

Lines changed: 10 additions & 9 deletions
Large diffs are not rendered by default.

src/RequestsLibrary/RequestsKeywords.py

Lines changed: 235 additions & 154 deletions
Large diffs are not rendered by default.

src/RequestsLibrary/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55

66

77
class RequestsLibrary(RequestsKeywords):
8-
""" RequestsLibrary is a HTTP client keyword library that uses
9-
the requests module from Kenneth Reitz
10-
https://github.com/kennethreitz/requests
8+
"""``RequestsLibrary`` is a HTTP client keyword library that uses
9+
test library that uses the [https://github.com/kennethreitz/requests|Requests] HTTP client.
1110
11+
Here is a sample test case:
1212
13-
Examples:
14-
| Create Session | google | http://www.google.com |
15-
| Create Session | github | http://github.com/api/v2/json |
16-
| ${resp} | Get google | / |
17-
| Should Be Equal As Strings | ${resp.status_code} | 200 |
18-
| ${resp} | Get github | /user/search/bulkan |
19-
| Should Be Equal As Strings | ${resp.status_code} | 200 |
20-
| ${jsondata} | To Json | ${resp.content} |
21-
| Dictionary Should Contain Value | ${jsondata['users'][0]} | Bulkan Savun Evcimen |
22-
13+
| ***** Settings ***** | | | | |
14+
| Library | Collections | | | |
15+
| Library | RequestsLibrary | | | |
16+
| ***** Test Cases ***** | | | | |
17+
| Get Requests | | | | |
18+
| | Create Session | github | http://api.github.com | |
19+
| | Create Session | google | http://www.google.com | |
20+
| | ${resp}= | Get Request | google | / |
21+
| | Should Be Equal As Strings | ${resp.status_code} | 200 | |
22+
| | ${resp}= | Get Request | github | /users/bulkan |
23+
| | Should Be Equal As Strings | ${resp.status_code} | 200 | |
24+
| | Dictionary Should Contain Value | ${resp.json()} | Bulkan Savun Evcimen | |
2325
"""
2426
ROBOT_LIBRARY_SCOPE = 'GLOBAL'

src/RequestsLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.6.1'
1+
VERSION = '0.6.2'

tests/test_retries.robot

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
*** Settings ***
2+
Library String
3+
Library Collections
4+
Library ../src/RequestsLibrary/RequestsKeywords.py
5+
6+
Suite Teardown Delete All Sessions
7+
8+
*** Test Cases ***
9+
Retry Session With Wrong Retry Status List
10+
[Tags] session retry
11+
${retry_status_list}= Create List 502baaad
12+
Run Keyword And Expect Error ValueError: * Create Session httpbin http://httpbin.org retry_status_list=${retry_status_list}
13+
14+
Retry Session With Empty Retry Status List
15+
[Tags] session retry
16+
${retry_status_list}= Set Variable ${Empty}
17+
Create Session httpbin http://httpbin.org retry_status_list=${retry_status_list}
18+
19+
Retry Get Request Because Of 502 Error With Default Config
20+
[Tags] get retry
21+
${retry_status_list}= Create List 502 503
22+
Create Session httpbin http://httpbin.org retry_status_list=${retry_status_list}
23+
Run Keyword And Expect Error RetryError: * Get Request httpbin /status/502
24+
25+
Retry Get Request Because Of 502 Error With Max Retries 1
26+
[Tags] get retry
27+
${retry_status_list}= Create List 502
28+
Create Session httpbin http://httpbin.org max_retries=1 retry_status_list=${retry_status_list}
29+
Run Keyword And Expect Error RetryError: * Get Request httpbin /status/502
30+
31+
Retry Disabled Get Request
32+
[Tags] get retry
33+
${retry_status_list}= Create List 502 503
34+
Create Session httpbin http://httpbin.org max_retries=0 retry_status_list=${retry_status_list}
35+
Get Request httpbin /status/502
36+
37+
Retry Post Request Because Of 502 Error With Default Config
38+
[Tags] post retry
39+
${retry_status_list}= Create List 502
40+
${retry_method_list}= Create List GET POST
41+
Create Session httpbin http://httpbin.org retry_status_list=${retry_status_list} retry_method_list=${retry_method_list}
42+
Run Keyword And Expect Error RetryError: * Post Request httpbin /status/502
43+
44+
Retry Post Request Because Of 502 Error With Wrong Config
45+
[Tags] post retry
46+
${retry_status_list}= Create List 502
47+
${retry_method_list}= Create List WRONG
48+
Create Session httpbin http://httpbin.org retry_status_list=${retry_status_list} retry_method_list=${retry_method_list}
49+
Post Request httpbin /status/502

tests/testcase.robot

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ Delete Request With URL Params
252252
${resp}= Delete Request httpbin /delete ${params}
253253
Should Be Equal As Strings ${resp.status_code} 200
254254

255-
256255
Delete Request With No Data
257256
[Tags] delete
258257
Create Session httpbin http://httpbin.org
259258
${resp}= Delete Request httpbin /delete
260259
Should Be Equal As Strings ${resp.status_code} 200
261260

262-
263261
Delete Request With Data
264262
[Tags] delete
265263
Create Session httpbin http://httpbin.org debug=3

0 commit comments

Comments
 (0)