Debian Codegraph @

tests/test_taiga.py

raw
1 from builtins import next
2 import responses
3
4 from bugwarrior.services.taiga import TaigaService
5
6 from .base import ServiceTest, AbstractServiceTest
7
8
9 class TestTaigaIssue(AbstractServiceTest, ServiceTest):
10 SERVICE_CONFIG = {
11 'taiga.base_uri': 'https://one',
12 'taiga.auth_token': 'two',
13 }
14 record = {
15 'id': 400,
16 'project': 4,
17 'ref': 40,
18 'subject': 'this is a title',
19 'tags': [
20 'single',
21 [
22 'bugwarrior',
23 None
24 ],
25 [
26 'task',
27 '#c0ffee'
28 ]
29 ],
30 }
31
32 def setUp(self):
33 super(TestTaigaIssue, self).setUp()
34 self.service = self.get_mock_service(TaigaService)
35
36 def test_to_taskwarrior(self):
37 extra = {
38 'project': 'awesome',
39 'annotations': [
40 # TODO - test annotations?
41 ],
42 'url': 'this is a url',
43 }
44
45 issue = self.service.get_issue_for_record(self.record, extra)
46 actual = issue.to_taskwarrior()
47 expected = {
48 'annotations': [],
49 'priority': 'M',
50 'project': 'awesome',
51 'tags': ['single', 'bugwarrior', 'task'],
52 'taigaid': 40,
53 'taigasummary': 'this is a title',
54 'taigaurl': 'this is a url',
55 }
56
57 self.assertEqual(actual, expected)
58
59 @responses.activate
60 def test_issues(self):
61 userid = 1
62
63 self.add_response(
64 'https://one/api/v1/users/me',
65 json={'id': userid})
66
67 self.add_response(
68 'https://one/api/v1/userstories?status__is_closed=false&assigned_to={0}'.format(
69 userid),
70 json=[self.record])
71
72 self.add_response(
73 'https://one/api/v1/projects/{0}'.format(self.record['project']),
74 json={'slug': 'something'})
75
76 self.add_response(
77 'https://one/api/v1/history/userstory/{0}'.format(
78 self.record['id']),
79 json=[{'user': {'username': 'you'}, 'comment': 'Blah blah blah!'}])
80
81 issue = next(self.service.issues())
82
83 expected = {
84 'annotations': [u'@you - Blah blah blah!'],
85 'description':
86 u'(bw)Is#40 - this is a title .. https://one/project/something/us/40',
87 'priority': u'M',
88 'project': u'something',
89 'tags': [u'single', u'bugwarrior', u'task'],
90 'taigaid': 40,
91 'taigasummary': u'this is a title',
92 'taigaurl': u'https://one/project/something/us/40'}
93
94 self.assertEqual(issue.get_taskwarrior_record(), expected)