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

test_result: introduce TestResult_getTestSuiteData

Extract the logic to "parse" test suite revisions and git repositories
in a reusable script.
At the same time, fix a minor bug that when we had both validated and
invalidated test suite, the invalidated one was selected.
parent 7f8561cf
"Jump to gitlab or gitweb web interface to view commit"
portal = context.getPortalObject()
test_suite_list = portal.portal_catalog(
portal_type='Test Suite',
validation_state=('validated', 'invalidated'),
title={'query': context.getTitle(), 'key': 'ExactMatch'})
if not test_suite_list:
return []
test_suite = sorted(
[test_suite.getObject() for test_suite in test_suite_list],
key=lambda test_suite: test_suite.getValidationState() == 'validated')[0]
# TODO: make this jump test suite
# decode the reference ( ${buildout_section_id}=${number of commits}-${hash},${buildout_section_id}=${number of commits}-${hash}, ... )
repository_dict = {}
for repository_string in context.getReference().split(','):
repository_code, revision = repository_string.split('-')
repository_dict[repository_code.split('=')[0]] = revision
from Products.PythonScripts.standard import Object
test_suite_data = context.TestResult_getTestSuiteData()
result_list = []
from Products.PythonScripts.standard import Object
def makeVCSLink(repository_url, revision):
# https://user:pass@lab.nexedi.cn/user/repo.git -> https://user:pass@lab.nexedi.cn/user/repo/commit/hash
if 'lab.nexedi.cn' in repository_url and repository_url.endswith('.git'):
if 'lab.nexedi' in repository_url and repository_url.endswith('.git'):
repository_url = repository_url[:-len('.git')]
if '@' in repository_url: # remove credentials
scheme = repository_url.split(':')[0]
......@@ -49,11 +29,11 @@ def makeVCSLink(repository_url, revision):
repository=repository_url,
revision=revision)
for repository in test_suite.contentValues(portal_type='Test Suite Repository'):
for repository in test_suite_data['repository_dict'].values():
result_list.append(
makeVCSLink(
repository.getProperty('git_url'),
repository_dict[repository.getProperty('buildout_section_id')]))
repository['repository_url'],
repository['revision']))
if len(result_list) == 1:
from zExceptions import Redirect
......
"""Returns info about a test result, a mapping containing:
test_suite_relative_url: relative url of test suite
repository_dict: for each test suite repository, keyed by buildout section id:
revision: commit sha
repository_url: git url of the repository
commits_count: number of commits
returns None if test suite cannot be found.
"""
portal = context.getPortalObject()
test_suite_list = portal.portal_catalog(
portal_type='Test Suite',
validation_state=('validated', 'invalidated'),
title={'query': context.getTitle(), 'key': 'ExactMatch'})
if not test_suite_list:
return None
test_suite = sorted(
[test_suite.getObject() for test_suite in test_suite_list],
key=lambda test_suite: test_suite.getValidationState() == 'validated')[-1]
# decode the reference ( ${buildout_section_id}=${number of commits}-${hash},${buildout_section_id}=${number of commits}-${hash} )
repository_dict = {}
if context.getReference() and '-' in context.getReference(): # tolerate invalid references, especially for tests
for repository_string in context.getReference().split(','):
buildout_section_id_and_commits_count, revision = repository_string.split('-')
buildout_section_id, commits_count = buildout_section_id_and_commits_count.split('=')
repository_dict[buildout_section_id] = {
'revision': revision,
'commits_count': int(commits_count),
}
# add information about test suite repositories
for test_result_repository in test_suite.contentValues(portal_type='Test Suite Repository'):
repository_data = repository_dict.setdefault(test_result_repository.getBuildoutSectionId(), {})
repository_data['repository_url'] = test_result_repository.getGitUrl()
if REQUEST:
REQUEST.RESPONSE.setHeader('content-type', 'application/json; charset=utf-8')
return {
'test_suite_relative_url': test_suite.getRelativeUrl(),
'repository_dict': repository_dict,
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TestResult_getTestSuiteData</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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