From 2a041f4bf7105cad8352e7c861804a8bc5dc8e06 Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Sat, 24 Aug 2024 00:07:25 -0400 Subject: [PATCH] Break TaskConstructor out of base Issue class. In preparation for stabilizing the base classes (#791), I'm moving these methods which child classes never need to call to a separate class in the collect module. We *could* leave them where they are and just make them private methods, but at this point I think slimming down the base classes as much as possible is our best bet to being disciplined about their stabilization. This not only removes lines of code but I believe the entire class of would-be private methods. I also removed the __str__ and __repr__ methods, which depended on the get_taskwarrior_record method. These used to be used in logging messages in db.synchronize but since #1037 db.synchronize is receiving dict's and not Issue's. (The usages in that method are presently mixed between logging `issue` and logging `issue['description']`. The logs could be improved by switching the remainder to the latter.) --- bugwarrior/collect.py | 53 +++++++++++++++++++- bugwarrior/docs/contributing/new-service.rst | 2 +- bugwarrior/services/__init__.py | 52 ------------------- tests/test_activecollab.py | 3 +- tests/test_activecollab2.py | 3 +- tests/test_azuredevops.py | 5 +- tests/test_bitbucket.py | 5 +- tests/test_bts.py | 4 +- tests/test_bugzilla.py | 9 ++-- tests/test_deck.py | 4 +- tests/test_gerrit.py | 6 ++- tests/test_gitbug.py | 3 +- tests/test_github.py | 7 +-- tests/test_gitlab.py | 11 ++-- tests/test_gmail.py | 3 +- tests/test_jira.py | 3 +- tests/test_kanboard.py | 3 +- tests/test_logseq.py | 6 ++- tests/test_pivotaltracker.py | 3 +- tests/test_redmine.py | 3 +- tests/test_taiga.py | 3 +- tests/test_teamlab.py | 3 +- tests/test_teamwork_projects.py | 10 ++-- tests/test_templates.py | 9 ++-- tests/test_trac.py | 3 +- tests/test_trello.py | 5 +- tests/test_youtrak.py | 3 +- 27 files changed, 126 insertions(+), 98 deletions(-) diff --git a/bugwarrior/collect.py b/bugwarrior/collect.py index c0fd163e..88bfcb7d 100644 --- a/bugwarrior/collect.py +++ b/bugwarrior/collect.py @@ -1,9 +1,13 @@ +import copy import logging import multiprocessing import time +from jinja2 import Template from pkg_resources import iter_entry_points +from taskw.task import Task + log = logging.getLogger(__name__) # Sentinels for process completion status @@ -88,7 +92,7 @@ def aggregate_issues(conf, main_section, debug): while currently_running > 0: issue = queue.get(True) try: - yield issue.get_taskwarrior_record() + yield TaskConstructor(issue).get_taskwarrior_record() except AttributeError: if isinstance(issue, tuple): currently_running -= 1 @@ -100,3 +104,50 @@ def aggregate_issues(conf, main_section, debug): yield issue log.info("Done aggregating remote issues.") + + +class TaskConstructor: + """ Construct a taskwarrior task from a foreign record. """ + + def __init__(self, issue): + self.issue = issue + + def get_added_tags(self): + added_tags = [] + for tag in self.issue.config.add_tags: + tag = Template(tag).render(self.get_template_context()) + if tag: + added_tags.append(tag) + + return added_tags + + def get_taskwarrior_record(self, refined=True) -> dict: + if not getattr(self, '_taskwarrior_record', None): + self._taskwarrior_record = self.issue.to_taskwarrior() + record = copy.deepcopy(self._taskwarrior_record) + if refined: + record = self.refine_record(record) + if 'tags' not in record: + record['tags'] = [] + if refined: + record['tags'].extend(self.get_added_tags()) + return record + + def get_template_context(self): + context = ( + self.get_taskwarrior_record(refined=False).copy() + ) + context.update(self.issue.extra) + context.update({ + 'description': self.issue.get_default_description(), + }) + return context + + def refine_record(self, record): + for field in Task.FIELDS.keys(): + if field in self.issue.config.templates: + template = Template(self.issue.config.templates[field]) + record[field] = template.render(self.get_template_context()) + elif hasattr(self.issue, 'get_default_%s' % field): + record[field] = getattr(self.issue, 'get_default_%s' % field)() + return record diff --git a/bugwarrior/docs/contributing/new-service.rst b/bugwarrior/docs/contributing/new-service.rst index 09795515..003aef5a 100644 --- a/bugwarrior/docs/contributing/new-service.rst +++ b/bugwarrior/docs/contributing/new-service.rst @@ -264,7 +264,7 @@ Create a test file and implement at least the minimal service tests by inheritin expected = { ... } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) 9. Documentation ------------------ diff --git a/bugwarrior/services/__init__.py b/bugwarrior/services/__init__.py index 2be8e9c1..775248c0 100644 --- a/bugwarrior/services/__init__.py +++ b/bugwarrior/services/__init__.py @@ -1,5 +1,4 @@ import abc -import copy import re from dateutil.parser import parse as parse_date @@ -7,8 +6,6 @@ from jinja2 import Template import pytz -from taskw.task import Task - from bugwarrior.config import schema, secrets from bugwarrior.db import MARKUP, URLShortener @@ -193,27 +190,6 @@ def get_tags_from_labels(self, return tags - def get_added_tags(self): - added_tags = [] - for tag in self.config.add_tags: - tag = Template(tag).render(self.get_template_context()) - if tag: - added_tags.append(tag) - - return added_tags - - def get_taskwarrior_record(self, refined=True) -> dict: - if not getattr(self, '_taskwarrior_record', None): - self._taskwarrior_record = self.to_taskwarrior() - record = copy.deepcopy(self._taskwarrior_record) - if refined: - record = self.refine_record(record) - if 'tags' not in record: - record['tags'] = [] - if refined: - record['tags'].extend(self.get_added_tags()) - return record - def get_priority(self): return self.PRIORITY_MAP.get( self.record.get('priority'), @@ -263,25 +239,6 @@ def build_default_description( url, ) - def get_template_context(self): - context = ( - self.get_taskwarrior_record(refined=False).copy() - ) - context.update(self.extra) - context.update({ - 'description': self.get_default_description(), - }) - return context - - def refine_record(self, record): - for field in Task.FIELDS.keys(): - if field in self.config.templates: - template = Template(self.config.templates[field]) - record[field] = template.render(self.get_template_context()) - elif hasattr(self, 'get_default_%s' % field): - record[field] = getattr(self, 'get_default_%s' % field)() - return record - @property def record(self): return self._foreign_record @@ -290,15 +247,6 @@ def record(self): def extra(self): return self._extra - def __str__(self): - return '%s: %s' % ( - self.config.target, - self.get_taskwarrior_record()['description'] - ) - - def __repr__(self): - return '<%s>' % str(self) - class ServiceClient: """ Abstract class responsible for making requests to service API's. """ diff --git a/tests/test_activecollab.py b/tests/test_activecollab.py index 536d3c5e..00df22c4 100644 --- a/tests/test_activecollab.py +++ b/tests/test_activecollab.py @@ -5,6 +5,7 @@ import pypandoc import pytz +from bugwarrior.collect import TaskConstructor from bugwarrior.services.activecollab import ( ActiveCollabService ) @@ -141,4 +142,4 @@ def test_issues(self): 'project': 'something', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_activecollab2.py b/tests/test_activecollab2.py index 35372416..3e963a83 100644 --- a/tests/test_activecollab2.py +++ b/tests/test_activecollab2.py @@ -4,6 +4,7 @@ import pytz import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.activecollab2 import ActiveCollab2Service from .base import ServiceTest, AbstractServiceTest @@ -97,4 +98,4 @@ def test_issues(self): 'project': 'something', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_azuredevops.py b/tests/test_azuredevops.py index 3165f8c0..a29aef93 100644 --- a/tests/test_azuredevops.py +++ b/tests/test_azuredevops.py @@ -3,6 +3,7 @@ from dateutil.tz.tz import tzutc +from bugwarrior.collect import TaskConstructor from bugwarrior.services.azuredevops import ( AzureDevopsService, striphtml, @@ -230,7 +231,7 @@ def test_issues(self): "tags": [] } issue = next(self.service.issues()) - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) def test_issues_wiql_filter(self): expected = { @@ -255,4 +256,4 @@ def test_issues_wiql_filter(self): } service = self.get_service(config_overrides={'wiql_filter': 'something'}) issue = next(service.issues()) - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_bitbucket.py b/tests/test_bitbucket.py index 223458be..4cd13a87 100644 --- a/tests/test_bitbucket.py +++ b/tests/test_bitbucket.py @@ -1,5 +1,6 @@ import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.bitbucket import BitbucketService from .base import ServiceTest, AbstractServiceTest @@ -104,7 +105,7 @@ def test_issues(self): 'project': 'somerepo', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected_issue) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected_issue) expected_pr = { 'annotations': ['@nobody - Some comment.'], @@ -116,7 +117,7 @@ def test_issues(self): 'project': 'somerepo', 'tags': []} - self.assertEqual(pr.get_taskwarrior_record(), expected_pr) + self.assertEqual(TaskConstructor(pr).get_taskwarrior_record(), expected_pr) def test_get_owner(self): issue = { diff --git a/tests/test_bts.py b/tests/test_bts.py index a372fd76..f1ca7303 100644 --- a/tests/test_bts.py +++ b/tests/test_bts.py @@ -1,6 +1,8 @@ import sys from unittest import mock, SkipTest +from bugwarrior.collect import TaskConstructor + if sys.version_info >= (3, 11): raise SkipTest( "Python-3.11+ not supported. " @@ -89,4 +91,4 @@ def test_issues(self): 'btsstatus': 'pending', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_bugzilla.py b/tests/test_bugzilla.py index 748a2c8f..37c75d7e 100644 --- a/tests/test_bugzilla.py +++ b/tests/test_bugzilla.py @@ -2,6 +2,7 @@ from unittest import mock from collections import namedtuple +from bugwarrior.collect import TaskConstructor from bugwarrior.services.bz import BugzillaService from .base import ConfigTest, ServiceTest, AbstractServiceTest @@ -155,7 +156,7 @@ def test_issues(self): 'project': 'Something', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) def test_only_if_assigned(self): with mock.patch('bugzilla.Bugzilla'): @@ -206,7 +207,7 @@ def test_only_if_assigned(self): 'project': 'Something', 'tags': []} - self.assertEqual(next(issues).get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(next(issues)).get_taskwarrior_record(), expected) # Only one issue is assigned. self.assertRaises(StopIteration, lambda: next(issues)) @@ -246,9 +247,9 @@ def test_also_unassigned(self): issues = self.service.issues() - self.assertIn(next(issues).get_taskwarrior_record()['bugzillabugid'], + self.assertIn(TaskConstructor(next(issues)).get_taskwarrior_record()['bugzillabugid'], [1234567, 1234568]) - self.assertIn(next(issues).get_taskwarrior_record()['bugzillabugid'], + self.assertIn(TaskConstructor(next(issues)).get_taskwarrior_record()['bugzillabugid'], [1234567, 1234568]) # Only two issues are assigned to the user or unassigned. self.assertRaises(StopIteration, lambda: next(issues)) diff --git a/tests/test_deck.py b/tests/test_deck.py index 96691689..ac8b1fe7 100644 --- a/tests/test_deck.py +++ b/tests/test_deck.py @@ -4,7 +4,9 @@ import pydantic from dateutil.tz import tzutc +from bugwarrior.collect import TaskConstructor from bugwarrior.services.deck import NextcloudDeckClient, NextcloudDeckService + from .base import AbstractServiceTest, ServiceTest @@ -157,7 +159,7 @@ def test_issues(self): 'tags': ['Later'] } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) def test_filter_boards_include(self): self.config['deck']['include_board_ids'] = '5' diff --git a/tests/test_gerrit.py b/tests/test_gerrit.py index b55437dc..b88a9067 100644 --- a/tests/test_gerrit.py +++ b/tests/test_gerrit.py @@ -2,7 +2,9 @@ import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.gerrit import GerritService + from .base import ServiceTest, AbstractServiceTest @@ -82,7 +84,7 @@ def test_work_in_progress(self): 'project': 'nova', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) @responses.activate def test_issues(self): @@ -107,4 +109,4 @@ def test_issues(self): 'project': 'nova', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_gitbug.py b/tests/test_gitbug.py index fc743206..015f6513 100644 --- a/tests/test_gitbug.py +++ b/tests/test_gitbug.py @@ -4,6 +4,7 @@ import dateutil import pydantic +from bugwarrior.collect import TaskConstructor from bugwarrior.services.gitbug import GitBugClient, GitBugConfig, GitBugService from .base import AbstractServiceTest, ConfigTest, ServiceTest @@ -82,7 +83,7 @@ def test_issues(self): 'tags': [] } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) class TestGitBugConfig(ConfigTest): diff --git a/tests/test_github.py b/tests/test_github.py index c387929d..2b6b3a95 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -4,6 +4,7 @@ import pytz import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.github import ( GithubConfig, GithubService, GithubClient) @@ -85,7 +86,7 @@ def test_draft(self): 'tags': [] } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) def test_to_taskwarrior(self): service = self.get_mock_service(GithubService, config_overrides={ @@ -178,7 +179,7 @@ def test_issues(self): 'project': 'arbitrary_repo', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) class TestGithubIssueQuery(AbstractServiceTest, ServiceTest): @@ -238,7 +239,7 @@ def test_issues(self): 'project': 'arbitrary_repo', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) class TestGithubService(ServiceTest): diff --git a/tests/test_gitlab.py b/tests/test_gitlab.py index a949a364..ce0b8108 100644 --- a/tests/test_gitlab.py +++ b/tests/test_gitlab.py @@ -3,6 +3,7 @@ import pytz import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.gitlab import GitlabService, GitlabClient from .base import ConfigTest, ServiceTest, AbstractServiceTest @@ -873,7 +874,7 @@ def test_issues_from_query(self): 'priority': 'M', 'project': 'arbitrary_username/project', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) @responses.activate def test_mrs_from_query(self): @@ -933,7 +934,7 @@ def test_mrs_from_query(self): 'priority': 'M', 'project': 'arbitrary_username/project', 'tags': []} - self.assertEqual(mr.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(mr).get_taskwarrior_record(), expected) @responses.activate def test_todos_from_query(self): @@ -997,7 +998,7 @@ def test_todos_from_query(self): 'priority': 'M', 'project': 'project', 'tags': []} - self.assertEqual(todo.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(todo).get_taskwarrior_record(), expected) overrides = { 'include_issues': 'false', @@ -1008,7 +1009,7 @@ def test_todos_from_query(self): } service = self.get_mock_service(GitlabService, config_overrides=overrides) todo = next(service.issues()) - self.assertEqual(todo.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(todo).get_taskwarrior_record(), expected) @responses.activate def test_issues(self): @@ -1065,4 +1066,4 @@ def test_issues(self): 'project': 'arbitrary_username/project', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_gmail.py b/tests/test_gmail.py index 480d4ee7..5bfef545 100644 --- a/tests/test_gmail.py +++ b/tests/test_gmail.py @@ -8,6 +8,7 @@ from dateutil.tz import tzutc from google.oauth2.credentials import Credentials +from bugwarrior.collect import TaskConstructor from bugwarrior.services import gmail from .base import AbstractServiceTest, ConfigTest, ServiceTest @@ -167,7 +168,7 @@ def test_issues(self): 'gmaillabels': 'CATEGORY_PERSONAL IMPORTANT postit sticky', 'gmaillastsenderaddr': 'foobar@example.com'} - taskwarrior = issue.get_taskwarrior_record() + taskwarrior = TaskConstructor(issue).get_taskwarrior_record() taskwarrior['tags'] = set(taskwarrior['tags']) self.assertEqual(taskwarrior, expected) diff --git a/tests/test_jira.py b/tests/test_jira.py index 7d61cff8..a25b8496 100644 --- a/tests/test_jira.py +++ b/tests/test_jira.py @@ -4,6 +4,7 @@ from dateutil.tz import datetime from dateutil.tz.tz import tzutc +from bugwarrior.collect import TaskConstructor from bugwarrior.config import schema from bugwarrior.services.jira import JiraExtraFields, JiraService @@ -240,7 +241,7 @@ def test_issues(self): 'project': 'DONUT', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) def test_get_due(self): issue = self.service.get_issue_for_record( diff --git a/tests/test_kanboard.py b/tests/test_kanboard.py index 3ef08b36..94b4ae5f 100644 --- a/tests/test_kanboard.py +++ b/tests/test_kanboard.py @@ -3,6 +3,7 @@ from dateutil.tz.tz import tzutc +from bugwarrior.collect import TaskConstructor from bugwarrior.services.kanboard import KanboardService from .base import AbstractServiceTest, ConfigTest, ServiceTest @@ -231,4 +232,4 @@ def test_issues(self): "priority": "M", # default priority } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_logseq.py b/tests/test_logseq.py index 96417732..dc10b6e3 100644 --- a/tests/test_logseq.py +++ b/tests/test_logseq.py @@ -1,8 +1,10 @@ from unittest import mock -from .base import AbstractServiceTest, ServiceTest +from bugwarrior.collect import TaskConstructor from bugwarrior.services.logseq import LogseqService, LogseqClient +from .base import AbstractServiceTest, ServiceTest + class TestLogseqIssue(AbstractServiceTest, ServiceTest): SERVICE_CONFIG = { @@ -97,4 +99,4 @@ def test_issues(self): issue.URI: "logseq://graph/Test?block-id=66699a83-3ee0-4edc-81c6-a24c9b80bec6", } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_pivotaltracker.py b/tests/test_pivotaltracker.py index d703ac5e..c0e7199c 100644 --- a/tests/test_pivotaltracker.py +++ b/tests/test_pivotaltracker.py @@ -3,6 +3,7 @@ from dateutil.tz import tzutc import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.pivotaltracker import PivotalTrackerService from .base import ServiceTest, AbstractServiceTest, ConfigTest @@ -354,4 +355,4 @@ def test_issues(self): 'project': 'death_star', 'tags': ['look_sir_metal'] } - self.assertEqual(story.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(story).get_taskwarrior_record(), expected) diff --git a/tests/test_redmine.py b/tests/test_redmine.py index 3dcbbd69..ad25e931 100644 --- a/tests/test_redmine.py +++ b/tests/test_redmine.py @@ -4,6 +4,7 @@ import dateutil import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.redmine import RedMineService from .base import ServiceTest, AbstractServiceTest @@ -126,4 +127,4 @@ def test_issues(self): 'redmineurl': 'https://something/issues/363901', 'tags': []} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_taiga.py b/tests/test_taiga.py index c8da6e7a..06e7be18 100644 --- a/tests/test_taiga.py +++ b/tests/test_taiga.py @@ -1,5 +1,6 @@ import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.taiga import TaigaService from .base import ServiceTest, AbstractServiceTest @@ -91,4 +92,4 @@ def test_issues(self): 'taigasummary': 'this is a title', 'taigaurl': 'https://one/project/something/us/40'} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_teamlab.py b/tests/test_teamlab.py index d694182c..b94c93a7 100644 --- a/tests/test_teamlab.py +++ b/tests/test_teamlab.py @@ -2,6 +2,7 @@ import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.teamlab import TeamLabService from .base import ServiceTest, AbstractServiceTest @@ -73,4 +74,4 @@ def test_issues(self): 'teamlaburl': 'http://something/products/projects/tasks.aspx?prjID=140&id=10'} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_teamwork_projects.py b/tests/test_teamwork_projects.py index 124533ec..cbdd0aa6 100644 --- a/tests/test_teamwork_projects.py +++ b/tests/test_teamwork_projects.py @@ -1,10 +1,12 @@ -from .base import ServiceTest, AbstractServiceTest -from bugwarrior.services.teamwork_projects import TeamworkService - import responses import datetime from dateutil.tz import tzutc +from bugwarrior.collect import TaskConstructor +from bugwarrior.services.teamwork_projects import TeamworkService + +from .base import ServiceTest, AbstractServiceTest + class TestTeamworkIssue(AbstractServiceTest, ServiceTest): SERVICE_CONFIG = { @@ -136,5 +138,5 @@ def test_issues(self): } issue.user_id = "5" issue.name = "Greg McCoy" - self.assertEqual(issue.get_taskwarrior_record(), expected_data) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected_data) self.assertEqual(issue.get_owner(), "Greg McCoy") diff --git a/tests/test_templates.py b/tests/test_templates.py index cb7cb165..ca088928 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -1,6 +1,7 @@ from .base import ServiceTest from .test_service import DumbIssue +from bugwarrior.collect import TaskConstructor from bugwarrior.config.schema import ServiceConfig, MainSectionConfig @@ -37,7 +38,7 @@ def get_issue( def test_default_taskwarrior_record(self): issue = self.get_issue({}) - record = issue.get_taskwarrior_record() + record = TaskConstructor(issue).get_taskwarrior_record() expected_record = self.arbitrary_issue.copy() expected_record.update({ 'description': self.arbitrary_default_description, @@ -53,7 +54,7 @@ def test_override_description(self): 'description': description_template }) - record = issue.get_taskwarrior_record() + record = TaskConstructor(issue).get_taskwarrior_record() expected_record = self.arbitrary_issue.copy() expected_record.update({ 'description': '%s - %s' % ( @@ -72,7 +73,7 @@ def test_override_project(self): 'project': project_template }) - record = issue.get_taskwarrior_record() + record = TaskConstructor(issue).get_taskwarrior_record() expected_record = self.arbitrary_issue.copy() expected_record.update({ 'description': self.arbitrary_default_description, @@ -85,7 +86,7 @@ def test_override_project(self): def test_tag_templates(self): issue = self.get_issue(add_tags=['one', '{{ project }}']) - record = issue.get_taskwarrior_record() + record = TaskConstructor(issue).get_taskwarrior_record() expected_record = self.arbitrary_issue.copy() expected_record.update({ 'description': self.arbitrary_default_description, diff --git a/tests/test_trac.py b/tests/test_trac.py index f8481e29..62abb062 100644 --- a/tests/test_trac.py +++ b/tests/test_trac.py @@ -1,3 +1,4 @@ +from bugwarrior.collect import TaskConstructor from bugwarrior.services.trac import TracService from .base import ServiceTest, AbstractServiceTest @@ -93,4 +94,4 @@ def test_issues(self): 'tracurl': 'https://ljlkajsdfl.com/ticket/1', 'traccomponent': 'testcomponent'} - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected) diff --git a/tests/test_trello.py b/tests/test_trello.py index 8cdd5879..5c1e3de7 100644 --- a/tests/test_trello.py +++ b/tests/test_trello.py @@ -1,8 +1,9 @@ from dateutil.parser import parse as parse_date import responses -from bugwarrior.services.trello import TrelloConfig, TrelloService, TrelloIssue +from bugwarrior.collect import TaskConstructor from bugwarrior.config.schema import MainSectionConfig +from bugwarrior.services.trello import TrelloConfig, TrelloService, TrelloIssue from .base import ConfigTest, ServiceTest @@ -215,7 +216,7 @@ def test_issues(self): "@luidgi - Preums", "@mario - Deuz"], 'tags': []} - actual = next(issues).get_taskwarrior_record() + actual = TaskConstructor(next(issues)).get_taskwarrior_record() self.assertEqual(expected, actual) maxDiff = None diff --git a/tests/test_youtrak.py b/tests/test_youtrak.py index 33c54e47..40a56902 100644 --- a/tests/test_youtrak.py +++ b/tests/test_youtrak.py @@ -1,5 +1,6 @@ import responses +from bugwarrior.collect import TaskConstructor from bugwarrior.services.youtrack import YoutrackService from .base import ConfigTest, ServiceTest, AbstractServiceTest @@ -101,4 +102,4 @@ def test_issues(self): 'youtracknumber': 1, } - self.assertEqual(issue.get_taskwarrior_record(), expected) + self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected)