def test_access_token_update(correct_config, fake_private_file, monkeypatch,
                             successful_token_response):
    jwt_client = JWT(correct_config, fake_private_file.name, 'test_company')
    mock_session = Mock()
    jwt_client.refresh_token = Mock()
    jwt_client.authenticate(mock_session)
    mock_session.headers.update.assert_called_once()
    jwt_client.refresh_token.assert_called_once()
def test_config_check(correct_config):
    wrong_config = {
        "CLIENT_SECRET": "testtesttest",
        "ORG_ID": "testtesttest",
        "PUBLIC_KEYS_WITH_EXPIRY": {
            "testtesttest": "07/21/2030"
        },
        "TECHNICAL_ACCOUNT_EMAIL": "*****@*****.**"
    }
    config_1 = JWT.create_config(correct_config)
    assert JWT.check_config(config_1) is True
    config_2 = JWT.create_config(wrong_config)
    with pytest.raises(ConfigInsufficientInformationError):
        JWT.check_config(config_2)
def test_jwt_client_init_from_path(correct_config, fake_private_file):
    jwt_client = JWT(correct_config, fake_private_file.name, 'test_company')
    assert list(jwt_client.config.keys()) == \
           'client_secret org_id api_key technical_account_id ' \
           'technical_account_email company_id'.split(' ')
    with open(fake_private_file.name, "r") as fd:
        data = fd.read()
    assert jwt_client.key == data
def test_access_token(correct_config, fake_private_file, monkeypatch,
                      successful_token_response):
    jwt_client = JWT(correct_config, fake_private_file.name, 'test_company')
    monkeypatch.setattr(requests, "post", successful_token_response)
    access_token = jwt_client.token_response
    assert access_token == {
        'access_token': 'test_token',
        'expires_in': 86399994,
        'token_type': 'bearer'
    }
def test_access_token_fail(correct_config, fake_private_file, monkeypatch,
                           unsuccessful_token_response):
    jwt_client = JWT(correct_config, fake_private_file.name, 'test_company')
    monkeypatch.setattr(requests, "post", unsuccessful_token_response)
    with pytest.raises(AuthenticationError):
        access_token = jwt_client.token_response
def test_get_jwt(correct_config, fake_private_file):
    jwt_client = JWT(correct_config, fake_private_file.name, 'test_company')
    jwt = jwt_client.jwt
    assert jwt is not None
    assert isinstance(jwt, bytes)
def test_jwt_client_init_file_not_found(correct_config):
    with pytest.raises(FileNotFoundError):
        jwt_client = JWT(correct_config, "testtesttest", 'test_company')