| OLD | NEW |
| 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 Loading... |
| 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, *_): | 570 def testGetChangeLogs(self): |
| 571 return ['2', '1'] | 571 def _MockSendRequestForJsonResponse(*_, **kargs): |
| 572 self.assertTrue(bool(kargs)) |
| 573 return {'log': [json.loads(COMMIT_LOG[5:])]} |
| 572 | 574 |
| 573 def testGetChangeLogs(self): | 575 self.mock(git_repository.GitRepository, '_SendRequestForJsonResponse', |
| 576 _MockSendRequestForJsonResponse) |
| 574 | 577 |
| 575 def _MockGetChangeLog(*_): | 578 changelogs = self.git_repo.GetChangeLogs('0', '2') |
| 576 return ChangeLog.FromDict(DUMMY_CHANGELOG_JSON) | |
| 577 | 579 |
| 578 self.mock(git_repository.GitRepository, 'GetCommitsBetweenRevisions', | 580 self.assertEqual(len(changelogs), 1) |
| 579 self._MockGetCommitsBetweenRevisions) | 581 self.assertEqual(changelogs[0].ToDict(), EXPECTED_CHANGE_LOG_JSON) |
| 580 self.mock(git_repository.GitRepository, 'GetChangeLog', | 582 |
| 581 _MockGetChangeLog) | 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(_, url, **kargs): |
| 590 self.assertTrue(bool(kargs)) |
| 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 | |
| 589 def testGetChangeLogsFailToGetChangeLog(self): | |
| 590 | |
| 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') | |
| OLD | NEW |