# Path: bugwarrior/services/activecollab.py
# class ActiveCollabService(IssueService):
#     ISSUE_CLASS = ActiveCollabIssue
#     CONFIG_SCHEMA = ActiveCollabConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
# 
#         self.client = ActiveCollabClient(
#             self.config.url, self.config.key, self.config.user_id
#         )
#         self.activecollab = activeCollab(url=self.config.url,
#                                          key=self.config.key,
#                                          user_id=self.config.user_id)
# 
#     def _comments(self, issue):
#         comments = self.activecollab.get_comments(
#             issue['project_id'],
#             issue['task_id']
#         )
#         comments_formatted = []
#         if comments is not None:
#             for comment in comments:
#                 comments_formatted.append(
#                     dict(user=comment['created_by']['display_name'],
#                          body=comment['body']))
#         return comments_formatted
# 
#     def get_owner(self, issue):
#         if issue['assignee_id']:
#             return issue['assignee_id']
# 
#     def annotations(self, issue, issue_obj):
#         if 'type' not in issue:
#             # Subtask
#             return []
#         comments = self._comments(issue)
#         if comments is None:
#             return []
# 
#         return self.build_annotations(
#             ((
#                 c['user'],
#                 pypandoc.convert_text(c['body'], 'md', format='html').rstrip()
#             ) for c in comments),
#             issue_obj.get_processed_url(issue_obj.record['permalink']),
#         )
# 
#     def issues(self):
#         data = self.activecollab.get_my_tasks()
#         label_data = self.activecollab.get_assignment_labels()
#         labels = dict()
#         for item in label_data:
#             labels[item['id']] = re.sub(r'\W+', '_', item['name'])
#         task_count = 0
#         issues = []
#         for key, record in data.items():
#             for task_id, task in record['assignments'].items():
#                 task_count = task_count + 1
#                 # Add tasks
#                 if task['assignee_id'] == self.config.user_id:
#                     task['label'] = labels.get(task['label_id'])
#                     issues.append(task)
#                 if 'subtasks' in task:
#                     for subtask_id, subtask in task['subtasks'].items():
#                         # Add subtasks
#                         task_count = task_count + 1
#                         if subtask['assignee_id'] is self.config.user_id:
#                             # Add some data from the parent task
#                             subtask['label'] = labels.get(subtask['label_id'])
#                             subtask['project_id'] = task['project_id']
#                             subtask['project'] = task['project']
#                             subtask['task_id'] = task['task_id']
#                             subtask['milestone'] = task['milestone']
#                             issues.append(subtask)
#         log.debug(" Found %i total", task_count)
#         log.debug(" Pruned down to %i", len(issues))
#         for issue in issues:
#             issue_obj = self.get_issue_for_record(issue)
#             extra = {
#                 'annotations': self.annotations(issue, issue_obj)
#             }
#             issue_obj.update_extra(extra)
#             yield issue_obj
# 
# 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 datetime
import unittest
import pypandoc
import pytz
from unittest import mock
from bugwarrior.services.activecollab import (
    ActiveCollabService
)
from .base import ServiceTest, AbstractServiceTest
    arbitrary_issue = {
        'priority': 0,
        'project': 'something',
        'due_on': {
            'formatted_date': arbitrary_due_on.isoformat(),
        },
        'permalink': 'http://wherever/',
        'task_id': 10,
        'project_name': 'something',
        'project_id': 10,
        'id': 30,
        'type': 'issue',
        'created_on': {
            'formatted_date': arbitrary_created_on.isoformat(),
        },
        'created_by_name': 'Tester',
        'body': _body.rstrip(),
        'name': 'Anonymous',
        'milestone': 'Sprint 1',
        'estimated_time': 1,
        'tracked_time': 10,
        'label': 'ON_HOLD',
        'assignee_id': 2,
        'label_id': 1,
    }

    def setUp(self):
        super().setUp()
        self.maxDiff = None
        with mock.patch('pyac.library.activeCollab.call_api'):

