def test_add_stub_to_running_impostor(mock_server): impostor = Imposter( Stub(Predicate(path="/test0"), Response(body="response0")), default_response=HttpResponse(body="default"), ) with mock_server(impostor): responses = [requests.get(f"{impostor.url}/test{i}") for i in range(3)] assert_that( responses, contains_exactly( is_response().with_body("response0"), is_response().with_body("default"), is_response().with_body("default"), ), ) index = impostor.add_stub( Stub(Predicate(path="/test1"), Response(body="response1")), ) assert index == 1 responses = [requests.get(f"{impostor.url}/test{i}") for i in range(3)] assert_that( responses, contains_exactly( is_response().with_body("response0"), is_response().with_body("response1"), is_response().with_body("default"), ), )
def test_remove_and_replace_stub_from_running_impostor(mock_server): impostor = Imposter( stubs=[ Stub(Predicate(path="/test0"), Response(body="response0")), Stub(Predicate(path="/test1"), Response(body="response1")), Stub(Predicate(path="/test2"), Response(body="response2")), ], default_response=HttpResponse(body="default"), ) with mock_server(impostor): responses = [requests.get(f"{impostor.url}/test{i}") for i in range(3)] assert_that( responses, contains_exactly( is_response().with_body("response0"), is_response().with_body("response1"), is_response().with_body("response2"), ), ) impostor.delete_stub(1) responses = [requests.get(f"{impostor.url}/test{i}") for i in range(3)] assert_that( responses, contains_exactly( is_response().with_body("response0"), is_response().with_body("default"), is_response().with_body("response2"), ), ) impostor.add_stub(Stub(Predicate(path="/test1"), Response(body="response1"))) responses = [requests.get(f"{impostor.url}/test{i}") for i in range(3)] assert_that( responses, contains_exactly( is_response().with_body("response0"), is_response().with_body("response1"), is_response().with_body("response2"), ), )