You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/02/24 12:48:21 UTC
[27/50] [abbrv] allura git commit: [#4542] ticket:728 Fix tests
[#4542] ticket:728 Fix tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/a433fa97
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a433fa97
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a433fa97
Branch: refs/heads/ib/7827
Commit: a433fa9778b8aaea2efada1f8df23f20291f09cf
Parents: fea9a04
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Feb 13 17:35:24 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Feb 16 10:17:42 2015 +0000
----------------------------------------------------------------------
Allura/allura/tests/test_webhooks.py | 20 +++++++++++---------
.../forgegit/tests/model/test_repository.py | 16 ++++++----------
.../forgesvn/tests/model/test_repository.py | 17 ++++++-----------
3 files changed, 23 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/a433fa97/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index 3d51f5c..629b322 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -3,7 +3,7 @@ import hmac
import hashlib
import datetime as dt
-from mock import Mock, patch, call
+from mock import Mock, MagicMock, patch, call
from nose.tools import (
assert_raises,
assert_equal,
@@ -480,7 +480,7 @@ class TestRepoPushWebhookSender(TestWebhookBase):
sender = RepoPushWebhookSender()
sender.get_payload = Mock()
with h.push_config(c, app=self.git):
- sender.send(arg1=1, arg2=2)
+ sender.send(dict(arg1=1, arg2=2))
send_webhook.post.assert_called_once_with(
self.wh._id,
sender.get_payload.return_value)
@@ -492,7 +492,7 @@ class TestRepoPushWebhookSender(TestWebhookBase):
sender.get_payload = Mock()
self.wh.enforce_limit = Mock(return_value=False)
with h.push_config(c, app=self.git):
- sender.send(arg1=1, arg2=2)
+ 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)
@@ -503,19 +503,21 @@ class TestRepoPushWebhookSender(TestWebhookBase):
session(self.wh).flush(self.wh)
sender = RepoPushWebhookSender()
with h.push_config(c, app=self.git):
- sender.send(arg1=1, arg2=2)
+ sender.send(dict(arg1=1, arg2=2))
assert_equal(send_webhook.post.call_count, 0)
def test_get_payload(self):
sender = RepoPushWebhookSender()
- _ci = list(range(1, 4))
- _se = [Mock(webhook_info=str(x)) for x in _ci]
- with patch.object(self.git.repo, 'commit', autospec=True, side_effect=_se):
+ _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=_ci)
+ result = sender.get_payload(commit_ids=['1', '2', '3'], ref='ref')
expected_result = {
'size': 3,
- 'commits': ['1', '2', '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',
http://git-wip-us.apache.org/repos/asf/allura/blob/a433fa97/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index b67a7ae..231e479 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -31,6 +31,7 @@ from ming.base import Object
from ming.orm import ThreadLocalORMSession, session
from nose.tools import assert_equal
from testfixtures import TempDirectory
+from datadiff.tools import assert_equals
from alluratest.controller import setup_basic_test, setup_global_objects
from allura.lib import helpers as h
@@ -546,9 +547,12 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
sender = RepoPushWebhookSender()
cids = list(self.repo.all_commit_ids())[:2]
- payload = sender.get_payload(commit_ids=cids)
+ 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/',
@@ -586,15 +590,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'url': u'http://localhost/p/test/src-git/',
},
}
-
- def _diff(one, two):
- from difflib import Differ
- from pprint import pformat
- one, two = pformat(one), pformat(two)
- diff = Differ().compare(one.splitlines(), two.splitlines())
- print '\n'.join(diff)
-
- assert payload == expected_payload, _diff(expected_payload, payload)
+ assert_equals(payload, expected_payload)
class TestGitImplementation(unittest.TestCase):
http://git-wip-us.apache.org/repos/asf/allura/blob/a433fa97/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 030931a..eb952e1 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -28,6 +28,7 @@ from collections import defaultdict
from pylons import tmpl_context as c, app_globals as g
import mock
from nose.tools import assert_equal
+from datadiff.tools import assert_equals
import tg
import ming
from ming.base import Object
@@ -584,8 +585,10 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
payload = sender.get_payload(commit_ids=cids)
expected_payload = {
'size': 2,
+ 'after': 'r6',
+ 'before': 'r4',
'commits': [{
- 'id': u'{}:6'.format(self.repo._id),
+ 'id': u'r6',
'url': u'http://localhost/p/test/src/6/',
'timestamp': datetime(2013, 11, 8, 13, 38, 11, 152000),
'message': u'',
@@ -600,7 +603,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
'modified': [],
'copied': []
}, {
- 'id': u'{}:5'.format(self.repo._id),
+ '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',
@@ -621,15 +624,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
'url': u'http://localhost/p/test/src/',
},
}
-
- def _diff(one, two):
- from difflib import Differ
- from pprint import pformat
- one, two = pformat(one), pformat(two)
- diff = Differ().compare(one.splitlines(), two.splitlines())
- print '\n'.join(diff)
-
- assert payload == expected_payload, _diff(expected_payload, payload)
+ assert_equals(payload, expected_payload)
class TestSVNRev(unittest.TestCase):