Skip to content

Commit 9c3fca5

Browse files
PaulBrandUWVlucagiove
authored andcommitted
Adds keyword to get response from last request
Removes some skipif decorators from the unit tests for old python versions
1 parent 6899855 commit 9c3fca5

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

atests/test_requests.robot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,21 @@ Trace Request
282282
[Tags] trace
283283
${resp}= TRACE ${HTTP_LOCAL_SERVER}/anything
284284
Status Should Be OK ${resp}
285+
286+
Get request with get response
287+
[Tags] get
288+
GET ${HTTP_LOCAL_SERVER}/anything
289+
Status Should Be OK
290+
${resp}= Get response
291+
Should be equal ${resp.status_code} ${200}
292+
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything
293+
294+
Post request with get response
295+
[Tags] post
296+
${data}= Create dictionary key1=one key2=two key3=3
297+
POST ${HTTP_LOCAL_SERVER}/anything json=${data}
298+
Status Should Be OK
299+
${resp}= Get response
300+
Should be equal ${resp.status_code} ${200}
301+
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything
302+
Should be equal ${resp.json()}[json] ${data}

src/RequestsLibrary/RequestsKeywords.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ def get_file_for_streaming_upload(path):
168168
"""
169169
return open(path, "rb")
170170

171+
@keyword("Get response")
172+
def get_response(self) -> requests.Response:
173+
"""
174+
Returns the response from the last request.
175+
"""
176+
return self.last_response
177+
171178
@keyword("GET")
172179
@warn_if_equal_symbol_in_url_session_less
173180
def session_less_get(

utests/test_RequestsKeywords.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import sys
2-
3-
import pytest
4-
51
from RequestsLibrary import RequestsLibrary
62
from utests import mock
73

@@ -69,14 +65,12 @@ def test_merge_url_with_session_url_path_slash_and_uri_endpoint():
6965
assert url == 'http://www.domain.com/path/endpoint'
7066

7167

72-
@pytest.mark.skipif(sys.version_info < (3, 0), reason="different urljoin handling of double slash")
7368
def test_merge_url_with_session2trailing_and_endpoint():
7469
session, keywords = build_mocked_session_keywords('http://www.domain.com//')
7570
url = keywords._merge_url(session, 'endpoint')
7671
assert url == 'http://www.domain.com/endpoint'
7772

7873

79-
@pytest.mark.skipif(sys.version_info < (3, 0), reason="different urljoin handling of double slash")
8074
def test_merge_url_with_session_and_slash_endpoint_2trailing():
8175
session, keywords = build_mocked_session_keywords('http://www.domain.com')
8276
url = keywords._merge_url(session, '/endpoint//')

utests/test_SessionKeywords.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import unittest
32

43
from RequestsLibrary import compat
@@ -13,14 +12,12 @@ def test_session_class_extends_keywords_class():
1312

1413
class TestUrlLibWarnings(unittest.TestCase):
1514

16-
@unittest.skipIf(sys.version_info < (3, 2), "python version doesn't support assertWarns")
1715
def test_get_default_retry_method_list_not_raise_warning(self):
1816
with self.assertRaises(AssertionError):
1917
with self.assertWarns(DeprecationWarning):
2018
DEFAULT_RETRY_METHOD_LIST = compat.RetryAdapter.get_default_allowed_methods()
2119
assert "GET" in DEFAULT_RETRY_METHOD_LIST
2220

23-
@unittest.skipIf(sys.version_info < (3, 2), "python version doesn't support assertWarns")
2421
def test_init_retry_adapter_not_raise_warning(self):
2522
with self.assertRaises(AssertionError):
2623
with self.assertWarns(DeprecationWarning):
@@ -29,7 +26,6 @@ def test_init_retry_adapter_not_raise_warning(self):
2926
status_forcelist=[500],
3027
allowed_methods=['GET'])
3128

32-
@unittest.skipIf(sys.version_info < (3, 2), "python version doesn't support assertWarns")
3329
def test_create_session_retry_not_raise_warning(self):
3430
keywords = SessionKeywords()
3531
with self.assertRaises(AssertionError):

0 commit comments

Comments
 (0)