Skip to content

Contributing to the tests

Laurent Mazuel edited this page Jan 27, 2016 · 23 revisions

Overview

This page is to help you writing tests for Azure Python SDK when these tests implies Azure HTTP requests. Our framework rests upon on a HTTP recording system (vcr.py). We will find here:

  • How to authenticate to Azure, in order to be able to record/play HTTP requests
  • How to write tests using our Python utilities classes

Authenticate

You have several ways to authenticate to Azure. To be able to use the tests framework, you must use an authentication which gives you a token:

  • OAuth authentication using Azure Active Directory user/password
  • OAuth authentication using Active Directory application and service principal

Certificate authentication does not allow you to record HTTP queries for testing.

For ARM tests, you can use any of the two authentication system. For ASM legacy tests, you have to authenticate using AAD user/password

Get a token with Azure Directory user/password

  1. Connect to the Azure Classic Portal with your admin account

  2. Create a user in your default AAD https://azure.microsoft.com/en-us/documentation/articles/active-directory-create-users/

    You must NOT activate Multi-Factor Authentication

  3. Go to Settings - Administrators

  4. Click on Add and enter the email of the new user. Check the checkbox of the subscription you want to test with this user.

  5. Login to Azure Portal with this new user to change the temporary password to a new one. You will not be able to use the temporary password for OAuth login.

You are now able to log in Python using OAuth. You can test with this code using adal:

import adal
adal.acquire_token_with_username_password(
    'https://login.microsoftonline.com/common/', # Do not change
    'user@domain.com',                           # Your new user
    'my_smart_password',                         # Your password
)

Get a token with Active Directory application and service principal

Follow this detailed link: https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/

You are now able to log in Python using OAuth. You can test with this code using adal:

import adal
adal.acquire_token_with_client_credentials(
    'https://login.microsoftonline.com/ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL/', # Your OAuth 2.0 Token Endpoint for this app
    'ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL',                                    # Your client id
    'generatedkey',                                                            # Your authentication key
)

Using the Azure Python SDK framework

In progress...

Clone this wiki locally