# Path: tests/labhub_test_case.py
# 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)
#         plugins.labhub.GitHubToken = create_autospec(IGitt.GitHub.GitHubToken)
#         plugins.labhub.GitLabPrivateToken = create_autospec(
#             IGitt.GitLab.GitLabPrivateToken)
# 
#         if klasses:
#             super().setUp(klasses)


from tempfile import mkdtemp
from unittest.mock import create_autospec
from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
from IGitt.GitLab.GitLabMergeRequest import GitLabMergeRequest
from IGitt.GitHub.GitHubIssue import GitHubIssue
from IGitt.GitLab.GitLabIssue import GitLabIssue
from git import Repo
from tests.labhub_test_case import LabHubTestCase
import plugins.git_stats
        self.labhub = self.load_plugin('LabHub')
        self.git_stats = self.load_plugin('GitStats')
        self.git_stats.REPOS = {'test': self.mock_repo}

    def test_pr_list(self):
        mock_github_mr = create_autospec(GitHubMergeRequest)
        mock_gitlab_mr = create_autospec(GitLabMergeRequest)
        mock_github_issue = create_autospec(GitHubIssue)
        mock_gitlab_issue = create_autospec(GitLabIssue)
        mock_github_mr.closes_issue = mock_github_issue
        mock_gitlab_mr.closes_issue = mock_gitlab_issue
        mock_github_mr.repository = self.mock_repo
        mock_gitlab_mr.repository = self.mock_repo
        mock_github_mr.url = 'http://www.example.com/'
        mock_gitlab_mr.url = 'http://www.example.com/'
        mock_repo_obj = create_autospec(Repo)
        cmd_github = '!mergable {}'
        cmd_gitlab = '!mergable {}'
        testbot = self

        self.mock_repo.merge_requests = [mock_github_mr]

        # Non-existing repo
        testbot.assertCommand(cmd_github.format('b'),
                              'Repository doesn\'t exist.')
        testbot.assertCommand(cmd_gitlab.format('b'),
                              'Repository doesn\'t exist.')

        # PR is suitable
        mock_github_mr.labels = ['process/approved', 'difficulty/newcomer']

# Path: tests/labhub_test_case.py
# 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)
#         plugins.labhub.GitHubToken = create_autospec(IGitt.GitHub.GitHubToken)
#         plugins.labhub.GitLabPrivateToken = create_autospec(
#             IGitt.GitLab.GitLabPrivateToken)
# 
#         if klasses:
#             super().setUp(klasses)


# Path: tests/git_stats_test.py
from tempfile import mkdtemp
from unittest.mock import create_autospec
from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
from IGitt.GitLab.GitLabMergeRequest import GitLabMergeRequest
from IGitt.GitHub.GitHubIssue import GitHubIssue
from IGitt.GitLab.GitLabIssue import GitLabIssue
from git import Repo
from tests.labhub_test_case import LabHubTestCase
import plugins.git_stats

        self.labhub = self.load_plugin('LabHub')
        self.git_stats = self.load_plugin('GitStats')
        self.git_stats.REPOS = {'test': self.mock_repo}

    def test_pr_list(self):
        mock_github_mr = create_autospec(GitHubMergeRequest)
        mock_gitlab_mr = create_autospec(GitLabMergeRequest)
        mock_github_issue = create_autospec(GitHubIssue)
        mock_gitlab_issue = create_autospec(GitLabIssue)
        mock_github_mr.closes_issue = mock_github_issue
        mock_gitlab_mr.closes_issue = mock_gitlab_issue
        mock_github_mr.repository = self.mock_repo
        mock_gitlab_mr.repository = self.mock_repo
        mock_github_mr.url = 'http://www.example.com/'
        mock_gitlab_mr.url = 'http://www.example.com/'
        mock_repo_obj = create_autospec(Repo)
        cmd_github = '!mergable {}'
        cmd_gitlab = '!mergable {}'
        testbot = self

        self.mock_repo.merge_requests = [mock_github_mr]

        # Non-existing repo
        testbot.assertCommand(cmd_github.format('b'),
                              'Repository doesn\'t exist.')
        testbot.assertCommand(cmd_gitlab.format('b'),
                              'Repository doesn\'t exist.')

        # PR is suitable
        mock_github_mr.labels = ['process/approved', 'difficulty/newcomer']

        mock_gitlab_mr.labels = ['process/approved', 'difficulty/newcomer']