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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py

Issue 2719173002: [WPT Export] Require GitHub API token in WPT remote origin URL (Closed)
Patch Set: Remove --depth, make LocalWPT.gh_token optional Created 3 years, 9 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 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, mock_git_comman ds 8 from webkitpy.common.system.executive_mock import MockExecutive, mock_git_comman ds
9 from webkitpy.common.system.filesystem_mock import MockFileSystem 9 from webkitpy.common.system.filesystem_mock import MockFileSystem
10 from webkitpy.w3c.local_wpt import LocalWPT 10 from webkitpy.w3c.local_wpt import LocalWPT
11 11
12 12
13 class LocalWPTTest(unittest.TestCase): 13 class LocalWPTTest(unittest.TestCase):
14 14
15 def test_fetch_requires_gh_token(self):
16 host = MockHost()
17 local_wpt = LocalWPT(host)
18
19 with self.assertRaises(AssertionError):
20 local_wpt.fetch()
21
15 def test_fetch_when_wpt_dir_exists(self): 22 def test_fetch_when_wpt_dir_exists(self):
16 host = MockHost() 23 host = MockHost()
17 host.filesystem = MockFileSystem(files={ 24 host.filesystem = MockFileSystem(files={
18 '/tmp/wpt': '' 25 '/tmp/wpt': ''
19 }) 26 })
20 27
21 local_wpt = LocalWPT(host) 28 local_wpt = LocalWPT(host, 'token')
22 local_wpt.fetch() 29 local_wpt.fetch()
23 30
24 self.assertEqual(host.executive.calls, [ 31 self.assertEqual(host.executive.calls, [
25 ['git', 'fetch', 'origin'], 32 ['git', 'fetch', 'origin'],
26 ['git', 'checkout', 'origin/master'], 33 ['git', 'checkout', 'origin/master'],
27 ]) 34 ])
28 35
29 def test_fetch_when_wpt_dir_does_not_exist(self): 36 def test_fetch_when_wpt_dir_does_not_exist(self):
30 host = MockHost() 37 host = MockHost()
31 host.filesystem = MockFileSystem() 38 host.filesystem = MockFileSystem()
32 39
33 local_wpt = LocalWPT(host) 40 local_wpt = LocalWPT(host, 'token')
34 local_wpt.fetch() 41 local_wpt.fetch()
35 42
36 self.assertEqual(host.executive.calls, [ 43 self.assertEqual(host.executive.calls, [
37 ['git', 'clone', 'https://github.com/w3c/web-platform-tests.git', '/ tmp/wpt'], 44 ['git', 'clone', 'https://token@github.com/w3c/web-platform-tests.gi t', '/tmp/wpt'],
38 ]) 45 ])
39 46
40 def test_constructor(self): 47 def test_constructor(self):
41 host = MockHost() 48 host = MockHost()
42 LocalWPT(host) 49 LocalWPT(host, 'token')
43 self.assertEqual(len(host.executive.calls), 0) 50 self.assertEqual(len(host.executive.calls), 0)
44 51
45 def test_run(self): 52 def test_run(self):
46 host = MockHost() 53 host = MockHost()
47 host.filesystem = MockFileSystem() 54 host.filesystem = MockFileSystem()
48 local_wpt = LocalWPT(host) 55 local_wpt = LocalWPT(host, 'token')
49 local_wpt.run(['echo', 'rutabaga']) 56 local_wpt.run(['echo', 'rutabaga'])
50 self.assertEqual(host.executive.calls, [['echo', 'rutabaga']]) 57 self.assertEqual(host.executive.calls, [['echo', 'rutabaga']])
51 58
52 def test_last_wpt_exported_commit(self): 59 def test_last_wpt_exported_commit(self):
53 host = MockHost() 60 host = MockHost()
54 host.executive = mock_git_commands({ 61 host.executive = mock_git_commands({
55 'rev-list': '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', 62 'rev-list': '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
56 'footers': 'Cr-Commit-Position: 123', 63 'footers': 'Cr-Commit-Position: 123',
57 'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306', 64 'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
58 }, strict=True) 65 }, strict=True)
59 host.filesystem = MockFileSystem() 66 host.filesystem = MockFileSystem()
60 local_wpt = LocalWPT(host) 67 local_wpt = LocalWPT(host, 'token')
61 68
62 wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit() 69 wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
63 self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8') 70 self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
64 self.assertEqual(chromium_commit.position, '123') 71 self.assertEqual(chromium_commit.position, '123')
65 self.assertEqual(chromium_commit.sha, 'add087a97844f4b9e307d9a216940582d 96db306') 72 self.assertEqual(chromium_commit.sha, 'add087a97844f4b9e307d9a216940582d 96db306')
66 73
67 def test_last_wpt_exported_commit_not_found(self): 74 def test_last_wpt_exported_commit_not_found(self):
68 host = MockHost() 75 host = MockHost()
69 host.executive = MockExecutive(run_command_fn=lambda _: '') 76 host.executive = MockExecutive(run_command_fn=lambda _: '')
70 host.filesystem = MockFileSystem() 77 host.filesystem = MockFileSystem()
71 local_wpt = LocalWPT(host) 78 local_wpt = LocalWPT(host, 'token')
72 79
73 commit = local_wpt.most_recent_chromium_commit() 80 commit = local_wpt.most_recent_chromium_commit()
74 self.assertEqual(commit, (None, None)) 81 self.assertEqual(commit, (None, None))
75 82
76 def test_create_branch_with_patch(self): 83 def test_create_branch_with_patch(self):
77 host = MockHost() 84 host = MockHost()
78 host.filesystem = MockFileSystem() 85 host.filesystem = MockFileSystem()
79 86
80 local_wpt = LocalWPT(host) 87 local_wpt = LocalWPT(host, 'token')
81 local_wpt.fetch() 88 local_wpt.fetch()
82 89
83 local_branch_name = local_wpt.create_branch_with_patch('message', 'patch ', 'author') 90 local_branch_name = local_wpt.create_branch_with_patch('message', 'patch ', 'author')
84 self.assertEqual(local_branch_name, 'chromium-export-try') 91 self.assertEqual(local_branch_name, 'chromium-export-try')
85 self.assertEqual(host.executive.calls, [ 92 self.assertEqual(host.executive.calls, [
86 ['git', 'clone', 'https://github.com/w3c/web-platform-tests.git', '/ tmp/wpt'], 93 ['git', 'clone', 'https://token@github.com/w3c/web-platform-tests.gi t', '/tmp/wpt'],
87 ['git', 'reset', '--hard', 'HEAD'], 94 ['git', 'reset', '--hard', 'HEAD'],
88 ['git', 'clean', '-fdx'], 95 ['git', 'clean', '-fdx'],
89 ['git', 'checkout', 'origin/master'], 96 ['git', 'checkout', 'origin/master'],
90 ['git', 'branch', '-a'], 97 ['git', 'branch', '-a'],
91 ['git', 'branch', '-a'], 98 ['git', 'branch', '-a'],
92 ['git', 'checkout', '-b', 'chromium-export-try'], 99 ['git', 'checkout', '-b', 'chromium-export-try'],
93 ['git', 'apply', '-'], 100 ['git', 'apply', '-'],
94 ['git', 'add', '.'], 101 ['git', 'add', '.'],
95 ['git', 'commit', '--author', 'author', '-am', 'message'], 102 ['git', 'commit', '--author', 'author', '-am', 'message'],
96 ['git', 'push', '-f', 'origin', 'chromium-export-try']]) 103 ['git', 'push', '-f', 'origin', 'chromium-export-try']])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698