コード例 #1
0
ファイル: conftest.py プロジェクト: sandeepk17/unmock-python
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()
コード例 #2
0
ファイル: app.py プロジェクト: Like-an-Angel/circleci_python
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
コード例 #3
0
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.
コード例 #4
0
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()
コード例 #5
0
def test_unmock_status():
    unmock.init()
    assert unmock.is_mocking()
    unmock.reset()
    assert not unmock.is_mocking()
コード例 #6
0
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)