Skip to content

support bodies with unicode #33

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

Open
wants to merge 3 commits 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
14 changes: 7 additions & 7 deletions src/HttpLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def set_request_header(self, header_name, header_value):
"""
logger.info(
'Set request header "%s" to "%s"' % (header_name, header_value))
self.context.request_headers[header_name] = header_value
self.context.request_headers[str(header_name)] = header_value

def set_basic_auth(self, username, password):
"""
Expand Down Expand Up @@ -471,7 +471,7 @@ def get_response_body(self):
| ${body}= | Get Response Body | |
| Should Start With | ${body} | <?xml version="1.0" encoding="UTF-8" |
"""
return self.response.body
return self.response.body.decode("utf-8")

def response_body_should_contain(self, should_contain):
"""
Expand All @@ -483,21 +483,21 @@ def response_body_should_contain(self, should_contain):
| Response Body Should Contain | encoding="UTF-8" |
"""
logger.debug('Testing whether "%s" contains "%s".' % (
self.response.body, should_contain))
self.get_response_body(), should_contain))

assert should_contain in self.response.body, \
assert should_contain in self.get_response_body(), \
'"%s" should have contained "%s", but did not.' % (
self.response.body, should_contain)
self.get_response_body(), should_contain)

def log_response_body(self, log_level='INFO'):
"""
Logs the response body.

Specify `log_level` (default: "INFO") to set the log level.
"""
if self.response.body:
if self.get_response_body():
logger.write("Response body:", log_level)
logger.write(self.response.body, log_level)
logger.write(self.get_response_body(), log_level)
else:
logger.debug("No response body received", log_level)

Expand Down
17 changes: 17 additions & 0 deletions tests/http/simple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ POST with one word request body
POST /echo
Response Body Should Contain Tooot

POST with Unicode request body
[Documentation] Unicode in response body must not break 'should contain'
[Tags] unicode
Set Request Body Tschüss Süße
Set Request Header Content-Type text/plain
POST /echo
Response Body Should Contain Tschüss Süße

POST with Unicode request body and Accept Header
[Documentation] Request body and headers must allow to be concatenated
[Tags] unicode
Set Request Body Tschüss Süße
Set Request Header Accept application/json
Set Request Header Content-Type text/plain
POST /echo
Response Body Should Contain Tschüss Süße

PUT with two word request body
Set Request Body Tooot Tooooot
Set Request Header Content-Type text/plain
Expand Down