| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Tests for gerrit_api.py""" | 5 """Tests for gerrit_api.py""" |
| 6 | 6 |
| 7 import copy | 7 import copy |
| 8 import json | 8 import json |
| 9 import mock | 9 import mock |
| 10 import requests | 10 import requests |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 HEADERS_WITH_CONTENT_TYPE = HEADERS.copy() | 26 HEADERS_WITH_CONTENT_TYPE = HEADERS.copy() |
| 27 HEADERS_WITH_CONTENT_TYPE['Content-Type'] = 'application/json;charset=UTF-8' | 27 HEADERS_WITH_CONTENT_TYPE['Content-Type'] = 'application/json;charset=UTF-8' |
| 28 | 28 |
| 29 TEST_PAYLOAD = { | 29 TEST_PAYLOAD = { |
| 30 'labels': { | 30 'labels': { |
| 31 'Code-Review': 1, | 31 'Code-Review': 1, |
| 32 }, | 32 }, |
| 33 'message': 'Test message.', | 33 'message': 'Test message.', |
| 34 'notify': 'NONE', | 34 'notify': 'NONE', |
| 35 'tag': 'cq', | 35 'tag': 'cq', |
| 36 'on_behalf_of': 'john@doe.net', |
| 36 } | 37 } |
| 37 | 38 |
| 38 TEST_PAYLOAD_LABELS_ONLY = { | 39 TEST_PAYLOAD_LABELS_ONLY = { |
| 39 'labels': { | 40 'labels': { |
| 40 'Code-Review': 1, | 41 'Code-Review': 1, |
| 41 }, | 42 }, |
| 42 'notify': 'OWNER', | 43 'notify': 'OWNER', |
| 43 } | 44 } |
| 44 | 45 |
| 45 TEST_CHANGE_INFO = { | 46 TEST_CHANGE_INFO = { |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 mock_method.return_value = _create_mock_return(None, 500) | 496 mock_method.return_value = _create_mock_return(None, 500) |
| 496 self.assertRaises(gerrit_api.UnexpectedResponseException, | 497 self.assertRaises(gerrit_api.UnexpectedResponseException, |
| 497 self.gerrit.get_issue, 'issue') | 498 self.gerrit.get_issue, 'issue') |
| 498 | 499 |
| 499 @mock.patch.object(requests.Session, 'request') | 500 @mock.patch.object(requests.Session, 'request') |
| 500 def test_set_review(self, mock_method): | 501 def test_set_review(self, mock_method): |
| 501 mock_method.return_value = _create_mock_return( | 502 mock_method.return_value = _create_mock_return( |
| 502 '%s%s' % (GERRIT_JSON_HEADER, | 503 '%s%s' % (GERRIT_JSON_HEADER, |
| 503 json.dumps({'labels':{'Code-Review':1}})), 200) | 504 json.dumps({'labels':{'Code-Review':1}})), 200) |
| 504 self.gerrit.set_review('change_id', 'revision_id', 'Test message.', | 505 self.gerrit.set_review('change_id', 'revision_id', 'Test message.', |
| 505 { 'Code-Review': 1 }, tag='cq') | 506 { 'Code-Review': 1 }, tag='cq', |
| 507 on_behalf_of='john@doe.net') |
| 506 mock_method.assert_called_once_with( | 508 mock_method.assert_called_once_with( |
| 507 data=json.dumps(TEST_PAYLOAD), | 509 data=json.dumps(TEST_PAYLOAD), |
| 508 method='POST', | 510 method='POST', |
| 509 params=None, | 511 params=None, |
| 510 url=('https://chromium-review.googlesource.com/a/changes/' | 512 url=('https://chromium-review.googlesource.com/a/changes/' |
| 511 'change_id/revisions/revision_id/review'), | 513 'change_id/revisions/revision_id/review'), |
| 512 headers=HEADERS_WITH_CONTENT_TYPE, | 514 headers=HEADERS_WITH_CONTENT_TYPE, |
| 513 hooks=self.gerrit._instrumentation_hooks) | 515 hooks=self.gerrit._instrumentation_hooks) |
| 514 | 516 |
| 515 @mock.patch.object(requests.Session, 'request') | 517 @mock.patch.object(requests.Session, 'request') |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 mock_method.return_value = _create_mock_return( | 556 mock_method.return_value = _create_mock_return( |
| 555 'revision revision_id is not current revision', 409) | 557 'revision revision_id is not current revision', 409) |
| 556 self.assertRaises(gerrit_api.RevisionConflictException, | 558 self.assertRaises(gerrit_api.RevisionConflictException, |
| 557 self.gerrit.submit_revision, 'change_id', 'revision_id') | 559 self.gerrit.submit_revision, 'change_id', 'revision_id') |
| 558 | 560 |
| 559 @mock.patch.object(requests.Session, 'request') | 561 @mock.patch.object(requests.Session, 'request') |
| 560 def test_submit_revision_unexpected_response(self, mock_method): | 562 def test_submit_revision_unexpected_response(self, mock_method): |
| 561 mock_method.return_value = _create_mock_return(None, 500) | 563 mock_method.return_value = _create_mock_return(None, 500) |
| 562 self.assertRaises(gerrit_api.UnexpectedResponseException, | 564 self.assertRaises(gerrit_api.UnexpectedResponseException, |
| 563 self.gerrit.submit_revision, 'change_id', 'revision_id') | 565 self.gerrit.submit_revision, 'change_id', 'revision_id') |
| OLD | NEW |