|  | 
|  | 1 | +from faker import Faker | 
|  | 2 | +from office365.graph.directory.userProfile import UserProfile | 
|  | 3 | +from office365.graph.graph_client import GraphClient | 
|  | 4 | +from settings import settings | 
|  | 5 | +from tests import random_seed | 
|  | 6 | + | 
|  | 7 | + | 
|  | 8 | +def acquire_token(auth_ctx): | 
|  | 9 | +    """ | 
|  | 10 | +
 | 
|  | 11 | +    :type auth_ctx: adal.AuthenticationContext | 
|  | 12 | +    """ | 
|  | 13 | +    token = auth_ctx.acquire_token_with_username_password( | 
|  | 14 | +        'https://graph.microsoft.com', | 
|  | 15 | +        settings['user_credentials']['username'], | 
|  | 16 | +        settings['user_credentials']['password'], | 
|  | 17 | +        settings['client_credentials']['client_id']) | 
|  | 18 | +    return token | 
|  | 19 | + | 
|  | 20 | + | 
|  | 21 | +def generate_user_profile(): | 
|  | 22 | +    fake = Faker() | 
|  | 23 | + | 
|  | 24 | +    user_json = { | 
|  | 25 | +        'givenName': fake.name(), | 
|  | 26 | +        'companyName': fake.company(), | 
|  | 27 | +        'businessPhones': [fake.phone_number()], | 
|  | 28 | +        'officeLocation': fake.street_address(), | 
|  | 29 | +        'city': fake.city(), | 
|  | 30 | +        'country': fake.country(), | 
|  | 31 | +        'principalName': "{0}@{1}".format(fake.user_name(), settings['tenant']), | 
|  | 32 | +        'password': "P@ssw0rd{0}".format(random_seed), | 
|  | 33 | +        'accountEnabled': True | 
|  | 34 | +    } | 
|  | 35 | +    return UserProfile(**user_json) | 
|  | 36 | + | 
|  | 37 | + | 
|  | 38 | +client = GraphClient(settings['tenant'], acquire_token) | 
|  | 39 | + | 
|  | 40 | +for idx in range(0, 5): | 
|  | 41 | +    user_profile = generate_user_profile() | 
|  | 42 | +    user = client.users.add(user_profile) | 
|  | 43 | +    client.execute_query() | 
|  | 44 | +    print("{0} user has been created".format(user.properties['userPrincipalName'])) | 
0 commit comments