| |
@@ -1,5 +1,6 @@
|
| |
import mock
|
| |
import unittest
|
| |
+ from nose.tools import eq_
|
| |
|
| |
import sync2jira.upstream as u
|
| |
|
| |
@@ -59,6 +60,112 @@
|
| |
'some_repo', issue_dict, self.config)
|
| |
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
+ @mock.patch('sync2jira.upstream._fetch_github_data')
|
| |
+ def test_handle_github_comment(self, _fetch_github_data, from_github):
|
| |
+ comment = {
|
| |
+ 'user': {'login': 'threebean'},
|
| |
+ 'body': 'This is fine.',
|
| |
+ }
|
| |
+ comments = [comment]
|
| |
+ issue_dict = {
|
| |
+ 'state': 'Open',
|
| |
+ 'title': 'title',
|
| |
+ 'url': 'some_issue_url',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'action': 'created',
|
| |
+ 'repository': {
|
| |
+ 'name': 'repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ 'comment': comment,
|
| |
+ },
|
| |
+ }
|
| |
+ githubResponse = mock.MagicMock()
|
| |
+ githubResponse.json.return_value = comments
|
| |
+ _fetch_github_data.return_value = githubResponse
|
| |
+ u.handle_github_comment(message, self.config)
|
| |
+
|
| |
+ from_github.assert_called_once_with(
|
| |
+ 'org/repo', issue_dict, self.config)
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
+ @mock.patch('sync2jira.upstream._fetch_github_data')
|
| |
+ def test_handle_github_change_comment(self, _fetch_github_data, from_github):
|
| |
+ comment = {
|
| |
+ 'user': {'login': 'threebean'},
|
| |
+ 'body': 'This is fine.',
|
| |
+ }
|
| |
+ comments = [
|
| |
+ comment,
|
| |
+ {
|
| |
+ 'user': {'login': 'threebean'},
|
| |
+ 'body': 'Some other text',
|
| |
+ }
|
| |
+ ]
|
| |
+ issue_dict = {
|
| |
+ 'state': 'Open',
|
| |
+ 'title': 'title',
|
| |
+ 'url': 'some_issue_url',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'action': 'edited',
|
| |
+ 'changes': {
|
| |
+ 'body': {
|
| |
+ 'from': 'Some text',
|
| |
+ },
|
| |
+ },
|
| |
+ 'repository': {
|
| |
+ 'name': 'repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ 'comment': comment,
|
| |
+ },
|
| |
+ }
|
| |
+ githubResponse = mock.MagicMock()
|
| |
+ githubResponse.json.return_value = comments
|
| |
+ _fetch_github_data.return_value = githubResponse
|
| |
+ u.handle_github_comment(message, self.config)
|
| |
+
|
| |
+ from_github.assert_called_once_with(
|
| |
+ 'org/repo', issue_dict, self.config)
|
| |
+
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
+ def test_handle_pagure_comment(self, from_pagure):
|
| |
+ issue_dict = {
|
| |
+ 'status': 'Open',
|
| |
+ 'title': 'title',
|
| |
+ 'id': 21,
|
| |
+ 'comments': [{
|
| |
+ 'user': {'name': 'Ralph'},
|
| |
+ 'comment': 'This is fine.',
|
| |
+ }],
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'project': {
|
| |
+ 'name': 'some_repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ },
|
| |
+ }
|
| |
+ u.handle_pagure_comment(message, self.config)
|
| |
+ from_pagure.assert_called_once_with(
|
| |
+ 'some_repo', issue_dict, self.config)
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
def test_handle_github_filter_positive(self, from_github):
|
| |
self.config['sync2jira']['filters'] = {
|
| |
'github': {
|
| |
@@ -172,8 +279,9 @@
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
def test_get_all_pagure_issues(self, from_pagure, requests):
|
| |
response = mock.MagicMock()
|
| |
+ mock_issue = {'comments_url': 'comment_url'}
|
| |
response.json.return_value = {
|
| |
- 'issues': ['some_issue_dict'],
|
| |
+ 'issues': [mock_issue],
|
| |
}
|
| |
requests.get.return_value = response
|
| |
|
| |
@@ -186,27 +294,30 @@
|
| |
params={'status': 'Open'},
|
| |
)
|
| |
from_pagure.assert_called_once_with(
|
| |
- 'some_repo', 'some_issue_dict', self.config)
|
| |
+ 'some_repo', mock_issue, self.config)
|
| |
|
| |
@mock.patch('sync2jira.upstream.requests')
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
def test_get_all_github_issues(self, from_github, requests):
|
| |
response = mock.MagicMock()
|
| |
- response.json.return_value = [
|
| |
- 'some_issue_dict',
|
| |
- ]
|
| |
+ mock_issue = {'comments_url': 'comment_url'}
|
| |
+ response.json.return_value = [mock_issue]
|
| |
requests.get.return_value = response
|
| |
|
| |
generator = u.github_issues('some_repo', self.config)
|
| |
# Step through that...
|
| |
list(generator)
|
| |
|
| |
- requests.get.assert_called_once_with(
|
| |
+ requests.get.assert_any_call(
|
| |
'https://api.github.com/repos/some_repo/issues?state=open',
|
| |
headers={},
|
| |
)
|
| |
+ requests.get.assert_any_call(
|
| |
+ 'comment_url',
|
| |
+ headers={},
|
| |
+ )
|
| |
from_github.assert_called_once_with(
|
| |
- 'some_repo', 'some_issue_dict', self.config)
|
| |
+ 'some_repo', mock_issue, self.config)
|
| |
|
| |
@mock.patch('sync2jira.upstream.requests')
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
@@ -219,8 +330,9 @@
|
| |
},
|
| |
}
|
| |
response = mock.MagicMock()
|
| |
+ mock_issue = {'comments_url': 'comment_url'}
|
| |
response.json.return_value = {
|
| |
- 'issues': ['some_issue_dict'],
|
| |
+ 'issues': [mock_issue],
|
| |
}
|
| |
requests.get.return_value = response
|
| |
|
| |
@@ -233,7 +345,7 @@
|
| |
params={'some_value': 'present'},
|
| |
)
|
| |
from_pagure.assert_called_once_with(
|
| |
- 'some_repo', 'some_issue_dict', self.config)
|
| |
+ 'some_repo', mock_issue, self.config)
|
| |
|
| |
@mock.patch('sync2jira.upstream.requests')
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
@@ -246,18 +358,21 @@
|
| |
},
|
| |
}
|
| |
response = mock.MagicMock()
|
| |
- response.json.return_value = [
|
| |
- 'some_issue_dict',
|
| |
- ]
|
| |
+ mock_issue = {'comments_url': 'comment_url'}
|
| |
+ response.json.return_value = [mock_issue]
|
| |
requests.get.return_value = response
|
| |
|
| |
generator = u.github_issues('some_repo', self.config)
|
| |
# Step through that...
|
| |
list(generator)
|
| |
|
| |
- requests.get.assert_called_once_with(
|
| |
+ requests.get.assert_any_call(
|
| |
'https://api.github.com/repos/some_repo/issues?some_value=present',
|
| |
headers={},
|
| |
)
|
| |
+ requests.get.assert_any_call(
|
| |
+ 'comment_url',
|
| |
+ headers={},
|
| |
+ )
|
| |
from_github.assert_called_once_with(
|
| |
- 'some_repo', 'some_issue_dict', self.config)
|
| |
+ 'some_repo', mock_issue, self.config)
|
| |