# Path: tests/corobo_test_case.py
# class CoroboTestCase(FullStackTest):
# 
#     def setUp(self, klasses: tuple):
#         super().setUp(loglevel=logging.ERROR,
#                       extra_config={'BACKEND': 'text'})
#         self.klasses = {}
#         self.plug_files = {}
#         self.plugins = {}
# 
#         for klass in klasses:
#             self.klasses[klass.__name__] = klass
#             self.load_plugin_templates(klass)
# 
#     def load_plugin_templates(self, klass):
#         plug_filename = klass.__module__.split('.')[-1] + '.plug'
#         plug_file_path = (Path(__file__)
#                           .parent / '..' / 'plugins' / plug_filename)
#         with plug_file_path.open() as plugfile:
#             plug_info = PluginInfo.load_file(plugfile, plug_file_path)
#             self.plug_files[klass.__name__] = plug_info
#             add_plugin_templates_path(plug_info)
# 
#     def load_plugin(self,
#                     plugin_name: str,
#                     mock_dict=False,
#                     plugin_config=None):
#         """Load plugin manually"""
#         klass = self.klasses[plugin_name]
#         plugin = klass(self.bot, plugin_name)
#         plugin.configure(plugin_config)
#         self.plugins[plugin_name] = plugin
#         self.bot.plugin_manager.plugins[plugin_name] = plugin
#         plug_file = self.plug_files[plugin_name]
#         plugin.dependencies = plug_file.dependencies
#         self.bot.plugin_manager.plugin_infos[plug_file.name] = plug_file
#         plugin.activate()
# 
#         if mock_dict:
#             self.inject_mocks(plugin_name=plugin_name, mock_dict=mock_dict)
# 
#         return plugin


import github3
import IGitt
import plugins.labhub
from unittest.mock import create_autospec, PropertyMock
from tests.corobo_test_case import CoroboTestCase



class LabHubTestCase(CoroboTestCase):

    def setUp(self, klasses=None):
        plugins.labhub.github3 = create_autospec(github3)

        self.mock_org = create_autospec(github3.orgs.Organization)
        self.mock_gh = create_autospec(github3.GitHub)
        self.mock_team = create_autospec(github3.orgs.Team)
        self.mock_team.name = PropertyMock()
        self.mock_team.name = 'mocked team'
        self.teams = {
            'coala newcomers': self.mock_team,
            'coala developers': self.mock_team,
            'coala maintainers': self.mock_team,
        }

        self.mock_repo = create_autospec(IGitt.GitHub.GitHub.GitHubRepository)

        plugins.labhub.github3.login.return_value = self.mock_gh
        self.mock_gh.organization.return_value = self.mock_org
        self.mock_org.teams.return_value = [self.mock_team]
        plugins.labhub.github3.organization.return_value = self.mock_org

        # patching
        plugins.labhub.GitHub = create_autospec(IGitt.GitHub.GitHub.GitHub)

# Path: tests/corobo_test_case.py
# class CoroboTestCase(FullStackTest):
# 
#     def setUp(self, klasses: tuple):
#         super().setUp(loglevel=logging.ERROR,
#                       extra_config={'BACKEND': 'text'})
#         self.klasses = {}
#         self.plug_files = {}
#         self.plugins = {}
# 
#         for klass in klasses:
#             self.klasses[klass.__name__] = klass
#             self.load_plugin_templates(klass)
# 
#     def load_plugin_templates(self, klass):
#         plug_filename = klass.__module__.split('.')[-1] + '.plug'
#         plug_file_path = (Path(__file__)
#                           .parent / '..' / 'plugins' / plug_filename)
#         with plug_file_path.open() as plugfile:
#             plug_info = PluginInfo.load_file(plugfile, plug_file_path)
#             self.plug_files[klass.__name__] = plug_info
#             add_plugin_templates_path(plug_info)
# 
#     def load_plugin(self,
#                     plugin_name: str,
#                     mock_dict=False,
#                     plugin_config=None):
#         """Load plugin manually"""
#         klass = self.klasses[plugin_name]
#         plugin = klass(self.bot, plugin_name)
#         plugin.configure(plugin_config)
#         self.plugins[plugin_name] = plugin
#         self.bot.plugin_manager.plugins[plugin_name] = plugin
#         plug_file = self.plug_files[plugin_name]
#         plugin.dependencies = plug_file.dependencies
#         self.bot.plugin_manager.plugin_infos[plug_file.name] = plug_file
#         plugin.activate()
# 
#         if mock_dict:
#             self.inject_mocks(plugin_name=plugin_name, mock_dict=mock_dict)
# 
#         return plugin


# Path: tests/labhub_test_case.py
import github3
import IGitt
import plugins.labhub
from unittest.mock import create_autospec, PropertyMock
from tests.corobo_test_case import CoroboTestCase




class LabHubTestCase(CoroboTestCase):

    def setUp(self, klasses=None):
        plugins.labhub.github3 = create_autospec(github3)

        self.mock_org = create_autospec(github3.orgs.Organization)
        self.mock_gh = create_autospec(github3.GitHub)
        self.mock_team = create_autospec(github3.orgs.Team)
        self.mock_team.name = PropertyMock()
        self.mock_team.name = 'mocked team'
        self.teams = {
            'coala newcomers': self.mock_team,
            'coala developers': self.mock_team,
            'coala maintainers': self.mock_team,
        }

        self.mock_repo = create_autospec(IGitt.GitHub.GitHub.GitHubRepository)

        plugins.labhub.github3.login.return_value = self.mock_gh
        self.mock_gh.organization.return_value = self.mock_org
        self.mock_org.teams.return_value = [self.mock_team]
        plugins.labhub.github3.organization.return_value = self.mock_org

        # patching
        plugins.labhub.GitHub = create_autospec(IGitt.GitHub.GitHub.GitHub)

        plugins.labhub.GitLab = create_autospec(IGitt.GitLab.GitLab.GitLab)