Skip to content

Instantly share code, notes, and snippets.

@bittercoder
Created August 31, 2012 01:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bittercoder/3547325 to your computer and use it in GitHub Desktop.
Save bittercoder/3547325 to your computer and use it in GitHub Desktop.
Using Python requests library to generate 15,000 ET users
#!/usr/bin/env python
# Generate 15,000 users in Enterprise Tester with admin permissions...
import json
import requests
from requests.auth import HTTPBasicAuth
server = 'http://localhost:8080/EnterpriseTester'
proxyDict = { 'http': '127.0.0.1:8888'} # so we can capture requests in fiddler
auth = HTTPBasicAuth('Administrator', 'password')
headers = { 'content-type': 'application/json' }
all_perms = [{'Key': '/Administration'}, {'Key': '/Resources'},{'Key': '/Reports'}, {'Key':'/Project'},{'Key':'/TestManagement'}]
def get_rel(rel, json):
for link in json['Links']:
if link['Rel'] == rel: return link['Href']
return None
def create_user(username):
model = { 'UserName': username, 'Email': 'noreply@unknown.org', 'Password': 'password'}
users_collection_url = server + '/api/users'
create_user_resp = requests.post(users_collection_url, auth=auth, data = json.dumps(model), proxies=proxyDict, headers=headers)
perms_url = get_rel('GlobalPermissions', create_user_resp.json)
requests.put(perms_url, auth=auth, data=json.dumps(all_perms), proxies=proxyDict, headers=headers)
for i in range(0,15000):
suffix = str(i).rjust(5,'0')
username = "user_" + suffix
create_user(username)
@joshrobb
Copy link

love me some python.

@mausch
Copy link

mausch commented Aug 31, 2012

If we had some similarly scriptish HTTP and JSON libraries in .NET, Boo or F# could probably achieve the same conciseness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment