def unmock_and_reset(): def init(**kwargs): default_kwargs = {"refresh_token": get_token(), "logger": get_logger()} default_kwargs.update(kwargs) return unmock.init(**default_kwargs) yield init unmock.reset()
def fetchSpotifyArtist(): opts = unmock.init(ignore=["headers", "story"]) # opts.save = True # For saving mocked response to local response = requests.get( "https://api.spotify.com/v1/artists") # will be mocked unmock.reset() return response
def test_unmock_off(): unmock.reset() res = requests.get("http://www.i-forgot-to-set-my-env-variable.com/") assert res.status_code == 200 # Got valid response from target URL after shutting down unmock.
def test_unmock_whitelist(): unmock.init(whitelist="www.example.com") res = requests.get("https://www.example.com") # Unmatched, so it is redirected with pytest.raises(Exception): assert res.json() unmock.reset()
def test_unmock_status(): unmock.init() assert unmock.is_mocking() unmock.reset() assert not unmock.is_mocking()
def test_init_and_reset(): unmock.init() assert_number_of_patches( 5) # Four different mocks for HTTPRequest plus one for HTTPResponse unmock.reset() assert_number_of_patches(0)