コード例 #1
0
def test_token_refresh(requests_mock):
    """Test token is refreshed after expiry"""

    requests_mock.post(
        TOKEN_URL,
        text=get_mock_auth_text(expiry=1),
    )
    requests_mock.get(
        "http://localhost:8000/v2/backpack/assertions", text='{"result": []}'
    )

    client = BadgrClient(
        username="******",
        password="******",
        client_id="kewl_client",
        scope="rw:profile rw:issuer rw:backpack",
    )

    # Wait for token to expire
    time.sleep(1)

    requests_mock.post(
        TOKEN_URL, text=get_mock_auth_text(token="refreshed_token")
    )
    # Call api to rigger refresh
    client.fetch_assertion()

    assert client.header == {"Authorization": "Bearer refreshed_token"}
コード例 #2
0
def client(requests_mock):
    requests_mock.post(TOKEN_URL, text=get_mock_auth_text())

    client = BadgrClient(
        username="******",
        password="******",
        client_id="kewl_client",
        scope="rw:profile rw:issuer rw:backpack",
    )

    return client
コード例 #3
0
ファイル: api_test.py プロジェクト: nasirhm/badgrclient
def test_client_credentials(mocker):
    """Test username password"""

    mocker.patch("badgrclient.BadgrClient._get_auth_token")
    BadgrClient(
        username=TEST_USER,
        password=TEST_PASSWORD,
        client_id="kewl_client",
        scope="rw:profile rw:issuer rw:backpack",
    )
    BadgrClient._get_auth_token.assert_called_once_with(
        TEST_USER, TEST_PASSWORD)
コード例 #4
0
ファイル: api_test.py プロジェクト: nasirhm/badgrclient
def unique_badge_client(requests_mock):
    requests_mock.post(TOKEN_URL, text=get_mock_auth_text())

    client = BadgrClient(
        username=TEST_USER,
        password=TEST_PASSWORD,
        client_id="kewl_client",
        scope="rw:profile rw:issuer rw:backpack",
        unique_badge_names=True,
    )

    return client