Skip to content

Commit

Permalink
@leplatrem review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jul 13, 2015
1 parent 03197ff commit 7c04646
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 102 deletions.
11 changes: 5 additions & 6 deletions loadtests/loadtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self, *args, **kwargs):
self.random_user = uuid.uuid4().hex
self.auth = HTTPBasicAuth(self.random_user, 'secret')

self.session.auth = self.auth
self.session.headers.update({'Content-Type': 'application/json'})

# Keep track of created objects.
self._collections_created = {}

Expand Down Expand Up @@ -73,14 +76,10 @@ def collection_url(self, bucket=None, collection=None, prefix=True):
if collection not in self._collections_created:
self.session.put(bucket_url,
data=json.dumps({'data': {}}),
auth=self.auth,
headers={'If-None-Match': '*',
'Content-Type': 'application/json'})
headers={'If-None-Match': '*'})
self.session.put(collection_url,
data=json.dumps({'data': {}}),
auth=self.auth,
headers={'If-None-Match': '*',
'Content-Type': 'application/json'})
headers={'If-None-Match': '*'})
self._collections_created[collection] = True

return collection_url + '/records'
Expand Down
25 changes: 11 additions & 14 deletions loadtests/loadtest/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def setUp(self):
This method is called as many times as number of hits.
"""
resp = self.session.get(self.collection_url(), auth=self.auth)
resp = self.session.get(self.collection_url())
records = resp.json()['data']

# Create some records, if not any in collection.
if len(records) < self.nb_initial_records:
for i in range(self.nb_initial_records):
self.create()
resp = self.session.get(self.collection_url(), auth=self.auth)
resp = self.session.get(self.collection_url())
records = resp.json()['data']

# Pick a random record
Expand Down Expand Up @@ -104,7 +104,6 @@ def create(self):
resp = self.session.post(
self.collection_url(),
data=json.dumps({'data': article}),
auth=self.auth,
headers={'Content-Type': 'application/json'})
self.incr_counter(resp.status_code)
self.assertEqual(resp.status_code, 201)
Expand Down Expand Up @@ -133,21 +132,19 @@ def filter_sort(self):
queryparams = random.choice(queries)
query_url = '&'.join(['='.join(param) for param in queryparams])
url = self.collection_url() + '?' + query_url
resp = self.session.get(url, auth=self.auth)
resp = self.session.get(url)
self.incr_counter(resp.status_code)
self.assertEqual(resp.status_code, 200)

def _patch(self, url, data, status=200):
data = json.dumps(data)
resp = self.session.patch(url, data, auth=self.auth)
resp = self.session.patch(url, data)
self.incr_counter(resp.status_code)
self.assertEqual(resp.status_code, status)

def _run_batch(self, data):
resp = self.session.post(self.api_url('batch'),
data=json.dumps(data),
auth=self.auth,
headers={'Content-Type': 'application/json'})
data=json.dumps(data))
self.incr_counter('status-%s' % resp.status_code)
self.assertEqual(resp.status_code, 200)
for subresponse in resp.json()['responses']:
Expand All @@ -163,14 +160,14 @@ def update(self):
self._patch(self.random_url, data)

def delete(self):
resp = self.session.delete(self.random_url, auth=self.auth)
resp = self.session.delete(self.random_url)
self.incr_counter(resp.status_code)
self.assertEqual(resp.status_code, 200)

def batch_delete(self):
# Get some random articles on which the batch will be applied
url = self.collection_url() + '?_limit=5&_sort=title'
resp = self.session.get(url, auth=self.auth)
resp = self.session.get(url)
articles = resp.json()['data']
urls = [self.record_url(a['id'], prefix=False)
for a in articles]
Expand All @@ -190,12 +187,12 @@ def poll_changes(self):
last_modified = self.random_record['last_modified']
filters = '?_since=%s' % last_modified
modified_url = self.collection_url() + filters
resp = self.session.get(modified_url, auth=self.auth)
resp = self.session.get(modified_url)
self.assertEqual(resp.status_code, 200)

def list_archived(self):
archived_url = self.collection_url() + '?archived=true'
resp = self.session.get(archived_url, auth=self.auth)
resp = self.session.get(archived_url)
self.assertEqual(resp.status_code, 200)

def batch_count(self):
Expand All @@ -218,7 +215,7 @@ def list_deleted(self):
modif = self.random_record['last_modified']
filters = '?_since=%s&deleted=true' % modif
deleted_url = self.collection_url() + filters
resp = self.session.get(deleted_url, auth=self.auth)
resp = self.session.get(deleted_url)
self.assertEqual(resp.status_code, 200)

def list_continuated_pagination(self):
Expand All @@ -227,7 +224,7 @@ def list_continuated_pagination(self):
urls = []

while paginated_url:
resp = self.session.get(paginated_url, auth=self.auth)
resp = self.session.get(paginated_url)
self.assertEqual(resp.status_code, 200)
next_page = resp.headers.get("Next-Page")
if next_page is not None and next_page not in urls:
Expand Down

0 comments on commit 7c04646

Please sign in to comment.