Return url with test results
Refstack API returns url on html page with test results in response on test results post and list. Change-Id: I038d067553fa742452497029a614f1296d8b9cab
This commit is contained in:
parent
369f7ce4ad
commit
1f04771ff4
|
@ -126,6 +126,9 @@
|
|||
# (boolean value)
|
||||
#app_dev_mode = false
|
||||
|
||||
# Template for test result url. (string value)
|
||||
#test_results_url = http://refstack.net/output.html?test_id=%s
|
||||
|
||||
# Number of results for one page (integer value)
|
||||
#results_per_page = 20
|
||||
|
||||
|
|
|
@ -64,6 +64,10 @@ API_OPTS = [
|
|||
'by pecan application. Also, server responses will '
|
||||
'contain some details with debug information.'
|
||||
),
|
||||
cfg.StrOpt('test_results_url',
|
||||
default='http://refstack.net/output.html?test_id=%s',
|
||||
help='Template for test result url.'
|
||||
),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
|
|
@ -123,7 +123,8 @@ class ResultsController(BaseRestControllerWithValidation):
|
|||
pecan.request.headers.get('X-Public-Key')
|
||||
test_id = db.store_results(item)
|
||||
LOG.debug(item)
|
||||
return {'test_id': test_id}
|
||||
return {'test_id': test_id,
|
||||
'url': CONF.api.test_results_url % test_id}
|
||||
|
||||
@pecan.expose('json')
|
||||
def get(self):
|
||||
|
@ -164,7 +165,8 @@ class ResultsController(BaseRestControllerWithValidation):
|
|||
results.append({
|
||||
'test_id': r.id,
|
||||
'created_at': r.created_at,
|
||||
'cpid': r.cpid
|
||||
'cpid': r.cpid,
|
||||
'url': CONF.api.test_results_url % r.id
|
||||
})
|
||||
|
||||
page = {'results': results,
|
||||
|
|
|
@ -43,6 +43,10 @@ class ResultsControllerTestCase(base.BaseTestCase):
|
|||
self.controller = v1.ResultsController()
|
||||
self.config_fixture = config_fixture.Config()
|
||||
self.CONF = self.useFixture(self.config_fixture).conf
|
||||
self.test_results_url = 'host?%s'
|
||||
self.CONF.set_override('test_results_url',
|
||||
self.test_results_url,
|
||||
'api')
|
||||
|
||||
@mock.patch('refstack.db.get_test')
|
||||
@mock.patch('refstack.db.get_test_results')
|
||||
|
@ -78,7 +82,9 @@ class ResultsControllerTestCase(base.BaseTestCase):
|
|||
mock_request.headers = {}
|
||||
mock_store_results.return_value = 'fake_test_id'
|
||||
result = self.controller.post()
|
||||
self.assertEqual(result, {'test_id': 'fake_test_id'})
|
||||
self.assertEqual(result,
|
||||
{'test_id': 'fake_test_id',
|
||||
'url': self.test_results_url % 'fake_test_id'})
|
||||
self.assertEqual(mock_response.status, 201)
|
||||
mock_store_results.assert_called_once_with({'answer': 42})
|
||||
|
||||
|
@ -95,7 +101,9 @@ class ResultsControllerTestCase(base.BaseTestCase):
|
|||
}
|
||||
mock_store_results.return_value = 'fake_test_id'
|
||||
result = self.controller.post()
|
||||
self.assertEqual(result, {'test_id': 'fake_test_id'})
|
||||
self.assertEqual(result,
|
||||
{'test_id': 'fake_test_id',
|
||||
'url': self.test_results_url % 'fake_test_id'})
|
||||
self.assertEqual(mock_response.status, 201)
|
||||
mock_store_results.assert_called_once_with(
|
||||
{'answer': 42, 'metadata': {'public_key': 'fake-key'}}
|
||||
|
@ -201,7 +209,8 @@ class ResultsControllerTestCase(base.BaseTestCase):
|
|||
'results': [{
|
||||
'test_id': record.id,
|
||||
'created_at': record.created_at,
|
||||
'cpid': record.cpid
|
||||
'cpid': record.cpid,
|
||||
'url': self.test_results_url % record.id
|
||||
}],
|
||||
'pagination': {
|
||||
'current_page': page_number,
|
||||
|
|
Loading…
Reference in New Issue