| |
@@ -5,24 +5,26 @@
|
| |
|
| |
|
| |
class TestUpstream(unittest.TestCase):
|
| |
- config = {
|
| |
- 'sync2jira': {
|
| |
- 'map': {
|
| |
- 'github': {
|
| |
- 'org/repo': {},
|
| |
+ def setUp(self):
|
| |
+ self.config = {
|
| |
+ 'sync2jira': {
|
| |
+ 'map': {
|
| |
+ 'github': {
|
| |
+ 'org/repo': {},
|
| |
+ },
|
| |
+ 'pagure': {
|
| |
+ 'some_repo': {},
|
| |
+ },
|
| |
},
|
| |
- 'pagure': {
|
| |
- 'some_repo': {},
|
| |
+ 'jira': {
|
| |
+ # Nothing, really..
|
| |
},
|
| |
},
|
| |
- 'jira': {
|
| |
- # Nothing, really..
|
| |
- },
|
| |
- },
|
| |
- }
|
| |
+ }
|
| |
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
def test_handle_github_message(self, from_github):
|
| |
+ issue_dict = {'state': 'open'}
|
| |
message = {
|
| |
'msg': {
|
| |
'repository': {
|
| |
@@ -31,15 +33,16 @@
|
| |
'login': 'org',
|
| |
},
|
| |
},
|
| |
- 'issue': 'some_issue_dict',
|
| |
+ 'issue': issue_dict,
|
| |
},
|
| |
}
|
| |
u.handle_github_message(message, self.config)
|
| |
from_github.assert_called_once_with(
|
| |
- 'org/repo', 'some_issue_dict', self.config)
|
| |
+ 'org/repo', issue_dict, self.config)
|
| |
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
def test_handle_pagure_message(self, from_pagure):
|
| |
+ issue_dict = {'status': 'Open'}
|
| |
message = {
|
| |
'msg': {
|
| |
'project': {
|
| |
@@ -48,12 +51,122 @@
|
| |
'login': 'org',
|
| |
},
|
| |
},
|
| |
- 'issue': 'some_issue_dict',
|
| |
+ 'issue': issue_dict,
|
| |
},
|
| |
}
|
| |
u.handle_pagure_message(message, self.config)
|
| |
from_pagure.assert_called_once_with(
|
| |
- 'some_repo', 'some_issue_dict', self.config)
|
| |
+ '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': {
|
| |
+ 'org/repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ issue_dict = {
|
| |
+ 'state': 'open',
|
| |
+ 'some_value': 'present',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'repository': {
|
| |
+ 'name': 'repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ },
|
| |
+ }
|
| |
+ u.handle_github_message(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_filter_positive(self, from_pagure):
|
| |
+ self.config['sync2jira']['filters'] = {
|
| |
+ 'pagure': {
|
| |
+ 'some_repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ issue_dict = {
|
| |
+ 'status': 'Open',
|
| |
+ 'some_value': 'present',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'project': {
|
| |
+ 'name': 'some_repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ },
|
| |
+ }
|
| |
+ u.handle_pagure_message(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_negative(self, from_github):
|
| |
+ self.config['sync2jira']['filters'] = {
|
| |
+ 'github': {
|
| |
+ 'org/repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ issue_dict = {
|
| |
+ 'state': 'open',
|
| |
+ 'some_value': 'absent',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'repository': {
|
| |
+ 'name': 'repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ },
|
| |
+ }
|
| |
+ u.handle_github_message(message, self.config)
|
| |
+ assert not from_github.called, 'should not have been called'
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
+ def test_handle_pagure_filter_negative(self, from_pagure):
|
| |
+ self.config['sync2jira']['filters'] = {
|
| |
+ 'pagure': {
|
| |
+ 'some_repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ issue_dict = {
|
| |
+ 'status': 'Open',
|
| |
+ 'some_value': 'absent',
|
| |
+ }
|
| |
+ message = {
|
| |
+ 'msg': {
|
| |
+ 'project': {
|
| |
+ 'name': 'some_repo',
|
| |
+ 'owner': {
|
| |
+ 'login': 'org',
|
| |
+ },
|
| |
+ },
|
| |
+ 'issue': issue_dict,
|
| |
+ },
|
| |
+ }
|
| |
+ u.handle_pagure_message(message, self.config)
|
| |
+ assert not from_pagure.called, 'should not have been called'
|
| |
|
| |
@mock.patch('sync2jira.upstream.requests')
|
| |
@mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
@@ -89,9 +202,62 @@
|
| |
list(generator)
|
| |
|
| |
requests.get.assert_called_once_with(
|
| |
- 'https://api.github.com/repos/some_repo/issues',
|
| |
+ 'https://api.github.com/repos/some_repo/issues?state=open',
|
| |
+ headers={},
|
| |
+ )
|
| |
+ from_github.assert_called_once_with(
|
| |
+ 'some_repo', 'some_issue_dict', self.config)
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.requests')
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_pagure')
|
| |
+ def test_get_filtered_pagure_issues(self, from_pagure, requests):
|
| |
+ self.config['sync2jira']['filters'] = {
|
| |
+ 'pagure': {
|
| |
+ 'some_repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ response = mock.MagicMock()
|
| |
+ response.json.return_value = {
|
| |
+ 'issues': ['some_issue_dict'],
|
| |
+ }
|
| |
+ requests.get.return_value = response
|
| |
+
|
| |
+ generator = u.pagure_issues('some_repo', self.config)
|
| |
+ # Step through that...
|
| |
+ list(generator)
|
| |
+
|
| |
+ requests.get.assert_called_once_with(
|
| |
+ 'https://pagure.io/api/0/some_repo/issues',
|
| |
+ params={'some_value': 'present'},
|
| |
+ )
|
| |
+ from_pagure.assert_called_once_with(
|
| |
+ 'some_repo', 'some_issue_dict', self.config)
|
| |
+
|
| |
+ @mock.patch('sync2jira.upstream.requests')
|
| |
+ @mock.patch('sync2jira.upstream.i.Issue.from_github')
|
| |
+ def test_get_filtered_github_issues(self, from_github, requests):
|
| |
+ self.config['sync2jira']['filters'] = {
|
| |
+ 'github': {
|
| |
+ 'some_repo': {
|
| |
+ 'some_value': 'present',
|
| |
+ },
|
| |
+ },
|
| |
+ }
|
| |
+ response = mock.MagicMock()
|
| |
+ response.json.return_value = [
|
| |
+ 'some_issue_dict',
|
| |
+ ]
|
| |
+ requests.get.return_value = response
|
| |
+
|
| |
+ generator = u.github_issues('some_repo', self.config)
|
| |
+ # Step through that...
|
| |
+ list(generator)
|
| |
+
|
| |
+ requests.get.assert_called_once_with(
|
| |
+ 'https://api.github.com/repos/some_repo/issues?some_value=present',
|
| |
headers={},
|
| |
- params={'per_page': 100, 'state': 'open'},
|
| |
)
|
| |
from_github.assert_called_once_with(
|
| |
'some_repo', 'some_issue_dict', self.config)
|
| |
This allows us to sync only special kinds of tickets from the bodhi
queue to the FACTORY project.
Additionally, I added pagination to our github scraping here which
previously only grabbed the latest 100 tickets.
Fixes #16.