# Path: bugwarrior/services/activecollab.py
# class ActiveCollabService(IssueService):
#     ISSUE_CLASS = ActiveCollabIssue
#     CONFIG_SCHEMA = ActiveCollabConfig
# 
#     def __init__(self, *args, **kw):
#         super().__init__(*args, **kw)
# 
#         self.client = ActiveCollabClient(
#             self.config.url, self.config.key, self.config.user_id
#         )
#         self.activecollab = activeCollab(url=self.config.url,
#                                          key=self.config.key,
#                                          user_id=self.config.user_id)
# 
#     def _comments(self, issue):
#         comments = self.activecollab.get_comments(
#             issue['project_id'],
#             issue['task_id']
#         )
#         comments_formatted = []
#         if comments is not None:
#             for comment in comments:
#                 comments_formatted.append(
#                     dict(user=comment['created_by']['display_name'],
#                          body=comment['body']))
#         return comments_formatted
# 
#     def get_owner(self, issue):
#         if issue['assignee_id']:
#             return issue['assignee_id']
# 
#     def annotations(self, issue, issue_obj):
#         if 'type' not in issue:
#             # Subtask
#             return []
#         comments = self._comments(issue)
#         if comments is None:
#             return []
# 
#         return self.build_annotations(
#             ((
#                 c['user'],
#                 pypandoc.convert_text(c['body'], 'md', format='html').rstrip()
#             ) for c in comments),
#             issue_obj.get_processed_url(issue_obj.record['permalink']),
#         )
# 
#     def issues(self):
#         data = self.activecollab.get_my_tasks()
#         label_data = self.activecollab.get_assignment_labels()
#         labels = dict()
#         for item in label_data:
#             labels[item['id']] = re.sub(r'\W+', '_', item['name'])
#         task_count = 0
#         issues = []
#         for key, record in data.items():
#             for task_id, task in record['assignments'].items():
#                 task_count = task_count + 1
#                 # Add tasks
#                 if task['assignee_id'] == self.config.user_id:
#                     task['label'] = labels.get(task['label_id'])
#                     issues.append(task)
#                 if 'subtasks' in task:
#                     for subtask_id, subtask in task['subtasks'].items():
#                         # Add subtasks
#                         task_count = task_count + 1
#                         if subtask['assignee_id'] is self.config.user_id:
#                             # Add some data from the parent task
#                             subtask['label'] = labels.get(subtask['label_id'])
#                             subtask['project_id'] = task['project_id']
#                             subtask['project'] = task['project']
#                             subtask['task_id'] = task['task_id']
#                             subtask['milestone'] = task['milestone']
#                             issues.append(subtask)
#         log.debug(" Found %i total", task_count)
#         log.debug(" Pruned down to %i", len(issues))
#         for issue in issues:
#             issue_obj = self.get_issue_for_record(issue)
#             extra = {
#                 'annotations': self.annotations(issue, issue_obj)
#             }
#             issue_obj.update_extra(extra)
#             yield issue_obj
# 
# 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_activecollab.py
import datetime
import unittest
import pypandoc
import pytz
from unittest import mock
from bugwarrior.services.activecollab import (
    ActiveCollabService
)
from .base import ServiceTest, AbstractServiceTest

    arbitrary_issue = {
        'priority': 0,
        'project': 'something',
        'due_on': {
            'formatted_date': arbitrary_due_on.isoformat(),
        },
        'permalink': 'http://wherever/',
        'task_id': 10,
        'project_name': 'something',
        'project_id': 10,
        'id': 30,
        'type': 'issue',
        'created_on': {
            'formatted_date': arbitrary_created_on.isoformat(),
        },
        'created_by_name': 'Tester',
        'body': _body.rstrip(),
        'name': 'Anonymous',
        'milestone': 'Sprint 1',
        'estimated_time': 1,
        'tracked_time': 10,
        'label': 'ON_HOLD',
        'assignee_id': 2,
        'label_id': 1,
    }

    def setUp(self):
        super().setUp()
        self.maxDiff = None
        with mock.patch('pyac.library.activeCollab.call_api'):

            self.service = self.get_mock_service(ActiveCollabService)