Skip to content

Commit

Permalink
Adds keyword to get response from last request
Browse files Browse the repository at this point in the history
Removes some skipif decorators from the unit tests for old python versions
  • Loading branch information
PaulBrandUWV authored and lucagiove committed Nov 7, 2024
1 parent 6899855 commit a69ffca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
18 changes: 18 additions & 0 deletions atests/test_requests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,21 @@ Trace Request
[Tags] trace
${resp}= TRACE ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}

Get request with get response
[Tags] get
GET ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK
${resp}= Get response
Should be equal ${resp.status_code} ${200}
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything

Post request with get response
[Tags] post
${data}= Create dictionary key1=one key2=two key3=3
POST ${HTTP_LOCAL_SERVER}/anything json=${data}
Status Should Be OK
${resp}= Get response
Should be equal ${resp.status_code} ${200}
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything
Should be equal ${resp.json()}[json] ${data}
7 changes: 7 additions & 0 deletions src/RequestsLibrary/RequestsKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ def get_file_for_streaming_upload(path):
"""
return open(path, "rb")

@keyword("Get response")
def get_response(self) -> requests.Response:
"""
Returns the response from the last request.
"""
return self.last_response

@keyword("GET")
@warn_if_equal_symbol_in_url_session_less
def session_less_get(
Expand Down
6 changes: 0 additions & 6 deletions utests/test_RequestsKeywords.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sys

import pytest

from RequestsLibrary import RequestsLibrary
from utests import mock

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


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


@pytest.mark.skipif(sys.version_info < (3, 0), reason="different urljoin handling of double slash")
def test_merge_url_with_session_and_slash_endpoint_2trailing():
session, keywords = build_mocked_session_keywords('http://www.domain.com')
url = keywords._merge_url(session, '/endpoint//')
Expand Down
4 changes: 0 additions & 4 deletions utests/test_SessionKeywords.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import unittest

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

class TestUrlLibWarnings(unittest.TestCase):

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

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

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

0 comments on commit a69ffca

Please sign in to comment.