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

Allow calls to requsts between calls to responses.add #375

Closed
wants to merge 7 commits into from

Conversation

Jlrine2
Copy link

@Jlrine2 Jlrine2 commented Mar 4, 2021

This change allows the use of multiple responses intermixed by calls to requests by removing previous matches that have already been called if multiple exist.

@codecov
Copy link

codecov bot commented Mar 4, 2021

Codecov Report

Merging #375 (aaf6838) into master (52e7484) will increase coverage by 0.11%.
The diff coverage is 100.00%.

❗ Current head aaf6838 differs from pull request most recent head bcf04d8. Consider uploading reports for the commit bcf04d8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #375      +/-   ##
==========================================
+ Coverage   96.51%   96.63%   +0.11%     
==========================================
  Files           3        3              
  Lines        1319     1365      +46     
==========================================
+ Hits         1273     1319      +46     
  Misses         46       46              
Impacted Files Coverage Δ
responses/__init__.py 97.78% <100.00%> (+0.05%) ⬆️
responses/test_responses.py 98.21% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52e7484...bcf04d8. Read the comment docs.

responses/__init__.py Outdated Show resolved Hide resolved
@Jlrine2 Jlrine2 requested a review from markstory March 31, 2021 21:18
@Jlrine2
Copy link
Author

Jlrine2 commented Apr 5, 2021

@markstory Is this good to go?

responses/__init__.py Outdated Show resolved Hide resolved
responses/__init__.py Outdated Show resolved Hide resolved
assert_response(resp, "best")

run()
assert_reset()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be missing some coverage on multiple responses. These changes cause the following test to fail, while it current passes on master.

def test_multiple_responses_out_of_order_two():
    @responses.activate
    def run():
        responses.add(responses.GET, "http://example.com", body="test")
        responses.add(responses.GET, "http://example.com", body="rest")
        responses.add(responses.GET, "http://example.com", body="fest")
        responses.add(responses.GET, "http://example.com", body="best")

        resp = requests.get("http://example.com")
        assert_response(resp, "test")

        resp = requests.get("http://example.com")
        assert_response(resp, "rest")

        resp = requests.get("http://example.com")
        assert_response(resp, "fest")

        resp = requests.get("http://example.com")
        assert_response(resp, "best")

        # After all responses are used, last response should be repeated
        resp = requests.get("http://example.com")
        assert_response(resp, "best")

    run()
    assert_reset()

Jlrine2 and others added 2 commits April 29, 2021 14:10
@beliaev-maksim
Copy link
Collaborator

@markstory
we can close current PR as #455 is merged

@markstory markstory closed this Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants