from logging import getLogger
from plone.testing import layered
from ploneintranet.suite.testing import PLONEINTRANET_SUITE_ROBOT

import os
import robotsuite
import unittest
import warnings

logger = getLogger()


def test_suite():
    suite = unittest.TestSuite()
    for testfile in os.listdir(os.path.join(os.path.dirname(__file__), "acceptance")):
        testfilepath = os.path.join("acceptance", testfile)
        if os.path.isdir(testfilepath):
            continue
        if testfile.endswith(".solr.robot"):

            # FIXME mixing solr and non-solr layers breaks
            # skipping library solr tests for now
            continue

        # TODO port those tests
        if testfile == "notifications.robot":
            warnings.warn(
                "Skipping notification robot tests. "
                "These should be redone for notifications v3."
            )
            continue

        if testfile.endswith(".robot"):
            suite.addTests(
                [
                    layered(
                        robotsuite.RobotTestSuite(
                            testfilepath,
                            noncritical=["fixme", "noncritical", "heisenbug"],
                        ),
                        layer=PLONEINTRANET_SUITE_ROBOT,
                    )
                ]
            )
    return suite
