Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #18 from jeads/https-protocol

Https protocol
  • Loading branch information...
commit 55b5db74ee20aeb2ccd9a2c44684730e809ab622 2 parents 40f1cca + 0804654
@malini malini authored
View
2  README.md
@@ -13,6 +13,7 @@ Usage
res.add_test_results("suite_name", "another_test", [2, 3, 4])
req = DatazillaRequest(
+ protocol="https",
host="datazilla.mozilla.org",
project="project",
oauth_key="oauth-key",
@@ -37,6 +38,7 @@ If you don't want to use `DatazillaResult` to build up the data structure to
send, you can still use `DatazillaRequest` to send it:
req = DatazillaRequest(
+ protocol="https",
host="datazilla.mozilla.org",
project="project",
oauth_key="oauth-key",
View
24 dzclient/client.py
@@ -145,7 +145,8 @@ class DatazillaRequest(DatazillaResultsCollection):
"""
@classmethod
- def create(cls, host, project, oauth_key, oauth_secret, collection):
+ def create(cls, protocol, host, project, oauth_key,
+ oauth_secret, collection):
"""create a DatazillaRequest instance from a results collection"""
# get attributes from the collection
@@ -154,14 +155,14 @@ def create(cls, host, project, oauth_key, oauth_secret, collection):
for i in attributes])
# create the instance
- instance = cls(host, project, oauth_key, oauth_secret, **kw)
+ instance = cls(protocol, host, project, oauth_key, oauth_secret, **kw)
# add the results
instance.add_datazilla_result(collection.results)
return instance
- def __init__(self, host, project, oauth_key, oauth_secret, **kw):
+ def __init__(self, protocol, host, project, oauth_key, oauth_secret, **kw):
"""
- host : datazilla host to post to
- project : name of the project in datazilla: http://host/project
@@ -173,6 +174,15 @@ def __init__(self, host, project, oauth_key, oauth_secret, **kw):
self.project = project
self.oauth_key = oauth_key
self.oauth_secret = oauth_secret
+
+ self.protocols = set(['http', 'https'])
+
+ if protocol in self.protocols:
+ self.protocol = protocol
+ else:
+ #Default to https
+ self.protocol = 'https'
+
DatazillaResultsCollection.__init__(self, **kw)
@@ -188,7 +198,7 @@ def submit(self):
def send(self, dataset):
"""Send given dataset to server; returns httplib Response."""
path = "/%s/api/load_test" % (self.project)
- uri = "http://%s%s" % (self.host, path)
+ uri = "%s://%s%s" % (self.protocol, self.host, path)
user = self.project
params = {
@@ -218,7 +228,11 @@ def send(self, dataset):
#Build the header
header = {'Content-type': 'application/x-www-form-urlencoded'}
- conn = httplib.HTTPConnection(self.host)
+ conn = None
+ if self.protocol == 'http':
+ conn = httplib.HTTPConnection(self.host)
+ else:
+ conn = httplib.HTTPSConnection(self.host)
conn.request("POST", path, req.to_postdata(), header)
return conn.getresponse()
View
19 dzclient/tests/test_datazilla_request.py
@@ -7,14 +7,16 @@ class DatazillaRequestTest(unittest.TestCase):
def test_init_with_date(self):
"""Can provide test date on instantiation."""
req = DatazillaRequest(
- 'host', 'project', 'key', 'secret', test_date=12345)
+ 'protocol', 'host', 'project', 'key', 'secret', test_date=12345)
self.assertEqual(req.test_date, 12345)
def test_add_datazilla_result(self):
"""Can add a DatazillaResult to a DatazillaRequest."""
- req = DatazillaRequest('host', 'project', 'key', 'secret')
+ req = DatazillaRequest(
+ 'protocol', 'host', 'project', 'key', 'secret'
+ )
res = DatazillaResult({'suite': {'test': [1, 2, 3]}})
req.add_datazilla_result(res)
@@ -24,7 +26,9 @@ def test_add_datazilla_result(self):
def test_add_second_datazilla_result(self):
"""Adding a second DatazillaResult joins their results."""
- req = DatazillaRequest('host', 'project', 'key', 'secret')
+ req = DatazillaRequest(
+ 'protocol', 'host', 'project', 'key', 'secret'
+ )
res1 = DatazillaResult({'suite1': {'test': [1]}})
res2 = DatazillaResult({'suite2': {'test': [2]}})
@@ -40,7 +44,9 @@ def test_create_from_results_collection(self):
collection = DatazillaResultsCollection(machine_name='localhost',
os='linux')
test_date = collection.test_date
- req = DatazillaRequest.create('host', 'project', 'key', 'secret', collection)
+ req = DatazillaRequest.create(
+ 'protocol', 'host', 'project', 'key', 'secret', collection
+ )
self.assertEqual(req.machine_name, 'localhost')
self.assertEqual(req.os, 'linux')
self.assertEqual(req.test_date, test_date)
@@ -53,6 +59,7 @@ def test_datasets(self):
"""Tests dataset creation for submission to datazilla"""
req = DatazillaRequest(
+ protocol='http',
host='host',
project='project',
oauth_key='key',
@@ -97,6 +104,7 @@ def test_datasets(self):
def test_submit(self, mock_send):
"""Submits blob of JSON data for each test suite."""
req = DatazillaRequest(
+ protocol='http',
host='host',
project='project',
oauth_key='key',
@@ -169,11 +177,12 @@ def test_send(self,
mock_time.return_value = 1342229050
mock_generate_nonce.return_value = "46810593"
+ protocol = 'http'
host = "datazilla.mozilla.org"
project = "project"
key = "oauth-key"
secret = "oauth-secret"
- req = DatazillaRequest(host, project, key, secret)
+ req = DatazillaRequest(protocol, host, project, key, secret)
mock_conn = mock_HTTPConnection.return_value
mock_request = mock_conn.request
Please sign in to comment.
Something went wrong with that request. Please try again.