From 4572a0910203f061db3bddae4d62f07775c97d76 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 9 May 2013 21:30:46 +0000 Subject: [PATCH] Have Rietveld.get_description() consistently strip CR and whitespace. This makes the commit description cleaner. R=iannucci@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/14061008 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@199275 0039d316-1c4b-4281-b951-d872f2087c98 --- rietveld.py | 11 ++++++++--- tests/rietveld_test.py | 7 ++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rietveld.py b/rietveld.py index 5cedc471a4..fd6fabcaba 100644 --- a/rietveld.py +++ b/rietveld.py @@ -82,15 +82,20 @@ class Rietveld(object): self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) def get_description(self, issue): - """Returns the issue's description.""" - return self.get('/%d/description' % issue) + """Returns the issue's description. + + Converts any CRLF into LF and strip extraneous whitespace. + """ + return '\n'.join(self.get('/%d/description' % issue).strip().splitlines()) def get_issue_properties(self, issue, messages): """Returns all the issue's metadata as a dictionary.""" url = '/api/%d' % issue if messages: url += '?messages=true' - return json.loads(self.get(url)) + data = json.loads(self.get(url)) + data['description'] = '\n'.join(data['description'].strip().splitlines()) + return data def get_patchset_properties(self, issue, patchset): """Returns the patchset properties.""" diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py index 9171c72145..17627a5fd1 100755 --- a/tests/rietveld_test.py +++ b/tests/rietveld_test.py @@ -403,11 +403,12 @@ class CachingRietveldTest(BaseFixture): self.assertEqual(expected, self.rietveld.get_description(1)) def test_get_issue_properties(self): + data = {'description': 'wow\r\nno CR!', 'messages': 'foo'} self.requests = [ - ('/api/1?messages=true', rietveld.json.dumps({'messages': 'foo'})), + ('/api/1?messages=true', rietveld.json.dumps(data)), ] - expected = {} - expected_msg = {'messages': 'foo'} + expected = {u'description': u'wow\nno CR!'} + expected_msg = {u'description': u'wow\nno CR!', u'messages': u'foo'} self.assertEqual(expected, self.rietveld.get_issue_properties(1, False)) self.assertEqual(expected_msg, self.rietveld.get_issue_properties(1, True))