# Path: bugwarrior/services/taiga.py
# class TaigaService(IssueService, ServiceClient):
#     ISSUE_CLASS = TaigaIssue
#     CONFIG_SCHEMA = TaigaConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
#         self.auth_token = self.get_password('auth_token')
#         self.session = requests.session()
#         self.session.headers.update({
#             'Accept': 'application/json',
#             'Authorization': 'Bearer %s' % self.auth_token,
#         })
# 
#     @staticmethod
#     def get_keyring_service(config):
#         return f"taiga://{config.base_uri}"
# 
#     def get_service_metadata(self):
#         return {
#             'url': self.config.base_uri,
#             'label_template': self.config.label_template,
#         }
# 
#     def get_owner(self, issue):
#         # TODO
#         raise NotImplementedError(
#             "This service has not implemented support for 'only_if_assigned'.")
# 
#     def _issues(self, userid, task_type, task_type_plural, task_type_short):
#         log.debug('Getting %s' % task_type_plural)
# 
#         response = self.session.get(
#             self.config.base_uri + '/api/v1/' + task_type_plural,
#             params={'assigned_to': userid, 'status__is_closed': "false"})
#         tasks = response.json()
# 
#         for task in tasks:
#             project = self.get_project(task['project'])
#             extra = {
#                 'project': project['slug'],
#                 'annotations': self.annotations(task, project, task_type, task_type_short),
#                 'url': self.build_url(task, project, task_type_short),
#             }
#             yield self.get_issue_for_record(task, extra)
# 
#     def issues(self):
#         url = self.config.base_uri + '/api/v1/users/me'
#         me = self.session.get(url)
#         data = me.json()
# 
#         # Check for errors and bail if we failed.
#         if '_error_message' in data:
#             raise RuntimeError("{_error_type} {_error_message}".format(**data))
# 
#         # Otherwise, proceed.
#         userid = data['id']
# 
#         yield from self._issues(userid, 'userstory', 'userstories', 'us')
# 
#         if self.config.include_tasks:
#             yield from self._issues(userid, 'task', 'tasks', 'task')
# 
#     @cache.cache_on_arguments()
#     def get_project(self, project_id):
#         url = '%s/api/v1/projects/%i' % (self.config.base_uri, project_id)
#         return self.json_response(self.session.get(url))
# 
#     def build_url(self, task, project, task_type):
#         return '%s/project/%s/%s/%i' % (
#             self.config.base_uri, project['slug'], task_type, task['ref'])
# 
#     def annotations(self, task, project, task_type, task_type_short):
#         url = f"{self.config.base_uri}/api/v1/history/{task_type}/{task['id']}"
#         response = self.session.get(url)
#         history = response.json()
#         return self.build_annotations(
#             ((
#                 item['user']['username'],
#                 item['comment'],
#             ) for item in history if item['comment']),
#             self.build_url(task, project, task_type_short)
#         )
# 
# 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


import responses
from bugwarrior.services.taiga import TaigaService
from .base import ServiceTest, AbstractServiceTest




class TestTaigaIssue(AbstractServiceTest, ServiceTest):
    SERVICE_CONFIG = {
        'service': 'taiga',
        'taiga.base_uri': 'https://one',
        'taiga.auth_token': 'two',
    }
    record = {
        'id': 400,
        'project': 4,
        'ref': 40,
        'subject': 'this is a title',
        'tags': [
            'single',
            [
                'bugwarrior',
                None
            ],
            [
                'task',
                '#c0ffee'
            ]
        ],
    }

    def setUp(self):
        super().setUp()

# Path: bugwarrior/services/taiga.py
# class TaigaService(IssueService, ServiceClient):
#     ISSUE_CLASS = TaigaIssue
#     CONFIG_SCHEMA = TaigaConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
#         self.auth_token = self.get_password('auth_token')
#         self.session = requests.session()
#         self.session.headers.update({
#             'Accept': 'application/json',
#             'Authorization': 'Bearer %s' % self.auth_token,
#         })
# 
#     @staticmethod
#     def get_keyring_service(config):
#         return f"taiga://{config.base_uri}"
# 
#     def get_service_metadata(self):
#         return {
#             'url': self.config.base_uri,
#             'label_template': self.config.label_template,
#         }
# 
#     def get_owner(self, issue):
#         # TODO
#         raise NotImplementedError(
#             "This service has not implemented support for 'only_if_assigned'.")
# 
#     def _issues(self, userid, task_type, task_type_plural, task_type_short):
#         log.debug('Getting %s' % task_type_plural)
# 
#         response = self.session.get(
#             self.config.base_uri + '/api/v1/' + task_type_plural,
#             params={'assigned_to': userid, 'status__is_closed': "false"})
#         tasks = response.json()
# 
#         for task in tasks:
#             project = self.get_project(task['project'])
#             extra = {
#                 'project': project['slug'],
#                 'annotations': self.annotations(task, project, task_type, task_type_short),
#                 'url': self.build_url(task, project, task_type_short),
#             }
#             yield self.get_issue_for_record(task, extra)
# 
#     def issues(self):
#         url = self.config.base_uri + '/api/v1/users/me'
#         me = self.session.get(url)
#         data = me.json()
# 
#         # Check for errors and bail if we failed.
#         if '_error_message' in data:
#             raise RuntimeError("{_error_type} {_error_message}".format(**data))
# 
#         # Otherwise, proceed.
#         userid = data['id']
# 
#         yield from self._issues(userid, 'userstory', 'userstories', 'us')
# 
#         if self.config.include_tasks:
#             yield from self._issues(userid, 'task', 'tasks', 'task')
# 
#     @cache.cache_on_arguments()
#     def get_project(self, project_id):
#         url = '%s/api/v1/projects/%i' % (self.config.base_uri, project_id)
#         return self.json_response(self.session.get(url))
# 
#     def build_url(self, task, project, task_type):
#         return '%s/project/%s/%s/%i' % (
#             self.config.base_uri, project['slug'], task_type, task['ref'])
# 
#     def annotations(self, task, project, task_type, task_type_short):
#         url = f"{self.config.base_uri}/api/v1/history/{task_type}/{task['id']}"
#         response = self.session.get(url)
#         history = response.json()
#         return self.build_annotations(
#             ((
#                 item['user']['username'],
#                 item['comment'],
#             ) for item in history if item['comment']),
#             self.build_url(task, project, task_type_short)
#         )
# 
# 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_taiga.py
import responses
from bugwarrior.services.taiga import TaigaService
from .base import ServiceTest, AbstractServiceTest





class TestTaigaIssue(AbstractServiceTest, ServiceTest):
    SERVICE_CONFIG = {
        'service': 'taiga',
        'taiga.base_uri': 'https://one',
        'taiga.auth_token': 'two',
    }
    record = {
        'id': 400,
        'project': 4,
        'ref': 40,
        'subject': 'this is a title',
        'tags': [
            'single',
            [
                'bugwarrior',
                None
            ],
            [
                'task',
                '#c0ffee'
            ]
        ],
    }

    def setUp(self):
        super().setUp()

        self.service = self.get_mock_service(TaigaService)