def test_nesting_cassette_context_managers(*args): first_response = { "body": { "string": b"first_response" }, "headers": {}, "status": { "message": "m", "code": 200 }, } second_response = copy.deepcopy(first_response) second_response["body"]["string"] = b"second_response" with contextlib.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use(path="test")) exit_stack.enter_context( mock.patch.object(first_cassette, "play_response", return_value=first_response)) assert_get_response_body_is("first_response") # Make sure a second cassette can supercede the first with Cassette.use(path="test") as second_cassette: with mock.patch.object(second_cassette, "play_response", return_value=second_response): assert_get_response_body_is("second_response") # Now the first cassette should be back in effect assert_get_response_body_is("first_response")
def test_nesting_cassette_context_managers(*args): first_response = { 'body': { 'string': b'first_response' }, 'headers': {}, 'status': { 'message': 'm', 'code': 200 } } second_response = copy.deepcopy(first_response) second_response['body']['string'] = b'second_response' with contextlib2.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use('test')) exit_stack.enter_context( mock.patch.object(first_cassette, 'play_response', return_value=first_response)) assert_get_response_body_is('first_response') # Make sure a second cassette can supercede the first with Cassette.use('test') as second_cassette: with mock.patch.object(second_cassette, 'play_response', return_value=second_response): assert_get_response_body_is('second_response') # Now the first cassette should be back in effect assert_get_response_body_is('first_response')
def test_nesting_context_managers_by_checking_references_of_http_connection(): original = httplib.HTTPConnection with Cassette.use(path="test"): first_cassette_HTTPConnection = httplib.HTTPConnection with Cassette.use(path="test"): second_cassette_HTTPConnection = httplib.HTTPConnection assert second_cassette_HTTPConnection is not first_cassette_HTTPConnection with Cassette.use(path="test"): assert httplib.HTTPConnection is not second_cassette_HTTPConnection with force_reset(): assert httplib.HTTPConnection is original assert httplib.HTTPConnection is second_cassette_HTTPConnection assert httplib.HTTPConnection is first_cassette_HTTPConnection
def test_nesting_context_managers_by_checking_references_of_http_connection(): original = httplib.HTTPConnection with Cassette.use(path='test'): first_cassette_HTTPConnection = httplib.HTTPConnection with Cassette.use(path='test'): second_cassette_HTTPConnection = httplib.HTTPConnection assert second_cassette_HTTPConnection is not first_cassette_HTTPConnection with Cassette.use(path='test'): assert httplib.HTTPConnection is not second_cassette_HTTPConnection with force_reset(): assert httplib.HTTPConnection is original assert httplib.HTTPConnection is second_cassette_HTTPConnection assert httplib.HTTPConnection is first_cassette_HTTPConnection
def test_custom_patchers(): class Test(object): attribute = None with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)): assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute old_attribute = Test.attribute with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)): assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute assert Test.attribute is not old_attribute assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute assert Test.attribute is old_attribute
def test_custom_patchers(): class Test(object): attribute = None with Cassette.use(path='custom_patches', custom_patches=((Test, 'attribute', VCRHTTPSConnection),)): assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute old_attribute = Test.attribute with Cassette.use(path='custom_patches', custom_patches=((Test, 'attribute', VCRHTTPSConnection),)): assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute assert Test.attribute is not old_attribute assert issubclass(Test.attribute, VCRHTTPSConnection) assert VCRHTTPSConnection is not Test.attribute assert Test.attribute is old_attribute
def test_nesting_cassette_context_managers(*args): first_response = {"body": {"string": b"first_response"}, "headers": {}, "status": {"message": "m", "code": 200}} second_response = copy.deepcopy(first_response) second_response["body"]["string"] = b"second_response" with contextlib.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use(path="test")) exit_stack.enter_context(mock.patch.object(first_cassette, "play_response", return_value=first_response)) assert_get_response_body_is("first_response") # Make sure a second cassette can supercede the first with Cassette.use(path="test") as second_cassette: with mock.patch.object(second_cassette, "play_response", return_value=second_response): assert_get_response_body_is("second_response") # Now the first cassette should be back in effect assert_get_response_body_is("first_response")
def test_nesting_cassette_context_managers(*args): first_response = {'body': {'string': b'first_response'}, 'headers': {}, 'status': {'message': 'm', 'code': 200}} second_response = copy.deepcopy(first_response) second_response['body']['string'] = b'second_response' with contextlib.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use(path='test')) exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response', return_value=first_response)) assert_get_response_body_is('first_response') # Make sure a second cassette can supercede the first with Cassette.use(path='test') as second_cassette: with mock.patch.object(second_cassette, 'play_response', return_value=second_response): assert_get_response_body_is('second_response') # Now the first cassette should be back in effect assert_get_response_body_is('first_response')
def test_function_decorated_with_use_cassette_can_be_invoked_multiple_times( *args): decorated_function = Cassette.use(path="test")(make_get_request) for i in range(4): decorated_function()
def test_path_transformer_None(): with Cassette.use(path="a", path_transformer=None) as cassette: assert cassette._path == "a"
def test_path_transformer_with_context_manager(): with Cassette.use(path="b", path_transformer=lambda *args: "a") as cassette: assert cassette._path == "a"
def test_function_decorated_with_use_cassette_can_be_invoked_multiple_times(*args): decorated_function = Cassette.use(path='test')(make_get_request) for i in range(4): decorated_function()
def test_path_transformer_with_context_manager(): with Cassette.use( path='b', path_transformer=lambda *args: 'a' ) as cassette: assert cassette._path == 'a'
def test_path_transformer_with_context_manager(): with Cassette.use(path='b', path_transformer=lambda *args: 'a') as cassette: assert cassette._path == 'a'
def test_path_transformer_None(): with Cassette.use( path='a', path_transformer=None, ) as cassette: assert cassette._path == 'a'