Exception message says `Content should be a callback or binary data` in method create_response where the check is only for `binary_type`

Bug #1627506 reported by Voith Mascarenhas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
requests-mock
Fix Released
Undecided
Jamie Lennox

Bug Description

Hi,
I was reading the code for request-mock and found a minor mistake which I'd like to point out.
The following lines https://github.com/openstack/requests-mock/blob/master/requests_mock/response.py#L150-#L153 in the current code says that `Content should be a callback or binary data`, but there is no check for callable there, unlike lines https://github.com/openstack/requests-mock/blob/master/requests_mock/response.py#L210-L216

From what I understood by reading the code, method `create_response` should receive content as binary data. The error message should be modified to `Content should be binary data`. The same thing applies for parameter `text`.

description: updated
Revision history for this message
Voith Mascarenhas (voith) wrote :

I have opened a PR here: https://github.com/openstack/requests-mock/pull/8.

Please excuse me for my English. I don't know if the sentence I modified is grammatically right. Feel free to point out errors.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to requests-mock (master)

Fix proposed to branch: master
Review: https://review.openstack.org/376057

Changed in requests-mock:
assignee: nobody → Jamie Lennox (jamielennox)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to requests-mock (master)

Reviewed: https://review.openstack.org/376057
Committed: https://git.openstack.org/cgit/openstack/requests-mock/commit/?id=890a4fe9ff04e287c0170a29a0c57771fcef8407
Submitter: Jenkins
Branch: master

commit 890a4fe9ff04e287c0170a29a0c57771fcef8407
Author: voith <email address hidden>
Date: Sun Sep 25 20:49:06 2016 +0530

    Fix exception message when creating a response

    When you register a handler the type for text or data can be a string or
    a callback that provides a string. By the time you get to
    create_response this callback should have been called and only a string
    can be passed.

    This check originally would have been in place for when a callback was
    run and the return value was not the expected type, however
    create_response is a public function that can be used on its own.

    Correct the exception to clarify in create_response you must pass a
    string or bytes and not a callback.

    Change-Id: I3e700afddc1f40454f69a564066495bfc77d91c8
    Closes-Bug: #1627506

Changed in requests-mock:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.