File: test_aws_cognito_authenticator.py

package info (click to toggle)
python-nice-go 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 608 kB
  • sloc: python: 1,981; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from unittest.mock import patch

from nice_go._aws_cognito_authenticator import AwsCognitoAuthenticator


async def test_refresh_token(mock_authenticator: AwsCognitoAuthenticator) -> None:
    with patch("nice_go._aws_cognito_authenticator.boto3.client") as mock_boto3_client:
        mock_boto3_client.return_value.initiate_auth.return_value = {
            "AuthenticationResult": {"IdToken": "test_token"},
        }
        result = mock_authenticator.refresh_token("refresh_token")

        assert result.id_token == "test_token"


async def test_get_new_token(mock_authenticator: AwsCognitoAuthenticator) -> None:
    with patch(
        "nice_go._aws_cognito_authenticator.boto3.client",
    ) as mock_boto3_client, patch(
        "nice_go._aws_cognito_authenticator.AWSSRP",
    ) as mock_awssrp:
        mock_boto3_client.return_value.initiate_auth.return_value = {
            "ChallengeParameters": {"key": "value"},
        }
        mock_boto3_client.return_value.respond_to_auth_challenge.return_value = {
            "AuthenticationResult": {"IdToken": "test_token"},
        }
        mock_awssrp.return_value.get_auth_params.return_value = {"key": "value"}
        mock_awssrp.return_value.process_challenge.return_value = {"key": "value"}
        result = mock_authenticator.get_new_token("username", "password")

        assert result.id_token == "test_token"
        assert result.refresh_token is None