Skip to content

Instantly share code, notes, and snippets.

@Altai-man
Created May 13, 2015 13:31
Show Gist options
  • Save Altai-man/8c7b5cc623849a47fb8b to your computer and use it in GitHub Desktop.
Save Altai-man/8c7b5cc623849a47fb8b to your computer and use it in GitHub Desktop.
Simple tester.
import random
import string
import requests
import json
def main():
host = "http://127.0.0.1:8000/api/v1"
api_key = "value_here"
filename = "filename_here"
number_of = 1000
for i in range(number_of):
rand = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
data = {
"text": "test_" + rand,
"user_id": 1,
"board_id": 1
}
data = json.dumps(data)
r = requests.post(host+'/posts/', data=data,
headers={"content-type": "application/json",
"authorization": api_key})
pid = json.loads(r.content.decode('utf-8'))['payload']['post_id']
files = {'image': open(filename, 'rb')}
r = requests.post(host+'/upload/',
data={"post_id": pid},
files=files,
headers={"authorization": api_key})
print(r.content)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment