Example #1
0
def test_BaseAPI_init_credential_provider_raises_error():
    """Test initializing the credentials when the provider raises an error."""
    creds = Credentials({
        'url': 'https://example.com',
        'token': 'ABCDEFGHIJKLM',
        'org_key': 'A1B2C3D4'
    })
    mock_provider = MockCredentialProvider({'my_section': creds})
    with pytest.raises(CredentialError):
        BaseAPI(integration_name='test4',
                credential_provider=mock_provider,
                profile='notexist')
def test_BaseAPI_init_external_credential_provider():
    """Test initializing the credentials from an externally-supplied provider."""
    creds = Credentials({'url': 'https://example.com', 'token': 'ABCDEFGHIJKLM', 'org_key': 'A1B2C3D4'})
    mock_provider = MockCredentialProvider({'my_section': creds})
    sut = BaseAPI(integration_name='test3', credential_provider=mock_provider, profile='my_section')
    assert sut.credentials is creds
    assert sut.credentials.url == 'https://example.com'
    assert sut.credentials.token == 'ABCDEFGHIJKLM'
    assert sut.credentials.org_key == 'A1B2C3D4'
    assert sut.credential_profile_name == 'my_section'
    assert sut.credential_provider is mock_provider
    assert sut.session.server == 'https://example.com'
    assert sut.session.token == 'ABCDEFGHIJKLM'
    assert sut.session.token_header['User-Agent'].startswith('test3')
def test_BaseAPI_init_with_only_profile_specified(mox):
    """Test the case where we only supply a profile string to the BaseAPI."""
    mox.StubOutWithMock(default_provider_object, 'get_default_provider')
    creds = Credentials({'url': 'https://example.com', 'token': 'ABCDEFGHIJKLM', 'org_key': 'A1B2C3D4'})
    mock_provider = MockCredentialProvider({'Valid': creds})
    default_provider_object.get_default_provider(None).AndReturn(mock_provider)
    mox.ReplayAll()
    sut = BaseAPI(profile='Valid')
    assert sut.credentials is creds
    assert sut.credentials.url == 'https://example.com'
    assert sut.credentials.token == 'ABCDEFGHIJKLM'
    assert sut.credentials.org_key == 'A1B2C3D4'
    assert sut.credential_profile_name == 'Valid'
    assert sut.session.server == 'https://example.com'
    assert sut.session.token == 'ABCDEFGHIJKLM'
    mox.VerifyAll()