From 11d1d33f4067e163f2c87d38eeefd15c6941f18e Mon Sep 17 00:00:00 2001
From: Alain Takoudjou <talino@tiolive.com>
Date: Wed, 12 Nov 2014 14:38:43 +0000
Subject: [PATCH] runTestSuite should be able to pick test files in
 portal_components folder

All tests in SlapOS bt5 have been migrated in portal_components, The commit
rewrite the method getTestList to allow to search tests script in portal_components folder.
Tests in product/Vifib/tests are broken and was not ran at all. So we remove them from the list.
---
 master/tests/__init__.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/master/tests/__init__.py b/master/tests/__init__.py
index 6262fd734..4493b7511 100644
--- a/master/tests/__init__.py
+++ b/master/tests/__init__.py
@@ -1,4 +1,7 @@
 from test_suite import SavedTestSuite, ProjectTestSuite
+from glob import glob
+import os, re
+import sys
 
 slapos_bt_list = [
     'erp5_web_shacache',
@@ -20,6 +23,38 @@ class SlapOSCloud(SavedTestSuite, ProjectTestSuite):
   _product_list = ['SlapOS']
   _saved_test_id = 'Products.SlapOS.tests.testSlapOSMixin.testSlapOSMixin'
   _bt_list = slapos_bt_list
+  
+  def getTestList(self):
+    test_list = []
+    path = sys.path[0]
+    erp5_path = sys.path[1]
+    component_re = re.compile(".*/([^/]+)/TestTemplateItem/portal_components"
+                              "/test\.[^.]+\.([^.]+).py$")
+    for test_path in (
+        glob('%s/product/*/tests/test*.py' % path) +
+        glob('%s/bt5/*/TestTemplateItem/test*.py' % path) +
+        glob('%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py' % path) +
+        glob('%s/bt5/*/TestTemplateItem/test*.py' % erp5_path) +
+        glob('%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py' % erp5_path)):
+      component_re_match = component_re.match(test_path)
+      if component_re_match is not None:
+        test_case = "%s:%s" % (component_re_match.group(1),
+                               component_re_match.group(2))
+      else:
+        test_case = test_path.split(os.sep)[-1][:-3] # remove .py
+      # Filter bt tests to run from _bt_list list
+      if test_path.split(os.sep)[-2] != 'tests':
+        if test_path.split(os.sep)[-2] == 'portal_components':
+          product = test_path.split(os.sep)[-4]
+        else:
+          product = test_path.split(os.sep)[-3]
+        if not product in self._bt_list:
+          continue
+      elif test_path.split(os.sep)[-3] == 'Vifib':
+        # There is no valid tests in Vifib!
+        continue
+      test_list.append(test_case)
+    return test_list
 
   def __init__(self, max_instance_count=1, *args, **kw):
     # hardcode number of node, to prevent concurrency issue on certificate
-- 
2.30.9