Updating tests results format according to spec
Spec: https://github.com/stackforge/refstack/blob/master/specs/approved/api-v1.md Update patch: https://review.openstack.org/#/c/146680/ Change-Id: I75c62090a45d742b88acdfe080e24d62658976ce
This commit is contained in:
parent
38e6276737
commit
9403991171
@ -168,8 +168,11 @@ class RefstackClient:
|
||||
self.logger.debug('API request content: %s ' % content)
|
||||
try:
|
||||
url = '%s/v1/results/' % self.args.url
|
||||
headers = {'Content-type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data={'data': json.dumps(content)})
|
||||
response = requests.post(url,
|
||||
data=json.dumps(content),
|
||||
headers=headers)
|
||||
self.logger.info(url + " Response: " + str(response.text))
|
||||
except Exception as e:
|
||||
self.logger.critical('Failed to post %s - %s ' % (url, e))
|
||||
|
@ -35,7 +35,9 @@ class TempestSubunitTestResultPassOnly(testtools.TestResult):
|
||||
"""Overwrite super class method for additional data processing."""
|
||||
super(TempestSubunitTestResultPassOnly, self).addSuccess(testcase)
|
||||
# Remove any [] and () from the test ID before appending it.
|
||||
self.results.append(re.sub('[\(\[].*[\]\)]', '', testcase.id()))
|
||||
self.results.append(
|
||||
{'name': re.sub('[\(\[].*[\]\)]', '', testcase.id())}
|
||||
)
|
||||
|
||||
def get_results(self):
|
||||
return self.results
|
||||
|
@ -2,7 +2,7 @@
|
||||
"duration_seconds": 0,
|
||||
"cpid": "test-id",
|
||||
"results": [
|
||||
"tempest.passed.test"
|
||||
{"name": "tempest.passed.test"}
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,12 @@ import os
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
import httmock
|
||||
import mock
|
||||
from mock import MagicMock
|
||||
import unittest
|
||||
|
||||
|
||||
import refstack_client.refstack_client as rc
|
||||
|
||||
|
||||
@ -55,7 +57,7 @@ class TestRefstackClient(unittest.TestCase):
|
||||
argv = ['test',
|
||||
'-c', conf_file_name,
|
||||
'--test-cases', 'tempest.api.compute',
|
||||
'--url', '0.0.0.0']
|
||||
'--url', 'http://127.0.0.1']
|
||||
if verbose:
|
||||
argv.append(verbose)
|
||||
return argv
|
||||
@ -216,7 +218,7 @@ class TestRefstackClient(unittest.TestCase):
|
||||
client = rc.RefstackClient(args)
|
||||
subunit_file = self.test_path + "/.testrepository/0"
|
||||
results = client.get_passed_tests(subunit_file)
|
||||
expected = ['tempest.passed.test']
|
||||
expected = [{'name': 'tempest.passed.test'}]
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_run_tempest(self):
|
||||
@ -232,20 +234,29 @@ class TestRefstackClient(unittest.TestCase):
|
||||
return_value=MagicMock(returncode=0))
|
||||
self.patch("os.path.isfile", return_value=True)
|
||||
self.mock_keystone()
|
||||
client.get_passed_tests = MagicMock(return_value=['test'])
|
||||
client.post_results = MagicMock()
|
||||
client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}])
|
||||
client.logger.info = MagicMock()
|
||||
client._save_json_results = MagicMock()
|
||||
client.test()
|
||||
|
||||
expected_content = json.dumps({'test_id': 42})
|
||||
|
||||
@httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v1/results/')
|
||||
def refstack_api_mock(url, request):
|
||||
return expected_content
|
||||
|
||||
with httmock.HTTMock(refstack_api_mock):
|
||||
client.test()
|
||||
|
||||
mock_popen.assert_called_with(
|
||||
('%s/run_tempest.sh' % self.test_path, '-C', self.conf_file_name,
|
||||
'-V', '-t', '--', 'tempest.api.compute'),
|
||||
stderr=None
|
||||
)
|
||||
|
||||
expected_content = {'duration_seconds': mock.ANY,
|
||||
'cpid': 'test-id',
|
||||
'results': ['test']}
|
||||
client.post_results.assert_called_with('0.0.0.0', expected_content)
|
||||
client.logger.info.assert_called_with(
|
||||
'http://127.0.0.1/v1/results/ Response: '
|
||||
'%s' % expected_content
|
||||
)
|
||||
|
||||
def test_run_tempest_offline(self):
|
||||
"""
|
||||
@ -319,7 +330,7 @@ class TestRefstackClient(unittest.TestCase):
|
||||
client.upload()
|
||||
expected_json = {'duration_seconds': 0,
|
||||
'cpid': 'test-id',
|
||||
'results': ['tempest.passed.test']}
|
||||
'results': [{'name': 'tempest.passed.test'}]}
|
||||
|
||||
client.post_results.assert_called_with('http://api.test.org',
|
||||
expected_json)
|
||||
|
@ -7,3 +7,4 @@ testrepository>=0.0.18
|
||||
testtools>=0.9.34
|
||||
mock
|
||||
coverage
|
||||
httmock
|
Loading…
Reference in New Issue
Block a user