summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorThais Siqueira <thais.siqueira@gmail.com>2016-03-11 14:46:06 -0300
committerThais Siqueira <thais.siqueira@gmail.com>2016-03-11 14:46:06 -0300
commit918ae543d94ea2c359c8608807fc251ac16ef1cc (patch)
treedf73afd4dec82155ebc000cf93dced8be3a812ea /service
parent0313e643e30cfe202a100a0b69e7ff3c3875fff5 (diff)
Fixes pep8 errors and update requests to 2.9.1.
Issue #213
Diffstat (limited to 'service')
-rw-r--r--service/requirements.txt2
-rw-r--r--service/test/load/locustfile.py63
2 files changed, 50 insertions, 15 deletions
diff --git a/service/requirements.txt b/service/requirements.txt
index 7c9ee87c..b74b7f94 100644
--- a/service/requirements.txt
+++ b/service/requirements.txt
@@ -4,7 +4,7 @@ https://launchpad.net/dirspec/stable-13-10/13.10/+download/dirspec-13.10.tar.gz
--allow-external dirspec --allow-unverified dirspec
https://launchpad.net/u1db/stable-13-10/13.10/+download/u1db-13.10.tar.bz2
pyasn1==0.1.8
-requests==2.4.1
+requests==2.9.1
srp==1.0.4
whoosh==2.5.7
pycryptopp
diff --git a/service/test/load/locustfile.py b/service/test/load/locustfile.py
index 23142eee..138f13db 100644
--- a/service/test/load/locustfile.py
+++ b/service/test/load/locustfile.py
@@ -8,8 +8,12 @@ from locust import HttpLocust, TaskSet, task
from pixelated.resources.login_resource import LoginResource
LEAP_PROVIDER = os.environ.get('LEAP_PROVIDER', 'dev.pixelated-project.org')
-LEAP_SERVER_HOST = os.environ.get('LEAP_SERVER_HOST', 'https://api.%s:4430' % LEAP_PROVIDER)
-LEAP_VERIFY_CERTIFICATE = os.environ.get('LEAP_VERIFY_CERTIFICATE', '~/.leap/ca.crt')
+LEAP_SERVER_HOST = os.environ.get(
+ 'LEAP_SERVER_HOST',
+ 'https://api.%s:4430' % LEAP_PROVIDER)
+LEAP_VERIFY_CERTIFICATE = os.environ.get(
+ 'LEAP_VERIFY_CERTIFICATE',
+ '~/.leap/ca.crt')
MAX_NUMBER_USER = os.environ.get('MAX_NUMBER_USER', 100)
INVITES_FILENAME = os.environ.get('INVITES_FILENAME', '/tmp/invite_codes.txt')
INVITES_ENABLED = os.environ.get('INVITES_ENABLED', 'true') == 'true'
@@ -23,27 +27,33 @@ def load_invite_from_number(number):
class UserBehavior(TaskSet):
def __init__(self, *args, **kwargs):
- super(UserBehavior, self).__init__(*args, **kwargs)
- self.cookies = {}
+ super(UserBehavior, self).__init__(*args, **kwargs)
+ self.cookies = {}
def on_start(self):
- """ on_start is called when a Locust start before any task is scheduled """
self.login()
def _get_or_create_user(self, number):
- srp_auth = SRPAuth(LEAP_SERVER_HOST, os.path.expanduser(LEAP_VERIFY_CERTIFICATE))
+ srp_auth = SRPAuth(
+ LEAP_SERVER_HOST,
+ os.path.expanduser(LEAP_VERIFY_CERTIFICATE))
username, password = ('loadtest%d' % number), ('password_%d' % number)
try:
srp_auth.authenticate(username, password)
except SRPAuthenticationError:
- invite_code = load_invite_from_number(number) if INVITES_ENABLED else None
+ invite_code = None
+ if INVITES_ENABLED:
+ invite_code = load_invite_from_number(number)
+
srp_auth.register(username, password, invite_code)
return username, password
def login(self):
number = randint(1, int(MAX_NUMBER_USER))
username, password = self._get_or_create_user(number)
- response = self.client.post("/%s" % LoginResource.BASE_URL, {"username": username, "password": password})
+ response = self.client.post(
+ "/%s" % LoginResource.BASE_URL,
+ {"username": username, "password": password})
self.cookies.update(response.cookies.get_dict())
resp = self.client.get("/")
self.cookies.update(resp.cookies.get_dict())
@@ -59,21 +69,46 @@ class UserBehavior(TaskSet):
@task(3)
def send_mail(self):
- payload = {"tags": ["drafts"], "body": "some text lorem ipsum", "attachments": [], "ident": "",
- "header": {"to": ["%s@%s" % (self.username, LEAP_PROVIDER)], "cc": [], "bcc": [], "subject": "load testing"}}
- self.cookies.update(self.client.get("/").cookies.get_dict())
+ payload = {
+ "tags": ["drafts"],
+ "body": "some text lorem ipsum",
+ "attachments": [],
+ "ident": "",
+ "header": {
+ "to": ["%s@%s" % (self.username, LEAP_PROVIDER)],
+ "cc": [],
+ "bcc": [],
+ "subject": "load testing"}}
+
+ self.cookies.update(
+ self.client.get("/").cookies.get_dict())
print(self.cookies)
- with self.client.post('/mails', json=payload, catch_response=True, cookies=self.cookies, headers={'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN':self.cookies['XSRF-TOKEN']}) as email_response:
+ with self.client.post(
+ '/mails',
+ json=payload,
+ catch_response=True,
+ cookies=self.cookies,
+ headers={
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-XSRF-TOKEN': self.cookies['XSRF-TOKEN']}) as email_response:
if email_response.status_code == 201:
email_id = json.loads(email_response.content)['ident']
print email_id
self.delete_mail(email_id)
else:
- email_response.failure('Error: email not Sent, status code: %s' % email_response.status_code)
+ email_response.failure(
+ 'Error: email not Sent, status code: %s' % (
+ email_response.status_code))
def delete_mail(self, ident):
payload = {"idents": [ident]}
- self.client.post('/mails/delete', json=payload, cookies=self.cookies, headers={'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN':self.cookies['XSRF-TOKEN']})
+ self.client.post(
+ '/mails/delete',
+ json=payload,
+ cookies=self.cookies,
+ headers={
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-XSRF-TOKEN': self.cookies['XSRF-TOKEN']})
class WebsiteUser(HttpLocust):