Skip to content
Browse files

Merge pull request #14 from k0s/13

separate results collection from posting
  • Loading branch information...
2 parents de84ef1 + b5d99d1 commit 7bfc0051d57bdb4573f923957940020c4c5dfd2d @malini malini committed Aug 1, 2012
Showing with 65 additions and 16 deletions.
  1. +1 −1 dzclient/__init__.py
  2. +50 −14 dzclient/client.py
  3. +14 −1 dzclient/tests/test_datazilla_request.py
View
2 dzclient/__init__.py
@@ -2,4 +2,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-from .client import DatazillaResult, DatazillaRequest
+from .client import DatazillaResult, DatazillaResultsCollection, DatazillaRequest
View
64 dzclient/client.py
@@ -2,11 +2,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-from copy import deepcopy
+import inspect
import httplib
import oauth2 as oauth
import time
import urllib
+from copy import deepcopy
from urlparse import urlparse
try:
@@ -41,22 +42,16 @@ def join_results(self, results):
for test_name, values in tests.items():
suite.setdefault(test_name, []).extend(values)
+class DatazillaResultsCollection(object):
+ """DatazillaResultsCollection manages test information and serialization to JSON"""
-class DatazillaRequest(object):
- """
- Datazilla request object that manages test information and submission.
-
- Note that the revision id can be 16 characters, maximum.
-
- """
- def __init__(self, host, project, oauth_key, oauth_secret,
- machine_name="", os="", os_version="", platform="",
+ def __init__(self, machine_name="", os="", os_version="", platform="",
build_name="", version="", revision="", branch="", id="",
test_date=None):
- self.host = host
- self.project = project
- self.oauth_key = oauth_key
- self.oauth_secret = oauth_secret
+ """
+ - id : the build ID for which the dzresults are for; a unique identifier to which these results belong
+ """
+
self.machine_name = machine_name
self.os = os
self.os_version = os_version
@@ -106,6 +101,47 @@ def datasets(self):
return datasets
+
+class DatazillaRequest(DatazillaResultsCollection):
+ """
+ Datazilla request object that manages test submission.
+
+ Note that the revision id can be 16 characters, maximum.
+
+ """
+
+ @classmethod
+ def create(cls, host, project, oauth_key, oauth_secret, collection):
+ """create a DatazillaRequest instance from a results collection"""
+
+ # get attributes from the collection
+ attributes = inspect.getargspec(DatazillaResultsCollection.__init__).args[1:]
+ kw = dict([(i, getattr(collection, i))
+ for i in attributes])
+
+ # create the instance
+ instance = cls(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):
+ """
+ - host : datazilla host to post to
+ - project : name of the project in datazilla: http://host/project
+ - oauth_key, oauth_secret : oauth credentials
+ - **kw : arguments to DatazillaResultsCollection.__init__
+ """
+
+ self.host = host
+ self.project = project
+ self.oauth_key = oauth_key
+ self.oauth_secret = oauth_secret
+ DatazillaResultsCollection.__init__(self, **kw)
+
+
def submit(self):
"""Submit test data to datazilla server, return list of responses."""
View
15 dzclient/tests/test_datazilla_request.py
@@ -1,6 +1,6 @@
import unittest
from mock import patch
-from dzclient import DatazillaRequest, DatazillaResult
+from dzclient import DatazillaRequest, DatazillaResult, DatazillaResultsCollection
class DatazillaRequestTest(unittest.TestCase):
@@ -36,6 +36,19 @@ def test_add_second_datazilla_result(self):
{'suite1': {'test': [1]}, 'suite2': {'test': [2]}},
)
+ 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)
+ self.assertEqual(req.machine_name, 'localhost')
+ self.assertEqual(req.os, 'linux')
+ self.assertEqual(req.test_date, test_date)
+ self.assertEqual(req.host, 'host')
+ self.assertEqual(req.project, 'project')
+ self.assertEqual(req.oauth_key, 'key')
+ self.assertEqual(req.oauth_secret, 'secret')
+
def test_datasets(self):
"""Tests dataset creation for submission to datazilla"""

0 comments on commit 7bfc005

Please sign in to comment.
Something went wrong with that request. Please try again.