Beispiel #1
0
 def test_send(self, send_webhook):
     sender = RepoPushWebhookSender()
     sender.get_payload = Mock()
     with h.push_config(c, app=self.git):
         sender.send(dict(arg1=1, arg2=2))
     send_webhook.post.assert_called_once_with(
         self.wh._id, sender.get_payload.return_value)
Beispiel #2
0
 def test_get_payload(self):
     sender = RepoPushWebhookSender()
     _ci = lambda x: MagicMock(webhook_info={'id': str(x)},
                               parent_ids=['0'])
     with patch.object(self.git.repo, 'commit', new=_ci):
         with h.push_config(c, app=self.git):
             result = sender.get_payload(commit_ids=['1', '2', '3'],
                                         ref='ref')
     expected_result = {
         'size': 3,
         'commits': [{
             'id': '1'
         }, {
             'id': '2'
         }, {
             'id': '3'
         }],
         'ref': u'ref',
         'after': u'1',
         'before': u'0',
         'repository': {
             'full_name': u'/adobe/adobe-1/src/',
             'name': u'Git',
             'url': u'http://localhost/adobe/adobe-1/src/',
         },
     }
     assert_equal(result, expected_result)
Beispiel #3
0
 def test_send(self, send_webhook):
     sender = RepoPushWebhookSender()
     sender.get_payload = Mock()
     with h.push_config(c, app=self.git):
         sender.send(dict(arg1=1, arg2=2))
     send_webhook.post.assert_called_once_with(
         self.wh._id,
         sender.get_payload.return_value)
Beispiel #4
0
    def test_webhook_payload(self):
        user = M.User.upsert('cory')
        email = user.claim_address('*****@*****.**')
        email.confirmed = True
        session(email).flush(email)
        user = M.User.upsert('rick')
        email = user.claim_address('*****@*****.**')
        email.confirmed = True
        session(email).flush(email)

        sender = RepoPushWebhookSender()
        cids = list(self.repo.all_commit_ids())[:2]
        payload = sender.get_payload(commit_ids=cids, ref='refs/heads/zz')
        expected_payload = {
            'size': 2,
            'ref': 'refs/heads/zz',
            'after': '5c47243c8e424136fd5cdd18cd94d34c66d1955c',
            'before': 'df30427c488aeab84b2352bdf88a3b19223f9d7a',
            'commits': [{
                'id': '5c47243c8e424136fd5cdd18cd94d34c66d1955c',
                'url': 'http://localhost/p/test/src-git/ci/5c47243c8e424136fd5cdd18cd94d34c66d1955c/',
                'timestamp': datetime.datetime(2013, 3, 28, 18, 54, 16),
                'message': 'Not repo root',
                'author': {'name': 'Cory Johns',
                           'email': '*****@*****.**',
                           'username': '******'},
                'committer': {'name': 'Cory Johns',
                              'email': '*****@*****.**',
                              'username': '******'},
                'added': ['bad'],
                'removed': [],
                'modified': [],
                'copied': [],
                'renamed': [],
            }, {
                'id': '1e146e67985dcd71c74de79613719bef7bddca4a',
                'url': 'http://localhost/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/',
                'timestamp': datetime.datetime(2010, 10, 7, 18, 44, 11),
                'message': 'Change README',
                'author': {'name': 'Rick Copeland',
                           'email': '*****@*****.**',
                           'username': '******'},
                'committer': {'name': 'Rick Copeland',
                              'email': '*****@*****.**',
                              'username': '******'},
                'added': [],
                'removed': [],
                'modified': ['README'],
                'copied': [],
                'renamed': [],
            }],
            'repository': {
                'name': 'Git',
                'full_name': '/p/test/src-git/',
                'url': 'http://localhost/p/test/src-git/',
            },
        }
        assert_equals(payload, expected_payload)
Beispiel #5
0
    def test_webhook_payload(self):
        user = M.User.upsert('cory')
        email = user.claim_address('*****@*****.**')
        email.confirmed = True
        session(email).flush(email)
        user = M.User.upsert('rick')
        email = user.claim_address('*****@*****.**')
        email.confirmed = True
        session(email).flush(email)

        sender = RepoPushWebhookSender()
        cids = list(self.repo.all_commit_ids())[:2]
        payload = sender.get_payload(commit_ids=cids, ref='refs/heads/zz')
        expected_payload = {
            'size': 2,
            'ref': u'refs/heads/zz',
            'after': u'5c47243c8e424136fd5cdd18cd94d34c66d1955c',
            'before': u'df30427c488aeab84b2352bdf88a3b19223f9d7a',
            'commits': [{
                'id': u'5c47243c8e424136fd5cdd18cd94d34c66d1955c',
                'url': u'http://localhost/p/test/src-git/ci/5c47243c8e424136fd5cdd18cd94d34c66d1955c/',
                'timestamp': datetime.datetime(2013, 3, 28, 18, 54, 16),
                'message': u'Not repo root',
                'author': {'name': u'Cory Johns',
                           'email': u'*****@*****.**',
                           'username': '******'},
                'committer': {'name': u'Cory Johns',
                              'email': u'*****@*****.**',
                              'username': '******'},
                'added': [u'bad'],
                'removed': [],
                'modified': [],
                'copied': [],
                'renamed': [],
            }, {
                'id': u'1e146e67985dcd71c74de79613719bef7bddca4a',
                'url': u'http://localhost/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/',
                'timestamp': datetime.datetime(2010, 10, 7, 18, 44, 11),
                'message': u'Change README',
                'author': {'name': u'Rick Copeland',
                           'email': u'*****@*****.**',
                           'username': '******'},
                'committer': {'name': u'Rick Copeland',
                              'email': u'*****@*****.**',
                              'username': '******'},
                'added': [],
                'removed': [],
                'modified': [u'README'],
                'copied': [],
                'renamed': [],
            }],
            'repository': {
                'name': u'Git',
                'full_name': u'/p/test/src-git/',
                'url': u'http://localhost/p/test/src-git/',
            },
        }
        assert_equals(payload, expected_payload)
Beispiel #6
0
 def test_send_limit_reached(self, send_webhook, log):
     sender = RepoPushWebhookSender()
     sender.get_payload = Mock()
     self.wh.enforce_limit = Mock(return_value=False)
     with h.push_config(c, app=self.git):
         sender.send(dict(arg1=1, arg2=2))
     assert_equal(send_webhook.post.call_count, 0)
     log.warn.assert_called_once_with(
         'Webhook fires too often: %s. Skipping', self.wh)
Beispiel #7
0
 def test_send_limit_reached(self, send_webhook, log):
     sender = RepoPushWebhookSender()
     sender.get_payload = Mock()
     self.wh.enforce_limit = Mock(return_value=False)
     with h.push_config(c, app=self.git):
         sender.send(dict(arg1=1, arg2=2))
     assert_equal(send_webhook.post.call_count, 0)
     log.warn.assert_called_once_with(
         'Webhook fires too often: %s. Skipping', self.wh)
Beispiel #8
0
 def test_send_with_list(self, send_webhook):
     sender = RepoPushWebhookSender()
     sender.get_payload = Mock(side_effect=[1, 2])
     self.wh.enforce_limit = Mock(return_value=True)
     with h.push_config(c, app=self.git):
         sender.send([dict(arg1=1, arg2=2), dict(arg1=3, arg2=4)])
     assert_equal(send_webhook.post.call_count, 2)
     assert_equal(send_webhook.post.call_args_list,
                  [call(self.wh._id, 1), call(self.wh._id, 2)])
     assert_equal(self.wh.enforce_limit.call_count, 1)
Beispiel #9
0
 def test_webhook_payload(self):
     sender = RepoPushWebhookSender()
     cids = list(self.repo.all_commit_ids())[:2]
     payload = sender.get_payload(commit_ids=cids)
     expected_payload = {
         'size': 2,
         'after': 'r6',
         'before': 'r4',
         'commits': [{
             'id': u'r6',
             'url': u'http://localhost/p/test/src/6/',
             'timestamp': datetime(2013, 11, 8, 13, 38, 11, 152000),
             'message': u'',
             'author': {'name': u'coldmind',
                        'email': u'',
                        'username': u''},
             'committer': {'name': u'coldmind',
                           'email': u'',
                           'username': u''},
             'added': [u'/ЗРЯЧИЙ_ТА_ПОБАЧИТЬ'],
             'removed': [],
             'modified': [],
             'copied': [],
             'renamed': [],
         }, {
             'id': u'r5',
             'url': u'http://localhost/p/test/src/5/',
             'timestamp': datetime(2010, 11, 18, 20, 14, 21, 515000),
             'message': u'Copied a => b',
             'author': {'name': u'rick446',
                        'email': u'',
                        'username': u''},
             'committer': {'name': u'rick446',
                           'email': u'',
                           'username': u''},
             'added': [],
             'removed': [],
             'modified': [],
             'copied': [
                 {'new': u'/b', 'old': u'/a', 'ratio': 1},
             ],
             'renamed': [],
         }],
         'repository': {
             'name': u'SVN',
             'full_name': u'/p/test/src/',
             'url': u'http://localhost/p/test/src/',
         },
     }
     assert_equals(payload, expected_payload)
Beispiel #10
0
 def test_webhook_payload(self):
     sender = RepoPushWebhookSender()
     cids = list(self.repo.all_commit_ids())[:2]
     payload = sender.get_payload(commit_ids=cids)
     expected_payload = {
         'size': 2,
         'after': 'r6',
         'before': 'r4',
         'commits': [{
             'id': u'r6',
             'url': u'http://localhost/p/test/src/6/',
             'timestamp': datetime(2013, 11, 8, 13, 38, 11, 152000),
             'message': u'',
             'author': {'name': u'coldmind',
                        'email': u'',
                        'username': u''},
             'committer': {'name': u'coldmind',
                           'email': u'',
                           'username': u''},
             'added': [u'/ЗРЯЧИЙ_ТА_ПОБАЧИТЬ'],
             'removed': [],
             'modified': [],
             'copied': [],
             'renamed': [],
         }, {
             'id': u'r5',
             'url': u'http://localhost/p/test/src/5/',
             'timestamp': datetime(2010, 11, 18, 20, 14, 21, 515000),
             'message': u'Copied a => b',
             'author': {'name': u'rick446',
                        'email': u'',
                        'username': u''},
             'committer': {'name': u'rick446',
                           'email': u'',
                           'username': u''},
             'added': [],
             'removed': [],
             'modified': [],
             'copied': [
                 {'new': u'/b', 'old': u'/a', 'ratio': 1},
             ],
             'renamed': [],
         }],
         'repository': {
             'name': u'SVN',
             'full_name': u'/p/test/src/',
             'url': u'http://localhost/p/test/src/',
         },
     }
     assert_equals(payload, expected_payload)
Beispiel #11
0
 def test_get_payload(self):
     sender = RepoPushWebhookSender()
     _ci = lambda x: MagicMock(webhook_info={'id': str(x)}, parent_ids=['0'])
     with patch.object(self.git.repo, 'commit', new=_ci):
         with h.push_config(c, app=self.git):
             result = sender.get_payload(commit_ids=['1', '2', '3'], ref='ref')
     expected_result = {
         'size': 3,
         'commits': [{'id': '1'}, {'id': '2'}, {'id': '3'}],
         'ref': u'ref',
         'after': u'1',
         'before': u'0',
         'repository': {
             'full_name': u'/adobe/adobe-1/src/',
             'name': u'Git',
             'url': u'http://localhost/adobe/adobe-1/src/',
         },
     }
     assert_equal(result, expected_result)