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

Side by Side Diff: infra/libs/gerrit_api/test/gerrit_api_test.py

Issue 2180173003: gerrit_api: add tag to set_review method. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 25
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 } 36 }
36 37
37 TEST_PAYLOAD_LABELS_ONLY = { 38 TEST_PAYLOAD_LABELS_ONLY = {
38 'labels': { 39 'labels': {
39 'Code-Review': 1, 40 'Code-Review': 1,
40 }, 41 },
41 'notify': 'OWNER', 42 'notify': 'OWNER',
42 } 43 }
43 44
44 TEST_CHANGE_INFO = { 45 TEST_CHANGE_INFO = {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 mock_method.return_value = _create_mock_return(None, 500) 495 mock_method.return_value = _create_mock_return(None, 500)
495 self.assertRaises(gerrit_api.UnexpectedResponseException, 496 self.assertRaises(gerrit_api.UnexpectedResponseException,
496 self.gerrit.get_issue, 'issue') 497 self.gerrit.get_issue, 'issue')
497 498
498 @mock.patch.object(requests.Session, 'request') 499 @mock.patch.object(requests.Session, 'request')
499 def test_set_review(self, mock_method): 500 def test_set_review(self, mock_method):
500 mock_method.return_value = _create_mock_return( 501 mock_method.return_value = _create_mock_return(
501 '%s%s' % (GERRIT_JSON_HEADER, 502 '%s%s' % (GERRIT_JSON_HEADER,
502 json.dumps({'labels':{'Code-Review':1}})), 200) 503 json.dumps({'labels':{'Code-Review':1}})), 200)
503 self.gerrit.set_review('change_id', 'revision_id', 'Test message.', 504 self.gerrit.set_review('change_id', 'revision_id', 'Test message.',
504 { 'Code-Review': 1 }) 505 { 'Code-Review': 1 }, tag='cq')
505 mock_method.assert_called_once_with( 506 mock_method.assert_called_once_with(
506 data=json.dumps(TEST_PAYLOAD), 507 data=json.dumps(TEST_PAYLOAD),
507 method='POST', 508 method='POST',
508 params=None, 509 params=None,
509 url=('https://chromium-review.googlesource.com/a/changes/' 510 url=('https://chromium-review.googlesource.com/a/changes/'
510 'change_id/revisions/revision_id/review'), 511 'change_id/revisions/revision_id/review'),
511 headers=HEADERS_WITH_CONTENT_TYPE, 512 headers=HEADERS_WITH_CONTENT_TYPE,
512 hooks=self.gerrit._instrumentation_hooks) 513 hooks=self.gerrit._instrumentation_hooks)
513 514
514 @mock.patch.object(requests.Session, 'request') 515 @mock.patch.object(requests.Session, 'request')
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 mock_method.return_value = _create_mock_return( 554 mock_method.return_value = _create_mock_return(
554 'revision revision_id is not current revision', 409) 555 'revision revision_id is not current revision', 409)
555 self.assertRaises(gerrit_api.RevisionConflictException, 556 self.assertRaises(gerrit_api.RevisionConflictException,
556 self.gerrit.submit_revision, 'change_id', 'revision_id') 557 self.gerrit.submit_revision, 'change_id', 'revision_id')
557 558
558 @mock.patch.object(requests.Session, 'request') 559 @mock.patch.object(requests.Session, 'request')
559 def test_submit_revision_unexpected_response(self, mock_method): 560 def test_submit_revision_unexpected_response(self, mock_method):
560 mock_method.return_value = _create_mock_return(None, 500) 561 mock_method.return_value = _create_mock_return(None, 500)
561 self.assertRaises(gerrit_api.UnexpectedResponseException, 562 self.assertRaises(gerrit_api.UnexpectedResponseException,
562 self.gerrit.submit_revision, 'change_id', 'revision_id') 563 self.gerrit.submit_revision, 'change_id', 'revision_id')
OLDNEW
« infra/libs/gerrit_api/gerrit_api.py ('K') | « infra/libs/gerrit_api/gerrit_api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698