| 1 |
from builtins import next |
| 2 |
from six.moves import configparser |
| 3 |
import responses |
| 4 |
|
| 5 |
from bugwarrior.services import ServiceConfig |
| 6 |
from bugwarrior.services.youtrack import YoutrackService |
| 7 |
|
| 8 |
from .base import ConfigTest, ServiceTest, AbstractServiceTest |
| 9 |
|
| 10 |
|
| 11 |
class TestYoutrackService(ConfigTest): |
| 12 |
def setUp(self): |
| 13 |
super(TestYoutrackService, self).setUp() |
| 14 |
self.config = configparser.RawConfigParser() |
| 15 |
self.config.add_section('general') |
| 16 |
self.config.add_section('myservice') |
| 17 |
self.config.set('myservice', 'youtrack.login', 'foobar') |
| 18 |
self.config.set('myservice', 'youtrack.password', 'XXXXXX') |
| 19 |
def test_get_keyring_service(self): |
| 20 |
self.config.set('myservice', 'youtrack.host', 'youtrack.example.com') |
| 21 |
service_config = ServiceConfig( |
| 22 |
YoutrackService.CONFIG_PREFIX, self.config, 'myservice') |
| 23 |
self.assertEqual( |
| 24 |
YoutrackService.get_keyring_service(service_config), |
| 25 |
'youtrack://[email protected]') |
| 26 |
|
| 27 |
|
| 28 |
class TestYoutrackIssue(AbstractServiceTest, ServiceTest): |
| 29 |
maxDiff = None |
| 30 |
SERVICE_CONFIG = { |
| 31 |
'youtrack.host': 'youtrack.example.com', |
| 32 |
'youtrack.login': 'arbitrary_login', |
| 33 |
'youtrack.password': 'arbitrary_password', |
| 34 |
'youtrack.anonymous': True, |
| 35 |
} |
| 36 |
arbitrary_issue = { |
| 37 |
"id": "TEST-1", |
| 38 |
"field": [ |
| 39 |
{ |
| 40 |
"name": "projectShortName", |
| 41 |
"value": "TEST" |
| 42 |
}, |
| 43 |
{ |
| 44 |
"name": "numberInProject", |
| 45 |
"value": "1" |
| 46 |
}, |
| 47 |
{ |
| 48 |
"name": "summary", |
| 49 |
"value": "Hello World" |
| 50 |
}, |
| 51 |
], |
| 52 |
"tag": [ |
| 53 |
{ |
| 54 |
"value": "bug", |
| 55 |
}, |
| 56 |
{ |
| 57 |
"value": "New Feature", |
| 58 |
} |
| 59 |
] |
| 60 |
} |
| 61 |
arbitrary_extra = { |
| 62 |
} |
| 63 |
|
| 64 |
def setUp(self): |
| 65 |
super(TestYoutrackIssue, self).setUp() |
| 66 |
self.service = self.get_mock_service(YoutrackService) |
| 67 |
|
| 68 |
def test_to_taskwarrior(self): |
| 69 |
self.service.import_tags = True |
| 70 |
issue = self.service.get_issue_for_record(self.arbitrary_issue, self.arbitrary_extra) |
| 71 |
|
| 72 |
expected_output = { |
| 73 |
'project': 'TEST', |
| 74 |
'priority': self.service.default_priority, |
| 75 |
'tags': [u'bug', u'new_feature'], |
| 76 |
issue.ISSUE: 'TEST-1', |
| 77 |
issue.SUMMARY: 'Hello World', |
| 78 |
issue.URL: 'https://youtrack.example.com:443/issue/TEST-1', |
| 79 |
issue.PROJECT: 'TEST', |
| 80 |
issue.NUMBER: 1, |
| 81 |
} |
| 82 |
actual_output = issue.to_taskwarrior() |
| 83 |
|
| 84 |
self.assertEqual(actual_output, expected_output) |
| 85 |
|
| 86 |
@responses.activate |
| 87 |
def test_issues(self): |
| 88 |
self.add_response( |
| 89 |
'https://youtrack.example.com:443/rest/issue?filter=for%3Ame+%23Unresolved&max=100', |
| 90 |
json={'issue': [self.arbitrary_issue]}) |
| 91 |
|
| 92 |
issue = next(self.service.issues()) |
| 93 |
|
| 94 |
expected = { |
| 95 |
'description': |
| 96 |
u'(bw)Is#TEST-1 - Hello World .. https://youtrack.example.com:443/issue/TEST-1', |
| 97 |
'project': 'TEST', |
| 98 |
'priority': self.service.default_priority, |
| 99 |
'tags': [u'bug', u'new_feature'], |
| 100 |
'youtrackissue': 'TEST-1', |
| 101 |
'youtracksummary': 'Hello World', |
| 102 |
'youtrackurl': 'https://youtrack.example.com:443/issue/TEST-1', |
| 103 |
'youtrackproject': 'TEST', |
| 104 |
'youtracknumber': 1, |
| 105 |
} |
| 106 |
|
| 107 |
self.assertEqual(issue.get_taskwarrior_record(), expected) |