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 test for response headers #14074

Merged
merged 7 commits into from
Feb 28, 2019
Merged
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
6 changes: 4 additions & 2 deletions tools/webdriver/webdriver/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class Response(object):
body has been read and parsed as appropriate.
"""

def __init__(self, status, body):
def __init__(self, status, body, headers):
self.status = status
self.body = body
self.headers = headers

def __repr__(self):
cls_name = self.__class__.__name__
Expand All @@ -39,11 +40,12 @@ def error(self):
def from_http(cls, http_response, decoder=json.JSONDecoder, **kwargs):
try:
body = json.load(http_response, cls=decoder, **kwargs)
headers = dict(http_response.getheaders())
except ValueError:
raise ValueError("Failed to decode response body as JSON:\n" +
http_response.read())

return cls(http_response.status, body)
return cls(http_response.status, body, headers)


class HTTPWireProtocol(object):
Expand Down
19 changes: 17 additions & 2 deletions webdriver/tests/support/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def assert_error(response, error_code):
assert response.body["value"]["error"] == error_code
assert isinstance(response.body["value"]["message"], basestring)
assert isinstance(response.body["value"]["stacktrace"], basestring)
assert_response_headers(response.headers)


def assert_success(response, value=None):
"""
Verify that the provided webdriver.Response instance described
a valid error response as defined by `dfn-send-an-error` and
the provided error code.
a valid success response as defined by `dfn-send-a-response` and
the provided response value.

:param response: ``webdriver.Response`` instance.
:param value: Expected value of the response body, if any.
Expand All @@ -67,9 +68,23 @@ def assert_success(response, value=None):

if value is not None:
assert response.body["value"] == value

assert_response_headers(response.headers)
return response.body.get("value")


def assert_response_headers(headers):
"""
Method to assert response headers for WebDriver requests

:param headers: dict with header data
"""
assert 'cache-control' in headers
assert 'no-cache' == headers['cache-control']
assert 'content-type' in headers
assert 'application/json; charset=utf-8' == headers['content-type']


def assert_dialog_handled(session, expected_text, expected_retval):
# If there were any existing dialogs prior to the creation of this
# fixture's dialog, then the "Get Alert Text" command will return
Expand Down