def test_poll_pull_request_filter_True(self): yield self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', pullrequest_filter=lambda x: True )) # patch client.getPage() self.patch(client, "getPage", self.pr_list.getPage) yield self.changesource.poll() self.assertEqual(self.master.data.updates.changesAdded, [{ 'author': 'contributor', 'committer': None, 'branch': 'default', 'category': None, 'codebase': None, 'comments': 'pull-request #1: title\nhttps://bitbucket.org/owner/slug/pull-request/1', 'files': None, 'project': '', 'properties': {'pullrequesturl': 'https://bitbucket.org/owner/slug/pull-request/1'}, 'repository': 'https://bitbucket.org/contributor/slug', 'revision': '1111111111111111111111111111111111111111', 'revlink': 'https://bitbucket.org/contributor/slug/commits/111111111111', 'src': 'bitbucket', 'when_timestamp': 1381869500, }])
def test_poll_pull_request_not_useTimestamps(self): yield self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', useTimestamps=False, )) # patch client.getPage() self.patch(client, "getPage", self.pr_list.getPage) self.patch(reactor, "seconds", lambda: 1396825656) yield self.changesource.poll() self.assertEqual(self.master.data.updates.changesAdded, [{ 'author': u'contributor', 'branch': u'default', 'category': None, 'codebase': None, 'comments': u'pull-request #1: title\nhttps://bitbucket.org/owner/slug/pull-request/1', 'files': None, 'project': u'', 'properties': {}, 'repository': u'https://bitbucket.org/contributor/slug', 'revision': u'1111111111111111111111111111111111111111', 'revlink': u'https://bitbucket.org/contributor/slug/commits/111111111111', 'src': u'bitbucket', 'when_timestamp': 1396825656, }])
def test_poll_pull_request_filter_False(self): yield self.attachChangeSource( BitbucketPullrequestPoller(owner='owner', slug='slug', pullrequest_filter=lambda x: False)) # patch client.getPage() self.patch(client, "getPage", self.pr_list.getPage) yield self.changesource.poll() self.assertEqual(len(self.master.data.updates.changesAdded), 0)
def test_poll_authorized_success(self): auth = ('user', '1234') expected_headers = {b'Authorization': b'Basic dXNlcjoxMjM0'} yield self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', auth=auth, )) # Polling with authorization should success self._fakeGetPage403(expected_headers) try: yield self.changesource.poll() except Exception as e: self.assertNotEqual(str(e), '403 Forbidden')
def test_poll_pull_request_properties(self): yield self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', bitbucket_property_whitelist=["bitbucket.*"], )) self.patch(client, "getPage", self.pr_list.getPage) yield self.changesource.poll() self.assertEqual(self.master.data.updates.changesAdded, [{ 'author': 'contributor', 'committer': None, 'branch': 'default', 'category': None, 'codebase': None, 'comments': 'pull-request #1: title\nhttps://bitbucket.org/owner/slug/pull-request/1', 'files': None, 'project': '', 'properties': { 'pullrequesturl': 'https://bitbucket.org/owner/slug/pull-request/1', 'bitbucket.author.display_name': 'contributor', 'bitbucket.created_on': '2013-10-15T20:38:20.001797+00:00', 'bitbucket.description': 'description', 'bitbucket.id': 1, 'bitbucket.links.html.href': 'https://bitbucket.org/owner/slug/pull-request/1', 'bitbucket.links.self.href': 'https://bitbucket.org/!api/2.0/' 'repositories/owner/slug/pullrequests/1', 'bitbucket.merge_commit': None, 'bitbucket.source.branch.name': 'default', 'bitbucket.source.commit.hash': '111111111111', 'bitbucket.source.commit.links.self.href': 'https://bitbucket.org/!api/2.0/' 'repositories/contributor/slug/' 'commit/111111111111', 'bitbucket.source.repository.links.self.href': 'https://bitbucket.org/!api/2.0/' 'repositories/contributor/slug', 'bitbucket.state': 'OPEN', 'bitbucket.title': 'title', 'bitbucket.updated_on': '2013-10-15T20:38:20.001797+00:00' }, 'repository': 'https://bitbucket.org/contributor/slug', 'revision': '1111111111111111111111111111111111111111', 'revlink': 'https://bitbucket.org/contributor/slug/commits/111111111111', 'src': 'bitbucket', 'when_timestamp': 1381869500, }])
def test_poll_pull_request_filter_False(self): self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', pullrequest_filter=lambda x: False )) # patch client.getPage() self.patch(client, "getPage", self.pr_list.getPage) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 0) d.addCallback(check) return d
def test_poll_pull_request_not_useTimestamps(self): self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', useTimestamps=False, )) # patch client.getPage() self.patch(client, "getPage", self.pr_list.getPage) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 1) self.assertEqual(self.changes_added[0]['author'], "contributor") self.assertEqual(int(self.changes_added[0]['revision']), 1) self.assertNotEqual(self.changes_added[0]['when_timestamp'], self.date_epoch) d.addCallback(check) return d
def attachDefaultChangeSource(self): return self.attachChangeSource( BitbucketPullrequestPoller(owner='owner', slug='slug'))
def create_poller(_): self.attachChangeSource(BitbucketPullrequestPoller( owner='owner', slug='slug', ))