|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
from google.auth import api_key |
|
|
|
|
|
def test_credentials_constructor(): |
|
with pytest.raises(ValueError) as excinfo: |
|
api_key.Credentials("") |
|
|
|
assert excinfo.match(r"Token must be a non-empty API key string") |
|
|
|
|
|
def test_expired_and_valid(): |
|
credentials = api_key.Credentials("api-key") |
|
|
|
assert credentials.valid |
|
assert credentials.token == "api-key" |
|
assert not credentials.expired |
|
|
|
credentials.refresh(None) |
|
assert credentials.valid |
|
assert credentials.token == "api-key" |
|
assert not credentials.expired |
|
|
|
|
|
def test_before_request(): |
|
credentials = api_key.Credentials("api-key") |
|
headers = {} |
|
|
|
credentials.before_request(None, "http://example.com", "GET", headers) |
|
assert headers["x-goog-api-key"] == "api-key" |
|
|