def test_storage_credentials():
    creds = azops.StorageCredentials(mock.MagicMock())

    with pytest.raises(ValueError):
        creds.add_storage_account('sa1', '', 'endpoint')

    creds.add_storage_account('sa1', 'somekey1', 'endpoint')

    a = creds.get_storage_account('sa1')
    assert a.name == 'sa1'
    assert a.key == 'somekey1'
    assert a.endpoint == 'endpoint'
    assert isinstance(a.append_blob_client,
                      azure.storage.blob.AppendBlobService)
    assert isinstance(a.block_blob_client, azure.storage.blob.BlockBlobService)
    assert isinstance(a.file_client, azure.storage.file.FileService)
    assert isinstance(a.page_blob_client, azure.storage.blob.PageBlobService)

    with pytest.raises(KeyError):
        a = creds.get_storage_account('sa2')

    with pytest.raises(ValueError):
        creds.add_storage_account('sa1', 'somekeyxx', 'endpoint')

    creds.add_storage_account('sa2', 'somekey2', 'endpoint2')
    a = creds.get_storage_account('sa1')
    b = creds.get_storage_account('sa2')
    assert a.name == 'sa1'
    assert a.key == 'somekey1'
    assert a.endpoint == 'endpoint'
    assert b.name == 'sa2'
    assert b.key == 'somekey2'
    assert b.endpoint == 'endpoint2'
示例#2
0
def test_storage_credentials():
    go = mock.MagicMock()
    go.timeout.max_retries = None

    creds = azops.StorageCredentials(go)

    with pytest.raises(ValueError):
        creds.add_storage_account('sa1', '', 'core.windows.net')

    with pytest.raises(ValueError):
        creds.add_storage_account(
            'sa1', 'somekey1', 'https://blob.core.windows.net')

    creds.add_storage_account('sa1', 'somekey1', 'core.windows.net')

    a = creds.get_storage_account('sa1')
    assert a.name == 'sa1'
    assert a.key == 'somekey1'
    assert a.endpoint == 'core.windows.net'
    assert isinstance(
        a.append_blob_client, azure.storage.blob.AppendBlobService)
    assert isinstance(
        a.block_blob_client, azure.storage.blob.BlockBlobService)
    assert isinstance(
        a.file_client, azure.storage.file.FileService)
    assert isinstance(
        a.page_blob_client, azure.storage.blob.PageBlobService)

    with pytest.raises(KeyError):
        a = creds.get_storage_account('sa2')

    with pytest.raises(ValueError):
        creds.add_storage_account('sa1', 'somekeyxx', 'core.windows.net')

    creds.add_storage_account('sa2', 'somekey2', 'core.cloudapi.de')
    a = creds.get_storage_account('sa1')
    b = creds.get_storage_account('sa2')
    assert a.name == 'sa1'
    assert a.key == 'somekey1'
    assert a.endpoint == 'core.windows.net'
    assert b.name == 'sa2'
    assert b.key == 'somekey2'
    assert b.endpoint == 'core.cloudapi.de'