## testing.StaticTokenCredential


A credential that returns a fixed token and records what it was asked for.


Usage

``` python
testing.StaticTokenCredential(
    token="fake-token",
    *,
    expires_in=3600,
)
```


Implements azure-core's `TokenCredential` and `SupportsTokenInfo` protocols without signing in or touching the network, so an [ApiClient](ApiClient.md#dazapiz.ApiClient) (or any Azure SDK client) can be tested offline. Each call returns a fresh token that expires `expires_in` seconds from now.


## Parameters


`token: str = ``"fake-token"`  
The access token to hand out; default `"fake-token"`, so requests carry `Authorization: Bearer fake-token`.

`expires_in: int = ``3600`  
Seconds until each returned token expires; default 3600.


## Attributes


`calls: list of tuple of str`  
The scopes of each [get_token()](RefreshTokenCredential.md#dazapiz.RefreshTokenCredential.get_token) or [get_token_info()](testing.StaticTokenCredential.md#dazapiz.testing.StaticTokenCredential.get_token_info) call, in order, one tuple per call.


## Notes

It wraps nothing: it is a plain object satisfying azure-core's `azure.core.credentials.TokenCredential` and `SupportsTokenInfo` protocols. `claims`, `tenant_id` and the `options` of [get_token_info()](testing.StaticTokenCredential.md#dazapiz.testing.StaticTokenCredential.get_token_info) are accepted and ignored. The token is redacted in `repr` (design §6), although it is only a test value.


## Examples

``` python
from dazapiz.testing import StaticTokenCredential

credential = StaticTokenCredential()
client = MyApiClient(credential=credential)  # requests send "Bearer fake-token"
...
assert credential.calls == [(MyApiClient.scope,)]
```


## Methods

| Name | Description |
|----|----|
| [get_token()](#get_token) | Return the fixed token for `scopes`, and record them. |
| [get_token_info()](#get_token_info) | Return the fixed token for `scopes` as `AccessTokenInfo`, and record them. |
| [close()](#close) | Do nothing: there is nothing to release. |

------------------------------------------------------------------------


#### get_token()


Return the fixed token for `scopes`, and record them.


Usage

``` python
get_token(*scopes, claims=None, tenant_id=None, enable_cae=False, **kwargs)
```


##### Parameters


`*scopes: str`  
The scopes asked for, recorded in `calls`.

`claims: str or None = None`  
Ignored.

`tenant_id: str or None = None`  
Ignored.

`enable_cae: bool = ``False`  
Ignored.

`**kwargs: Any`  
Ignored.


##### Returns


`azure.core.credentials.AccessToken`  
The token, expiring `expires_in` seconds from now.


------------------------------------------------------------------------


#### get_token_info()


Return the fixed token for `scopes` as `AccessTokenInfo`, and record them.


Usage

``` python
get_token_info(*scopes, options=None)
```


##### Parameters


`*scopes: str`  
The scopes asked for, recorded in `calls`.

`options: TokenRequestOptions or None = None`  
Ignored.


##### Returns


`azure.core.credentials.AccessTokenInfo`  
The token, of type `Bearer`, expiring `expires_in` seconds from now.


------------------------------------------------------------------------


#### close()


Do nothing: there is nothing to release.


Usage

``` python
close()
```
