Created
December 13, 2017 06:49
-
-
Save wohali/1cd19b78c0a417dbeb9f66b3229f7b58 to your computer and use it in GitHub Desktop.
repro support script for apache/couchdb#745
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
Puts random docs in localhost:5984/foo. | |
Usage: | |
makeit.py <number_of_docs> [--size=<size>] | |
makeit.py -h | --help | |
makeit.py --version | |
Options: | |
-h --help Show this screen. | |
--version Show version. | |
--size=<size> Attachment size in bytes [default: 50000000]. | |
""" | |
import random_words | |
import RandomIO | |
import requests | |
from docopt import docopt | |
from schema import Or, Use, Schema | |
URL="http://admin:password@localhost:5984/foo" | |
def make_doc(): | |
rw = random_words.RandomWords() | |
re = random_words.RandomEmails() | |
ri = random_words.LoremIpsum() | |
doc = {} | |
doc['name'] = ' '.join(rw.random_words(count=2)) | |
doc['email'] = re.randomMail() | |
doc['string1'] = ri.get_sentence() | |
doc['string2'] = ri.get_sentences(3) | |
#doc['string3'] = ri.get_sentences(10) | |
doc['_id'] = doc['email'] | |
return doc | |
def put_doc(attsize=50000000): | |
rw = random_words.RandomWords() | |
doc = make_doc() | |
rnd = RandomIO.RandomIO(' '.join(rw.random_words(count=5))) | |
# PUT doc to /dbname | |
res = requests.post(URL, json=doc) | |
res.raise_for_status() | |
payload = {'rev': res.json()['rev']} | |
# PUT bytes to /dbname/doc/att1 | |
res = requests.put( | |
URL + '/' + doc['_id'] + '/att1', | |
data=rnd.read(attsize), | |
params=payload | |
) | |
print (res.json()) | |
if __name__ == '__main__': | |
Int = Or(None, Use(int)) | |
sch = Schema({ | |
'--size': Int, | |
'<number_of_docs>': Int, | |
'--help': bool, | |
'--version': bool | |
}) | |
args = sch.validate(docopt(__doc__, version='1.0.0')) | |
for ctr in range(0, args['<number_of_docs>']): | |
put_doc(attsize=args['--size']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment