Skip to content

Commit

Permalink
Test annotation and description builders.
Browse files Browse the repository at this point in the history
Also fix an errant ValueError thrown since `u'' is not ''` but `u'' ==
''`.
  • Loading branch information
ryneeverett committed Feb 26, 2017
1 parent 834d568 commit c822ec1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bugwarrior/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def getint(self, section, option):
try:
return super(BugwarriorConfigParser, self).getint(section, option)
except ValueError:
if self.get(section, option) is u'':
if self.get(section, option) == u'':
return None
else:
raise ValueError(
Expand Down
77 changes: 77 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import unittest

from bugwarrior import config, services

LONG_MESSAGE = """\
Some message that is over 100 characters. This message is so long it's
going to fill up your floppy disk taskwarrior backup. Actually it's not
that long.""".replace('\n', ' ')


class TestIssueService(unittest.TestCase):
def setUp(self):
super(TestIssueService, self).setUp()
self.config = config.BugwarriorConfigParser()
self.config.add_section('general')

def test_build_annotations_default(self):
service = services.IssueService(self.config, 'general', 'test')

annotations = service.build_annotations(
(('some_author', LONG_MESSAGE),), 'example.com')
self.assertEqual(annotations, [
u'@some_author - Some message that is over 100 characters. Thi...'
])

def test_build_annotations_limited(self):
self.config.set('general', 'annotation_length', '20')
service = services.IssueService(self.config, 'general', 'test')

annotations = service.build_annotations(
(('some_author', LONG_MESSAGE),), 'example.com')
self.assertEqual(
annotations, [u'@some_author - Some message that is...'])

def test_build_annotations_limitless(self):
self.config.set('general', 'annotation_length', '')
service = services.IssueService(self.config, 'general', 'test')

annotations = service.build_annotations(
(('some_author', LONG_MESSAGE),), 'example.com')
self.assertEqual(annotations, [
u'@some_author - {message}'.format(message=LONG_MESSAGE)])


class TestIssue(unittest.TestCase):
def setUp(self):
super(TestIssue, self).setUp()
self.config = config.BugwarriorConfigParser()
self.config.add_section('general')

def makeIssue(self):
service = services.IssueService(self.config, 'general', 'test')
service.ISSUE_CLASS = services.Issue
return service.get_issue_for_record(None)

def test_build_default_description_default(self):
issue = self.makeIssue()

description = issue.build_default_description(LONG_MESSAGE)
self.assertEqual(
description, u'(bw)Is# - Some message that is over 100 chara')

def test_build_default_description_limited(self):
self.config.set('general', 'description_length', '20')
issue = self.makeIssue()

description = issue.build_default_description(LONG_MESSAGE)
self.assertEqual(
description, u'(bw)Is# - Some message that is')

def test_build_default_description_limitless(self):
self.config.set('general', 'description_length', '')
issue = self.makeIssue()

description = issue.build_default_description(LONG_MESSAGE)
self.assertEqual(
description, u'(bw)Is# - {message}'.format(message=LONG_MESSAGE))

0 comments on commit c822ec1

Please sign in to comment.