# Path: bugwarrior/services/teamlab.py
# class TeamLabService(IssueService):
#     ISSUE_CLASS = TeamLabIssue
#     CONFIG_SCHEMA = TeamLabConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
# 
#         _password = self.get_password('password', self.config.login)
# 
#         self.client = TeamLabClient(self.config.hostname)
#         self.client.authenticate(self.config.login, _password)
# 
#         self.project_name = self.config.project_name or self.config.hostname
# 
#     @staticmethod
#     def get_keyring_service(config):
#         return f"teamlab://{config.login}@{config.hostname}"
# 
#     def get_service_metadata(self):
#         return {
#             'hostname': self.config.hostname,
#             'project_name': self.project_name,
#         }
# 
#     def get_owner(self, issue):
#         # TODO
#         raise NotImplementedError(
#             "This service has not implemented support for 'only_if_assigned'.")
# 
#     def issues(self):
#         issues = self.client.get_task_list()
#         log.debug(" Remote has %i total issues.", len(issues))
# 
#         # Filter out closed tasks.
#         issues = [i for i in issues if i["status"] == 1]
#         log.debug(" Remote has %i active issues.", len(issues))
# 
#         for issue in issues:
#             yield self.get_issue_for_record(issue)
# 
# Path: tests/base.py
# class ServiceTest(ConfigTest):
#     GENERAL_CONFIG = {
#         'interactive': False,
#         'annotation_length': 100,
#         'description_length': 100,
#     }
#     SERVICE_CONFIG = {
#     }
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.maxDiff = None
# 
#     def get_mock_service(
#         self, service_class, section='unspecified',
#         config_overrides=None, general_overrides=None
#     ):
#         options = {
#             'general': {**self.GENERAL_CONFIG, 'targets': section},
#             section: self.SERVICE_CONFIG.copy(),
#         }
#         if config_overrides:
#             options[section].update(config_overrides)
#         if general_overrides:
#             options['general'].update(general_overrides)
# 
#         service_config = service_class.CONFIG_SCHEMA(**options[section])
#         main_config = schema.MainSectionConfig(**options['general'])
#         main_config.data = data.BugwarriorData(self.lists_path)
# 
#         return service_class(service_config, main_config, section)
# 
#     @staticmethod
#     def add_response(url, **kwargs):
#         responses.add(responses.GET, url, match_querystring=True, **kwargs)
# 
# class AbstractServiceTest(abc.ABC):
#     """ Ensures that certain test methods are implemented for each service. """
#     @abc.abstractmethod
#     def test_to_taskwarrior(self):
#         """ Test Service.to_taskwarrior(). """
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def test_issues(self):
#         """
#         Test Service.issues().
# 
#         - When the API is accessed via requests, use the responses library to
#         mock requests.
#         - When the API is accessed via a third party library, substitute a fake
#         implementation class for it.
#         """
#         raise NotImplementedError


from unittest import mock
from bugwarrior.services.teamlab import TeamLabService
from .base import ServiceTest, AbstractServiceTest
import responses
        'projectOwner': {
            'id': 140,
        },
        'status': 1,
    }

    def setUp(self):
        super().setUp()
        with mock.patch(
            'bugwarrior.services.teamlab.TeamLabClient.authenticate'
        ):
            self.service = self.get_mock_service(TeamLabService)

    def test_to_taskwarrior(self):
        arbitrary_url = 'http://galkjsdflkj.com/'

        issue = self.service.get_issue_for_record(self.arbitrary_issue)

        expected_output = {
            'project': self.SERVICE_CONFIG['teamlab.project_name'],
            'priority': self.service.config.default_priority,
            issue.TITLE: self.arbitrary_issue['title'],
            issue.FOREIGN_ID: self.arbitrary_issue['id'],
            issue.URL: arbitrary_url,
            issue.PROJECTOWNER_ID: self.arbitrary_issue['projectOwner']['id']
        }

        def get_url(*args):
            return arbitrary_url


# Path: bugwarrior/services/teamlab.py
# class TeamLabService(IssueService):
#     ISSUE_CLASS = TeamLabIssue
#     CONFIG_SCHEMA = TeamLabConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
# 
#         _password = self.get_password('password', self.config.login)
# 
#         self.client = TeamLabClient(self.config.hostname)
#         self.client.authenticate(self.config.login, _password)
# 
#         self.project_name = self.config.project_name or self.config.hostname
# 
#     @staticmethod
#     def get_keyring_service(config):
#         return f"teamlab://{config.login}@{config.hostname}"
# 
#     def get_service_metadata(self):
#         return {
#             'hostname': self.config.hostname,
#             'project_name': self.project_name,
#         }
# 
#     def get_owner(self, issue):
#         # TODO
#         raise NotImplementedError(
#             "This service has not implemented support for 'only_if_assigned'.")
# 
#     def issues(self):
#         issues = self.client.get_task_list()
#         log.debug(" Remote has %i total issues.", len(issues))
# 
#         # Filter out closed tasks.
#         issues = [i for i in issues if i["status"] == 1]
#         log.debug(" Remote has %i active issues.", len(issues))
# 
#         for issue in issues:
#             yield self.get_issue_for_record(issue)
# 
# Path: tests/base.py
# class ServiceTest(ConfigTest):
#     GENERAL_CONFIG = {
#         'interactive': False,
#         'annotation_length': 100,
#         'description_length': 100,
#     }
#     SERVICE_CONFIG = {
#     }
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.maxDiff = None
# 
#     def get_mock_service(
#         self, service_class, section='unspecified',
#         config_overrides=None, general_overrides=None
#     ):
#         options = {
#             'general': {**self.GENERAL_CONFIG, 'targets': section},
#             section: self.SERVICE_CONFIG.copy(),
#         }
#         if config_overrides:
#             options[section].update(config_overrides)
#         if general_overrides:
#             options['general'].update(general_overrides)
# 
#         service_config = service_class.CONFIG_SCHEMA(**options[section])
#         main_config = schema.MainSectionConfig(**options['general'])
#         main_config.data = data.BugwarriorData(self.lists_path)
# 
#         return service_class(service_config, main_config, section)
# 
#     @staticmethod
#     def add_response(url, **kwargs):
#         responses.add(responses.GET, url, match_querystring=True, **kwargs)
# 
# class AbstractServiceTest(abc.ABC):
#     """ Ensures that certain test methods are implemented for each service. """
#     @abc.abstractmethod
#     def test_to_taskwarrior(self):
#         """ Test Service.to_taskwarrior(). """
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def test_issues(self):
#         """
#         Test Service.issues().
# 
#         - When the API is accessed via requests, use the responses library to
#         mock requests.
#         - When the API is accessed via a third party library, substitute a fake
#         implementation class for it.
#         """
#         raise NotImplementedError


# Path: tests/test_teamlab.py
from unittest import mock
from bugwarrior.services.teamlab import TeamLabService
from .base import ServiceTest, AbstractServiceTest
import responses

        'projectOwner': {
            'id': 140,
        },
        'status': 1,
    }

    def setUp(self):
        super().setUp()
        with mock.patch(
            'bugwarrior.services.teamlab.TeamLabClient.authenticate'
        ):
            self.service = self.get_mock_service(TeamLabService)

    def test_to_taskwarrior(self):
        arbitrary_url = 'http://galkjsdflkj.com/'

        issue = self.service.get_issue_for_record(self.arbitrary_issue)

        expected_output = {
            'project': self.SERVICE_CONFIG['teamlab.project_name'],
            'priority': self.service.config.default_priority,
            issue.TITLE: self.arbitrary_issue['title'],
            issue.FOREIGN_ID: self.arbitrary_issue['id'],
            issue.URL: arbitrary_url,
            issue.PROJECTOWNER_ID: self.arbitrary_issue['projectOwner']['id']
        }

        def get_url(*args):
            return arbitrary_url


        with mock.patch.object(issue, 'get_issue_url', side_effect=get_url):