Commit c3f38db1 authored by Jérome Perrin's avatar Jérome Perrin

test_result: support templated URL for test results

The previous way of using portal.ERP5Site_absoluteUrl() +
test_result.getRelativeUrl() could not work with ERP5JS URLs.

To be compatible with this and also maybe erp5_web-style URLs if we want
to link to public tests results, we should have more flexibility in how
we generate URLs.

Introduce a "test result url template" property on gitlab connector, see
unit test for a renderjs ui compatible usage.

/reviewed-on !963
parent 49e78bec
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Template of URL for the test results, using python\'s str.format.\n
\n
The following keys are available:\n
* portal_url url of the portal, as returned by portal.ERP5Site_getAbsoluteUrl()\n
* test_result_relative_url relative url of the test result, as returned by test_result.getRelativeUrl()\n
* test_result_reference reference of the test result, as returned by test_result.getReference()\n
* test_result_id id of the test result, as returned by test_result.getId()</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test_result_url_template_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>string:{portal_url}/{test_result_relative_url}</string> </value>
</item>
<item>
<key> <string>read_permission</string> </key>
<value> <string>Access contents information</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -76,6 +76,7 @@
<list>
<string>my_reference</string>
<string>my_url_string</string>
<string>my_test_result_url_template</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_test_result_url_template</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Test Result URL Template</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -2,17 +2,25 @@
"""
portal = context.getPortalObject()
portal_absolute_url = portal.ERP5Site_getAbsoluteUrl()
portal_url = portal.ERP5Site_getAbsoluteUrl()
test_result_relative_url = context.getRelativeUrl()
test_result_relative_id = context.getId()
test_result_reference = context.getReference()
test_suite_data = context.TestResult_getTestSuiteData()
if test_suite_data:
for repository_info in test_suite_data['repository_dict'].values():
connector_url = repository_info['connector_relative_url']
if connector_url:
portal.restrictedTraverse(connector_url).postCommitStatus(
connector = portal.restrictedTraverse(connector_url)
connector.postCommitStatus(
repository_info['repository_url'],
repository_info['revision'],
state,
'%s/%s' % ( portal_absolute_url, context.getRelativeUrl() ),
connector.getTestResultUrlTemplate().format(
portal_url=portal_url,
test_result_relative_url=test_result_relative_url,
test_result_relative_id=test_result_relative_id,
test_result_reference=test_result_reference),
context.getTitle()
)
......@@ -1619,3 +1619,24 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
self.test_result.start()
self.tic()
def test_test_result_url(self):
# We can define on the gitlab connector the pattern of URLs to use.
# This is useful for example to integrate with ERP5JS or erp5_web URLs
# that are not simply the relative URL.
self.connector.setTestResultUrlTemplate(
'https://erp5js.example.com/#{test_result_relative_url}')
def _callback(request):
body = json.loads(request.body)
self.assertEqual(
'https://erp5js.example.com/#%s' % self.test_result.getRelativeUrl(),
body['target_url'])
return (httplib.CREATED, {'content-type': 'application/json'}, '{}')
with responses.RequestsMock() as rsps:
rsps.add_callback(
responses.POST,
self.post_commit_status_url,
_callback)
self.test_result.start()
self.tic()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment