Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyword to get response from last request #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -152,6 +152,13 @@
"""
return open(path, "rb")

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

Check warning on line 160 in src/RequestsLibrary/RequestsKeywords.py

View check run for this annotation

Codecov / codecov/patch

src/RequestsLibrary/RequestsKeywords.py#L160

Added line #L160 was not covered by tests

@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
Loading