Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1023)

Unified Diff: tests/rietveld_test.py

Issue 6792028: Move patch.py and rietveld.py from commit-queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fixed remaining issues Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tests/local_rietveld.py ('K') | « tests/patch_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/rietveld_test.py
diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..6a32f64e4561159f1a6152198988b143c20453ce
--- /dev/null
+++ b/tests/rietveld_test.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for rietveld.py."""
+
+import logging
+import os
+import sys
+import unittest
+
+ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
+
+import patch
+import rietveld
+
+# Access to a protected member XX of a client class
+# pylint: disable=W0212
+
+
+class RietveldTest(unittest.TestCase):
+ def setUp(self):
+ super(RietveldTest, self).setUp()
+ self._rietveld_send = rietveld.Rietveld._send
+ rietveld.Rietveld._send = None
+
+ def tearDown(self):
+ super(RietveldTest, self).setUp()
+ rietveld.Rietveld._send = self._rietveld_send
+
+ def test_get_patch_empty(self):
+ rietveld.Rietveld._send = lambda x, y, payload: '{}'
+ r = rietveld.Rietveld('url', 'email', 'password')
+ patches = r.get_patch(123, 456)
+ self.assertTrue(isinstance(patches, patch.PatchSet))
+ self.assertEquals([], patches.patches)
+
+ def test_get_patch_no_status(self):
+ rietveld.Rietveld._send = lambda x, y, payload: (
+ '{'
+ ' "files":'
+ ' {'
+ ' "file_a":'
+ ' {'
+ ' }'
+ ' }'
+ '}')
+ r = rietveld.Rietveld('url', 'email', 'password')
+ try:
+ r.get_patch(123, 456)
+ self.fail()
+ except patch.UnsupportedPatchFormat, e:
+ self.assertEquals('file_a', e.filename)
+
+ def test_get_patch_two_files(self):
+ output = (
+ '{'
+ ' "files":'
+ ' {'
+ ' "file_a":'
+ ' {'
+ ' "status": "A",'
+ ' "is_binary": false,'
+ ' "num_chunks": 1,'
+ ' "id": 789'
+ ' }'
+ ' }'
+ '}')
+ rietveld.Rietveld._send = lambda x, y, payload: output
+ r = rietveld.Rietveld('url', 'email', 'password')
+ patches = r.get_patch(123, 456)
+ self.assertTrue(isinstance(patches, patch.PatchSet))
+ self.assertEquals(1, len(patches.patches))
+ obj = patches.patches[0]
+ self.assertEquals(patch.FilePatchDiff, obj.__class__)
+ self.assertEquals('file_a', obj.filename)
+ self.assertEquals([], obj.svn_properties)
+ self.assertEquals(False, obj.is_git_diff)
+ self.assertEquals(0, obj.patchlevel)
+ # This is because Rietveld._send() always returns the same buffer.
+ self.assertEquals(output, obj.get())
+
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.ERROR)
+ unittest.main()
« tests/local_rietveld.py ('K') | « tests/patch_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698