зеркало из https://github.com/mozilla/treeherder.git
made changes
This commit is contained in:
Родитель
5fad6b8b4b
Коммит
35be73269c
|
@ -20,4 +20,4 @@ oauth2==1.5.211
|
|||
httplib2==0.7.4
|
||||
|
||||
git+git://github.com/jeads/datasource@143ac08d11
|
||||
git+git://github.com/mozilla/treeherder-client@7c71e756cf
|
||||
git+git://github.com/mozilla/treeherder-client@abe6a85180
|
||||
|
|
|
@ -5,7 +5,6 @@ import sys
|
|||
from django.core.management import call_command
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--runslow",
|
||||
|
@ -101,7 +100,6 @@ def initial_data():
|
|||
|
||||
call_command('load_initial_data')
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def jm():
|
||||
""" Give a test access to a JobsModel instance. """
|
||||
|
|
|
@ -1,14 +1,38 @@
|
|||
import pytest
|
||||
from webtest.app import TestApp
|
||||
from treeherder.etl.mixins import JsonLoaderMixin
|
||||
from treeherder.etl.mixins import JsonLoaderMixin, OAuthLoaderMixin
|
||||
from treeherder.webapp.wsgi import application
|
||||
from treeherder.etl import common
|
||||
|
||||
from tests.sampledata import SampleData
|
||||
|
||||
@pytest.fixture
|
||||
def mock_post_json_data(monkeypatch):
|
||||
"""mock the urllib call replacing it with a webtest call"""
|
||||
def _post_json_data(adapter, url, data):
|
||||
response = TestApp(application).post_json(url, params=data)
|
||||
|
||||
tjc = TreeherderJobCollection()
|
||||
tj = tjc.get_job(data)
|
||||
tjc.add(tj)
|
||||
|
||||
OAuthLoaderMixin.set_credentials( SampleData.get_credentials() )
|
||||
credentials = OAuthLoaderMixin.get_credentials('test_treeherder')
|
||||
|
||||
|
||||
tr = TreeherderRequest(
|
||||
protocol='http',
|
||||
host='localhost',
|
||||
project=jm.project,
|
||||
oauth_key=credentials['consumer_key'],
|
||||
oauth_secret=credentials['consumer_secret']
|
||||
)
|
||||
signed_uri = tr.get_signed_uri(tjc.to_json(), tr.get_uri(tjc))
|
||||
|
||||
#response = TestApp(application).post_json(url, params=data)
|
||||
response = TestApp(application).post_json(
|
||||
str(signed_uri), params=tjc.get_collection_data()
|
||||
)
|
||||
|
||||
response.getcode = lambda: response.status_int
|
||||
return response
|
||||
|
||||
|
|
|
@ -5,6 +5,18 @@ from django.conf import settings
|
|||
|
||||
class SampleData(object):
|
||||
|
||||
@classmethod
|
||||
def get_credentials(cls):
|
||||
|
||||
credentials = {
|
||||
'test_treeherder': {
|
||||
'consumer_key':'8de17836-4a9b-45f5-824c-5ada76713334',
|
||||
'consumer_secret':'0f71d011-d773-4831-9f1c-17b237207467'
|
||||
}
|
||||
}
|
||||
|
||||
return credentials
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.job_data_file = "{0}/sample_data/job_data.txt".format(
|
||||
|
@ -61,3 +73,4 @@ class SampleData(object):
|
|||
def get_log_path(self, name):
|
||||
"""Returns the full path to a log file"""
|
||||
return "{0}/{1}".format(self.logs_dir, name)
|
||||
|
||||
|
|
|
@ -556,10 +556,14 @@ class Builds4hAnalyzer(JsonExtractorMixin, Builds4hTransformerMixin):
|
|||
# found in the analysis file
|
||||
with open(self.builds4h_analysis_file_path) as f:
|
||||
data = f.read()
|
||||
|
||||
deserialized_data = {}
|
||||
if data:
|
||||
deserialized_data = json.loads(data)
|
||||
|
||||
self.report_obj['guids'] = deserialized_data.get('guids', {})
|
||||
|
||||
if 'analyzers' in deserialized_data:
|
||||
for analysis_type in deserialized_data['analyzers']:
|
||||
self.report_obj['analyzers'][analysis_type]['data'] = \
|
||||
deserialized_data['analyzers'][analysis_type]
|
||||
|
@ -569,7 +573,11 @@ class Builds4hAnalyzer(JsonExtractorMixin, Builds4hTransformerMixin):
|
|||
if os.path.isfile(self.builds4h_blacklist_file_path):
|
||||
with open(self.builds4h_blacklist_file_path) as f:
|
||||
data = f.read()
|
||||
|
||||
deserialized_data = []
|
||||
if data:
|
||||
deserialized_data = json.loads(data)
|
||||
|
||||
self.blacklist = set(deserialized_data)
|
||||
|
||||
def write_report(self):
|
||||
|
|
|
@ -134,10 +134,12 @@ class OAuthLoaderMixin(object):
|
|||
return parameters
|
||||
|
||||
@classmethod
|
||||
def set_credentials(cls):
|
||||
def set_credentials(cls, credentials={}):
|
||||
# Only get the credentials once
|
||||
if not cls.credentials:
|
||||
if not cls.credentials and not credentials:
|
||||
cls.credentials = TreeherderModelBase.get_oauth_credentials()
|
||||
else:
|
||||
cls.credentials = credentials
|
||||
|
||||
@classmethod
|
||||
def get_credentials(cls, project):
|
||||
|
|
|
@ -75,7 +75,6 @@ def oauth_required(func):
|
|||
)
|
||||
|
||||
server = oauth.Server()
|
||||
|
||||
token = oauth.Token(key='', secret='')
|
||||
|
||||
#Get the consumer object
|
||||
|
|
|
@ -580,16 +580,31 @@ class TreeherderRequest(object):
|
|||
|
||||
collection_inst.validate()
|
||||
|
||||
uri = self.get_uri(collection_inst)
|
||||
|
||||
# Build the header
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
use_oauth = bool(self.oauth_key and self.oauth_secret)
|
||||
|
||||
body = collection_inst.get_collection_data()
|
||||
serialized_body = collection_inst.to_json()
|
||||
|
||||
uri = self.get_uri(collection_inst)
|
||||
|
||||
if use_oauth:
|
||||
uri = self.get_signed_uri(serialized_body, uri)
|
||||
|
||||
# Make the POST request
|
||||
conn = None
|
||||
if self.protocol == 'http':
|
||||
conn = httplib.HTTPConnection(self.host)
|
||||
else:
|
||||
conn = httplib.HTTPSConnection(self.host)
|
||||
|
||||
conn.request('POST', uri, serialized_body, headers)
|
||||
|
||||
return conn.getresponse()
|
||||
|
||||
def get_signed_uri(self, serialized_body, uri):
|
||||
|
||||
# There is no requirement for the token in two-legged
|
||||
# OAuth but we still need the token object.
|
||||
|
@ -606,7 +621,7 @@ class TreeherderRequest(object):
|
|||
try:
|
||||
req = oauth.Request(
|
||||
method='POST',
|
||||
body=json.dumps(body),
|
||||
body=serialized_body,
|
||||
url=uri,
|
||||
parameters=parameters
|
||||
)
|
||||
|
@ -618,18 +633,7 @@ class TreeherderRequest(object):
|
|||
signature_method = oauth.SignatureMethod_HMAC_SHA1()
|
||||
req.sign_request(signature_method, consumer, token)
|
||||
|
||||
uri = req.to_url()
|
||||
|
||||
# Make the POST request
|
||||
conn = None
|
||||
if self.protocol == 'http':
|
||||
conn = httplib.HTTPConnection(self.host)
|
||||
else:
|
||||
conn = httplib.HTTPSConnection(self.host)
|
||||
|
||||
conn.request('POST', uri, json.dumps(body), headers)
|
||||
|
||||
return conn.getresponse()
|
||||
return req.to_url()
|
||||
|
||||
def get_uri(self, collection_inst):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче