Skip to content

Instantly share code, notes, and snippets.

@AhmedHelalAhmed
Forked from Loupeznik/api_test.py
Created March 15, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedHelalAhmed/59a3f7d6866e9fd99e8145f5850b1d5e to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/59a3f7d6866e9fd99e8145f5850b1d5e to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import requests
url = "http://127.0.0.1:8000/api/test"
payload={}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer xxxxx' #add your API token
}
ok = 0
failed = 0
access_level = 1
for i in range(80):
response = requests.request("GET", url, headers=headers, data=payload)
if response.status_code == 200:
print ('Attempt ' + str(i + 1) + ': OK')
ok += 1
else:
print ('Attempt ' + str(i + 1) + ': FAILED (' + str(response.status_code) + ')')
failed += 1
#print(response.text)
print ('Tested for AccessLevel = ' + str(access_level) + ' user')
print ('OK: ' + str(ok))
print ('FAILED: ' + str(failed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment