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

Side by Side Diff: appengine/findit/common/test/git_repository_test.py

Issue 1957653002: [Findit] Pull changelogs in batch. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 import base64 5 import base64
6 from datetime import datetime 6 from datetime import datetime
7 import json 7 import json
8 import re 8 import re
9 9
10 from testing_utils import testing 10 from testing_utils import testing
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 {'commit': '1'} 560 {'commit': '1'}
561 ] 561 ]
562 } 562 }
563 563
564 self.mock(git_repository.GitRepository, '_SendRequestForJsonResponse', 564 self.mock(git_repository.GitRepository, '_SendRequestForJsonResponse',
565 _MockSendRequestForJsonResponse) 565 _MockSendRequestForJsonResponse)
566 expected_commits = ['3', '2', '1'] 566 expected_commits = ['3', '2', '1']
567 actual_commits = self.git_repo.GetCommitsBetweenRevisions('0', '3', n=2) 567 actual_commits = self.git_repo.GetCommitsBetweenRevisions('0', '3', n=2)
568 self.assertEqual(expected_commits, actual_commits) 568 self.assertEqual(expected_commits, actual_commits)
569 569
570 def _MockGetCommitsBetweenRevisions(self, *_):
571 return ['2', '1']
572
573 def testGetChangeLogs(self): 570 def testGetChangeLogs(self):
574 571
575 def _MockGetChangeLog(*_): 572 def _MockSendRequestForJsonResponse(*_):
576 return ChangeLog.FromDict(DUMMY_CHANGELOG_JSON) 573 return {'log': [json.loads(COMMIT_LOG[5:])]}
577 574
578 self.mock(git_repository.GitRepository, 'GetCommitsBetweenRevisions', 575 self.mock(git_repository.GitRepository, '_SendRequestForJsonResponse',
579 self._MockGetCommitsBetweenRevisions) 576 _MockSendRequestForJsonResponse)
580 self.mock(git_repository.GitRepository, 'GetChangeLog', 577
581 _MockGetChangeLog) 578 changelogs = self.git_repo.GetChangeLogs('0', '2')
579
580 self.assertEqual(len(changelogs), 1)
581 self.assertEqual(changelogs[0].ToDict(), EXPECTED_CHANGE_LOG_JSON)
582
583 def testGetChangeLogsNextPage(self):
584 log1 = json.loads(COMMIT_LOG[5:])
585 log1['commit'] = 'first_commit'
586 log2 = log1.copy()
587 log2['commit'] = 'next_page_commit'
588
589 def _MockSendRequestForJsonResponse(*args, **_):
590 url = args[1]
stgao 2016/05/06 06:59:18 Can we expand the arguments above instead?
Sharu Jiang 2016/05/06 17:46:12 Done.
591 if 'next' in url:
592 return {'log': [log2]}
593
594 return {'log': [log1], 'next': 'next_page_commit'}
595
596 self.mock(git_repository.GitRepository, '_SendRequestForJsonResponse',
597 _MockSendRequestForJsonResponse)
582 598
583 changelogs = self.git_repo.GetChangeLogs('0', '2') 599 changelogs = self.git_repo.GetChangeLogs('0', '2')
584 600
585 self.assertEqual(len(changelogs), 2) 601 self.assertEqual(len(changelogs), 2)
586 self.assertEqual([changelogs[0].ToDict(), changelogs[1].ToDict()],
587 [DUMMY_CHANGELOG_JSON, DUMMY_CHANGELOG_JSON])
588 602
589 def testGetChangeLogsFailToGetChangeLog(self):
590 603
591 def _MockGetChangeLog(*_):
592 return None
593
594 self.mock(git_repository.GitRepository, 'GetCommitsBetweenRevisions',
595 self._MockGetCommitsBetweenRevisions)
596 self.mock(git_repository.GitRepository, 'GetChangeLog',
597 _MockGetChangeLog)
598
599 self.assertRaisesRegexp(
600 Exception, 'Failed to pull changelog for revision 2',
601 self.git_repo.GetChangeLogs, '0', '2')
OLDNEW
« appengine/findit/common/git_repository.py ('K') | « appengine/findit/common/git_repository.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698