Commit 0024e8ac authored by Jérome Perrin's avatar Jérome Perrin

fixes for TestResult_getTestSuiteData

While deploying nexedi/erp5!924 we found out that this script was not working in these cases:

 * when buildout section id contains `-repository` there's a convention that this is stripped and does not appear in test result reference ( implemented [here](https://lab.nexedi.com/nexedi/erp5/blob/31804f683fd36322fb38aeb9654bee70cebe4fdb/erp5/util/testnode/NodeTestSuite.py#L95) )
 * when buildout section id contains `-` this script crash
 * when there's no buildout section id and there's no fix for that, because buildout section id is a required property. If we encounter this failure, we fix the data by putting a buildout section id on test suite repository.

/reviewed-on nexedi/erp5!961
parents 954f86cc f20d2689
......@@ -27,8 +27,8 @@ test_suite = sorted(
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('=')
buildout_section_id, commits_count_and_revision = repository_string.split('=')
commits_count, revision = commits_count_and_revision.split('-')
repository_dict[buildout_section_id] = {
'revision': revision,
'commits_count': int(commits_count),
......@@ -36,7 +36,10 @@ if context.getReference() and '-' in context.getReference(): # tolerate invalid
# 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(), {})
buildout_section_id = test_result_repository.getBuildoutSectionId()
# NodeTestSuite.revision strip trailing -repository
buildout_section_id = buildout_section_id[:-11] if buildout_section_id.endswith('-repository') else buildout_section_id
repository_data = repository_dict.setdefault(buildout_section_id, {})
repository_data['repository_url'] = test_result_repository.getGitUrl()
repository_data['connector_relative_url'] = test_result_repository.getDestination()
......
......@@ -1421,7 +1421,7 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
"""Tests for Gitlab commits annotations.
"""
def afterSetUp(self):
connector = self.portal.portal_web_services.newContent(
self.connector = connector = self.portal.portal_web_services.newContent(
portal_type='Gitlab REST Connector',
reference='lab.example.com',
url_string='https://lab.example.com/api/v4/',
......@@ -1439,6 +1439,7 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
source_project_value=self.project,
)
self.test_suite.newContent(
id='test_repo',
portal_type='Test Suite Repository',
branch='master',
git_url='https://lab.example.com/nexedi/test.git',
......@@ -1448,6 +1449,7 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
# another unrelated repository, without connector, this
# should not cause any API call.
self.test_suite.newContent(
id='erp5_repo',
portal_type='Test Suite Repository',
branch='master',
git_url='https://lab.nexedi.com/nexedi/erp5.git',
......@@ -1544,3 +1546,47 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
self._response_callback('failed'))
self.test_result.stop()
self.tic()
def test_TestResult_getTestSuiteData(self):
"""test for TestResult_getTestSuiteData helper script
"""
self.assertEqual({
"repository_dict": {
"erp5": {
"commits_count": 1,
"connector_relative_url": None,
"repository_url": "https://lab.nexedi.com/nexedi/erp5.git",
"revision": "dc7b6e2e85e9434a97694a698884b057b7d30286",
},
"test": {
"commits_count": 10,
"connector_relative_url": self.connector.getRelativeUrl(),
"repository_url": "https://lab.example.com/nexedi/test.git",
"revision": "cc4c79c003f7cfe0bfcbc7b302eac988110c96ae",
},
},
"test_suite_relative_url": self.test_suite.getRelativeUrl()
},
self.test_result.TestResult_getTestSuiteData())
# the repositories on test suite can also have -repository suffix for
# buildout id. This is ignored in the keys of repository_dict from
# TestResult_getTestSuiteData, because this also ignored when generating
# the test result reference.
self.test_suite.erp5_repo.setBuildoutSectionId('foo-repository')
self.test_result.setReference('foo=1-dc7b6e2e85e9434a97694a698884b057b7d30286,test=10-cc4c79c003f7cfe0bfcbc7b302eac988110c96ae')
test_suite_data = self.test_result.TestResult_getTestSuiteData()
self.assertEqual(set(['foo', 'test']), set(test_suite_data['repository_dict']))
# another edge case is when in test suite repository we have a buildout_section_id
# containing a -
self.test_suite.erp5_repo.setBuildoutSectionId('foo-bar')
self.test_result.setReference('foo-bar=1-dc7b6e2e85e9434a97694a698884b057b7d30286,test=10-cc4c79c003f7cfe0bfcbc7b302eac988110c96ae')
test_suite_data = self.test_result.TestResult_getTestSuiteData()
self.assertEqual({
"commits_count": 1,
"connector_relative_url": None,
"repository_url": "https://lab.nexedi.com/nexedi/erp5.git",
"revision": "dc7b6e2e85e9434a97694a698884b057b7d30286",
},
test_suite_data['repository_dict']['foo-bar'])
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