| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 unittest | 5 import unittest |
| 6 | 6 |
| 7 from webkitpy.common.host_mock import MockHost | 7 from webkitpy.common.host_mock import MockHost |
| 8 from webkitpy.common.system.executive_mock import MockExecutive | 8 from webkitpy.common.system.executive_mock import MockExecutive |
| 9 from webkitpy.w3c.test_exporter import TestExporter | 9 from webkitpy.w3c.test_exporter import TestExporter |
| 10 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub | 10 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub |
| 11 | 11 |
| 12 | 12 |
| 13 class TestExporterTest(unittest.TestCase): | 13 class TestExporterTest(unittest.TestCase): |
| 14 | 14 |
| 15 def setUp(self): | 15 def setUp(self): |
| 16 self.host = MockHost() | 16 self.host = MockHost() |
| 17 self.wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 18 | 17 |
| 19 def test_stops_if_more_than_one_pr_is_in_flight(self): | 18 def test_stops_if_more_than_one_pr_is_in_flight(self): |
| 20 host = MockHost() | 19 host = MockHost() |
| 21 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) | 20 test_exporter = TestExporter(host, 'gh-username', 'gh-token') |
| 21 test_exporter.wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id'
: 2}]) |
| 22 | 22 |
| 23 # TODO: make Exception more specific | 23 # TODO: make Exception more specific |
| 24 with self.assertRaises(Exception): | 24 with self.assertRaises(Exception): |
| 25 TestExporter(host, wpt_github).run() | 25 test_exporter.run() |
| 26 | 26 |
| 27 def test_if_pr_exists_merges_it(self): | 27 def test_if_pr_exists_merges_it(self): |
| 28 host = MockHost() | 28 host = MockHost() |
| 29 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
) | 29 test_exporter = TestExporter(host, 'gh-username', 'gh-token') |
| 30 TestExporter(host, wpt_github).run() | 30 test_exporter.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 't
itle': 'abc'}]) |
| 31 test_exporter.run() |
| 31 | 32 |
| 32 self.assertIn('merge_pull_request', wpt_github.calls) | 33 self.assertIn('merge_pull_request', test_exporter.wpt_github.calls) |
| 33 | 34 |
| 34 def test_merge_failure_errors_out(self): | 35 def test_merge_failure_errors_out(self): |
| 35 host = MockHost() | 36 host = MockHost() |
| 36 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
, | 37 test_exporter = TestExporter(host, 'gh-username', 'gh-token') |
| 37 unsuccessful_merge=True) | 38 test_exporter.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 't
itle': 'abc'}], |
| 39 unsuccessful_merge=True) |
| 38 | 40 |
| 39 # TODO: make Exception more specific | 41 # TODO: make Exception more specific |
| 40 with self.assertRaises(Exception): | 42 with self.assertRaises(Exception): |
| 41 TestExporter(host, wpt_github).run() | 43 test_exporter.run() |
| 42 | 44 |
| 43 def test_dry_run_stops_before_creating_pr(self): | 45 def test_dry_run_stops_before_creating_pr(self): |
| 44 host = MockHost() | 46 host = MockHost() |
| 45 host.executive = MockExecutive(output='beefcafe') | 47 host.executive = MockExecutive(output='beefcafe') |
| 46 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
) | 48 test_exporter = TestExporter(host, 'gh-username', 'gh-token', dry_run=Tr
ue) |
| 47 TestExporter(host, wpt_github, dry_run=True).run() | 49 test_exporter.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 't
itle': 'abc'}]) |
| 50 test_exporter.run() |
| 48 | 51 |
| 49 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) | 52 self.assertEqual(test_exporter.wpt_github.calls, ['in_flight_pull_reques
ts']) |
| 50 | 53 |
| 51 def test_creates_pull_request_for_earliest_commit(self): | 54 def test_creates_pull_request_for_earliest_commit(self): |
| 52 host = MockHost() | 55 host = MockHost() |
| 53 | 56 |
| 54 def mock_command(args): | 57 def mock_command(args): |
| 55 canned_git_outputs = { | 58 canned_git_outputs = { |
| 56 'show': 'newer fake text' if 'add087a97844f4b9e307d9a216940582d9
6db306' in args else 'older fake text', | 59 'show': 'newer fake text' if 'add087a97844f4b9e307d9a216940582d9
6db306' in args else 'older fake text', |
| 57 'rev-list': 'c881563d734a86f7d9cd57ac509653a61c45c240\nadd087a97
844f4b9e307d9a216940582d96db306', | 60 'rev-list': 'c881563d734a86f7d9cd57ac509653a61c45c240\nadd087a97
844f4b9e307d9a216940582d96db306', |
| 58 'footers': 'fake-cr-position', | 61 'footers': 'fake-cr-position', |
| 59 'remote': 'github', | 62 'remote': 'github', |
| 60 'format-patch': 'fake patch', | 63 'format-patch': 'fake patch', |
| 61 'diff': 'fake patch diff', | 64 'diff': 'fake patch diff', |
| 62 'diff-tree': 'fake\n\files\nchanged', | 65 'diff-tree': 'fake\n\files\nchanged', |
| 63 'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240', | 66 'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240', |
| 64 } | 67 } |
| 65 return canned_git_outputs.get(args[1], '') | 68 return canned_git_outputs.get(args[1], '') |
| 66 | 69 |
| 67 host.executive = MockExecutive(run_command_fn=mock_command) | 70 host.executive = MockExecutive(run_command_fn=mock_command) |
| 68 wpt_github = MockWPTGitHub(pull_requests=[]) | 71 test_exporter = TestExporter(host, 'gh-username', 'gh-token') |
| 72 test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) |
| 73 test_exporter.run() |
| 69 | 74 |
| 70 TestExporter(host, wpt_github).run() | 75 self.assertEqual(test_exporter.wpt_github.calls, ['in_flight_pull_reques
ts', 'create_pr']) |
| 71 | 76 self.assertEqual(test_exporter.wpt_github.pull_requests_created, |
| 72 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
r']) | |
| 73 self.assertEqual(wpt_github.pull_requests_created, | |
| 74 [('chromium-export-try', 'older fake text', 'older fake
text')]) | 77 [('chromium-export-try', 'older fake text', 'older fake
text')]) |
| OLD | NEW |