def test_restores_original_value(self): original_value = doubles.testing.User patch_class('doubles.testing.User') teardown() assert original_value == doubles.testing.User
def test_using_the_patched_class(self): allow_constructor(patch_class('doubles.testing.User')).and_return('result_1') allow_constructor(patch_class('doubles.testing.OldStyleUser')).and_return('result_2') result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance() assert result_1 == 'result_1' assert result_2 == 'result_2'
def test_using_the_patched_class(self): allow_constructor( patch_class('doubles.testing.User')).and_return('result_1') allow_constructor( patch_class('doubles.testing.OldStyleUser')).and_return('result_2') result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance( ) assert result_1 == 'result_1' assert result_2 == 'result_2'
def gen_mock_service(): class_name = 'bootcamp.handlers.add_user.UserService' mock_service = UserService() service_class = patch_class(class_name) allow_constructor(service_class).and_return(mock_service) return mock_service
def gen_mock_service(): class_name = 'bootcamp.handlers.title.TitleService' mock_service = TitleService() service_class = patch_class(class_name) allow_constructor(service_class).and_return(mock_service) return mock_service
def test_class_double_after_patching(self): patch_class('doubles.testing.User') assert ClassDouble('doubles.testing.User')
def test_non_existent_class(self): with pytest.raises(VerifyingDoubleImportError): patch_class('doubles.testing.NotReal')
def test_raises_an_error_trying_to_patch_a_function(self): with pytest.raises(VerifyingDoubleImportError): patch_class('doubles.test.top_level_function')