Debian Codegraph @

tests/test_service.py

raw
1 import unittest
2
3 from bugwarrior import config, services
4
5 LONG_MESSAGE = """\
6 Some message that is over 100 characters. This message is so long it's
7 going to fill up your floppy disk taskwarrior backup. Actually it's not
8 that long.""".replace('\n', ' ')
9
10
11 class TestIssueService(unittest.TestCase):
12 def setUp(self):
13 super(TestIssueService, self).setUp()
14 self.config = config.BugwarriorConfigParser()
15 self.config.add_section('general')
16
17 def test_build_annotations_default(self):
18 service = services.IssueService(self.config, 'general', 'test')
19
20 annotations = service.build_annotations(
21 (('some_author', LONG_MESSAGE),), 'example.com')
22 self.assertEqual(annotations, [
23 u'@some_author - Some message that is over 100 characters. Thi...'
24 ])
25
26 def test_build_annotations_limited(self):
27 self.config.set('general', 'annotation_length', '20')
28 service = services.IssueService(self.config, 'general', 'test')
29
30 annotations = service.build_annotations(
31 (('some_author', LONG_MESSAGE),), 'example.com')
32 self.assertEqual(
33 annotations, [u'@some_author - Some message that is...'])
34
35 def test_build_annotations_limitless(self):
36 self.config.set('general', 'annotation_length', '')
37 service = services.IssueService(self.config, 'general', 'test')
38
39 annotations = service.build_annotations(
40 (('some_author', LONG_MESSAGE),), 'example.com')
41 self.assertEqual(annotations, [
42 u'@some_author - {message}'.format(message=LONG_MESSAGE)])
43
44
45 class TestIssue(unittest.TestCase):
46 def setUp(self):
47 super(TestIssue, self).setUp()
48 self.config = config.BugwarriorConfigParser()
49 self.config.add_section('general')
50
51 def makeIssue(self):
52 service = services.IssueService(self.config, 'general', 'test')
53 service.ISSUE_CLASS = services.Issue
54 return service.get_issue_for_record(None)
55
56 def test_build_default_description_default(self):
57 issue = self.makeIssue()
58
59 description = issue.build_default_description(LONG_MESSAGE)
60 self.assertEqual(
61 description, u'(bw)Is# - Some message that is over 100 chara')
62
63 def test_build_default_description_limited(self):
64 self.config.set('general', 'description_length', '20')
65 issue = self.makeIssue()
66
67 description = issue.build_default_description(LONG_MESSAGE)
68 self.assertEqual(
69 description, u'(bw)Is# - Some message that is')
70
71 def test_build_default_description_limitless(self):
72 self.config.set('general', 'description_length', '')
73 issue = self.makeIssue()
74
75 description = issue.build_default_description(LONG_MESSAGE)
76 self.assertEqual(
77 description, u'(bw)Is# - {message}'.format(message=LONG_MESSAGE))