Ejemplo n.º 1
0
def test_token_refresh():
    update_called = []

    # hacky way to test side effect
    def token_updater(token):
        update_called.append(1)

    client = OuraClient(client_id="test_id",
                        access_token="token",
                        refresh_callback=token_updater)
    adapter.register_uri(
        requests_mock.POST,
        requests_mock.ANY,
        status_code=401,
        text=json.dumps({
            "access_token": "fake_return_access_token",
            "refresh_token": "fake_return_refresh_token",
        }),
    )
    adapter.register_uri(
        requests_mock.GET,
        requests_mock.ANY,
        status_code=401,
        text=json.dumps({"a": "b"}),
    )

    client._auth_handler._session.mount(client.API_ENDPOINT, adapter)
    try:
        client.user_info()
    except Exception:
        pass
    assert len(update_called) == 1
Ejemplo n.º 2
0
def test_token_refresh():
    update_called = []

    # hacky way to test side effect
    def token_updater(token):
        update_called.append(1)

    client = OuraClient('test_id',
                        access_token='token',
                        refresh_callback=token_updater)
    adapter.register_uri(requests_mock.POST,
                         requests_mock.ANY,
                         status_code=401,
                         text=json.dumps({
                             'access_token':
                             'fake_return_access_token',
                             'refresh_token':
                             'fake_return_refresh_token'
                         }))
    adapter.register_uri(requests_mock.GET,
                         requests_mock.ANY,
                         status_code=401,
                         text=json.dumps({'a': 'b'}))

    client._session.mount(client.API_ENDPOINT, adapter)
    try:
        resp = client.user_info()
    except:
        pass
    assert len(update_called) == 1
Ejemplo n.º 3
0
def get_self():
    pat = os.getenv("OURA_PAT")
    client = OuraClient(personal_access_token=pat)
    user_info = client.user_info()
    print(user_info)