From f20d2689b876928bf5206dea244d014f934155cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 16 Oct 2019 07:02:58 +0200
Subject: [PATCH] test_result: tolerate buildout section ids with -

parsing of reference in TestResult_getTestSuiteData did not handle
properly buildout section ids with -, this was causing

  File "Script (Python)", line 30, in TestResult_getTestSuiteData
    buildout_section_id_and_commits_count, revision = repository_string.split('-')
  ValueError: too many values to unpack
---
 .../erp5_test_result/TestResult_getTestSuiteData.py |  4 ++--
 .../test.erp5.testTaskDistribution.py               | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResult_getTestSuiteData.py b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResult_getTestSuiteData.py
index 26280461cb..9b8dbea7e0 100644
--- a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResult_getTestSuiteData.py
+++ b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResult_getTestSuiteData.py
@@ -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),
diff --git a/bt5/erp5_test_result/TestTemplateItem/portal_components/test.erp5.testTaskDistribution.py b/bt5/erp5_test_result/TestTemplateItem/portal_components/test.erp5.testTaskDistribution.py
index 25e9077861..5565557b58 100644
--- a/bt5/erp5_test_result/TestTemplateItem/portal_components/test.erp5.testTaskDistribution.py
+++ b/bt5/erp5_test_result/TestTemplateItem/portal_components/test.erp5.testTaskDistribution.py
@@ -1575,3 +1575,16 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
     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'])
-- 
2.30.9