Index: dashboard/dashboard/pinpoint/models/change/patch_test.py |
diff --git a/dashboard/dashboard/pinpoint/models/change/patch_test.py b/dashboard/dashboard/pinpoint/models/change/patch_test.py |
index c18e0c771aca427893cc54028e21aa8c7b80627c..034bb3ea92d37ff5b3727275a4af5a57153badfe 100644 |
--- a/dashboard/dashboard/pinpoint/models/change/patch_test.py |
+++ b/dashboard/dashboard/pinpoint/models/change/patch_test.py |
@@ -4,36 +4,108 @@ |
import unittest |
+import mock |
+ |
from dashboard.pinpoint.models.change import patch |
-class PatchTest(unittest.TestCase): |
+_GERRIT_CHANGE_INFO = { |
+ 'id': 'repo~branch~id', |
+ 'project': 'chromium/src', |
+ '_number': 658277, |
+ 'current_revision': 'current revision', |
+ 'revisions': { |
+ 'current revision': { |
+ '_number': 5, |
+ 'fetch': { |
+ 'http': { |
+ 'url': 'https://googlesource.com/chromium/src', |
+ 'ref': 'refs/changes/77/658277/5', |
+ }, |
+ }, |
+ }, |
+ 'other revision': { |
+ '_number': 4, |
+ 'fetch': { |
+ 'http': { |
+ 'url': 'https://googlesource.com/chromium/src', |
+ 'ref': 'refs/changes/77/658277/4', |
+ }, |
+ }, |
+ }, |
+ }, |
+} |
+ |
+ |
+class FromDictTest(unittest.TestCase): |
+ |
+ @mock.patch('dashboard.services.gerrit_service.GetChange') |
+ def testFromDictGerrit(self, get_change): |
+ get_change.return_value = _GERRIT_CHANGE_INFO |
+ |
+ p = patch.FromDict('https://example.com/c/repo/+/658277') |
+ |
+ expected = patch.GerritPatch( |
+ 'https://example.com', 'repo~branch~id', 'current revision') |
+ self.assertEqual(p, expected) |
+ |
+ |
+class GerritPatchTest(unittest.TestCase): |
def testPatch(self): |
- p = patch.Patch('https://codereview.chromium.org', 2851943002, 40001) |
+ p = patch.GerritPatch('https://example.com', 672011, '2f0d5c7') |
- other_patch = patch.Patch(u'https://codereview.chromium.org', |
- 2851943002, 40001) |
+ other_patch = patch.GerritPatch(u'https://example.com', 672011, '2f0d5c7') |
self.assertEqual(p, other_patch) |
- string = 'https://codereview.chromium.org/2851943002/40001' |
+ string = 'https://example.com/672011/2f0d5c7' |
self.assertEqual(str(p), string) |
self.assertEqual(p.id_string, string) |
+ @mock.patch('dashboard.services.gerrit_service.GetChange') |
+ def testBuildParameters(self, get_change): |
+ get_change.return_value = _GERRIT_CHANGE_INFO |
+ |
+ p = patch.GerritPatch('https://example.com', 658277, 'current revision') |
+ expected = { |
+ 'patch_gerrit_url': 'https://example.com', |
+ 'patch_issue': 658277, |
+ 'patch_project': 'chromium/src', |
+ 'patch_ref': 'refs/changes/77/658277/5', |
+ 'patch_repository_url': 'https://googlesource.com/chromium/src', |
+ 'patch_set': 5, |
+ 'patch_storage': 'gerrit', |
+ } |
+ self.assertEqual(p.BuildParameters(), expected) |
+ |
def testAsDict(self): |
- p = patch.Patch('https://codereview.chromium.org', 2851943002, 40001) |
+ p = patch.GerritPatch('https://example.com', 672011, '2f0d5c7') |
expected = { |
- 'server': 'https://codereview.chromium.org', |
- 'issue': 2851943002, |
- 'patchset': 40001, |
+ 'server': 'https://example.com', |
+ 'change': 672011, |
+ 'revision': '2f0d5c7', |
} |
self.assertEqual(p.AsDict(), expected) |
- def testFromDict(self): |
- p = patch.Patch.FromDict({ |
- 'server': 'https://codereview.chromium.org', |
- 'issue': 2851943002, |
- 'patchset': 40001, |
+ @mock.patch('dashboard.services.gerrit_service.GetChange') |
+ def testFromDict(self, get_change): |
+ get_change.return_value = _GERRIT_CHANGE_INFO |
+ |
+ p = patch.GerritPatch.FromDict({ |
+ 'server': 'https://example.com', |
+ 'change': 658277, |
+ 'revision': 4, |
}) |
- expected = patch.Patch('https://codereview.chromium.org', 2851943002, 40001) |
+ expected = patch.GerritPatch( |
+ 'https://example.com', 'repo~branch~id', 'other revision') |
+ self.assertEqual(p, expected) |
+ |
+ @mock.patch('dashboard.services.gerrit_service.GetChange') |
+ def testFromDictString(self, get_change): |
+ get_change.return_value = _GERRIT_CHANGE_INFO |
+ |
+ p = patch.GerritPatch.FromDict('https://example.com/c/repo/+/658277') |
+ |
+ expected = patch.GerritPatch( |
+ 'https://example.com', 'repo~branch~id', 'current revision') |
self.assertEqual(p, expected) |