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 json | 5 import json |
6 | 6 |
7 import mock | 7 import mock |
8 import webapp2 | 8 import webapp2 |
9 import webtest | 9 import webtest |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 }) | 37 }) |
38 | 38 |
39 | 39 |
40 class FunctionalityTest(_IsolateTest): | 40 class FunctionalityTest(_IsolateTest): |
41 | 41 |
42 def testPostAndGet(self): | 42 def testPostAndGet(self): |
43 testing_common.SetIpWhitelist(['remote_ip']) | 43 testing_common.SetIpWhitelist(['remote_ip']) |
44 | 44 |
45 builder_name = 'Mac Builder' | 45 builder_name = 'Mac Builder' |
46 change = '{"base_commit": {"repository": "src", "git_hash": "git hash"}}' | 46 change = '{"commits": [{"repository": "src", "git_hash": "git hash"}]}' |
47 target = 'telemetry_perf_tests' | 47 target = 'telemetry_perf_tests' |
48 isolate_hash = 'a0c28d99182661887feac644317c94fa18eccbbb' | 48 isolate_hash = 'a0c28d99182661887feac644317c94fa18eccbbb' |
49 | 49 |
50 params = { | 50 params = { |
51 'builder_name': builder_name, | 51 'builder_name': builder_name, |
52 'change': change, | 52 'change': change, |
53 'isolate_map': json.dumps({target: isolate_hash}), | 53 'isolate_map': json.dumps({target: isolate_hash}), |
54 } | 54 } |
55 self.testapp.post('/isolate', params, status=200) | 55 self.testapp.post('/isolate', params, status=200) |
56 | 56 |
57 params = { | 57 params = { |
58 'builder_name': builder_name, | 58 'builder_name': builder_name, |
59 'change': change, | 59 'change': change, |
60 'target': target, | 60 'target': target, |
61 } | 61 } |
62 response = self.testapp.get('/isolate', params, status=200) | 62 response = self.testapp.get('/isolate', params, status=200) |
63 self.assertEqual(response.normal_body, isolate_hash) | 63 self.assertEqual(response.normal_body, isolate_hash) |
64 | 64 |
65 def testGetUnknownIsolate(self): | 65 def testGetUnknownIsolate(self): |
66 params = { | 66 params = { |
67 'builder_name': 'Mac Builder', | 67 'builder_name': 'Mac Builder', |
68 'change': '{"base_commit": {"repository": "src", "git_hash": "hash"}}', | 68 'change': '{"commits": [{"repository": "src", "git_hash": "hash"}]}', |
69 'target': 'not a real target', | 69 'target': 'not a real target', |
70 } | 70 } |
71 self.testapp.get('/isolate', params, status=404) | 71 self.testapp.get('/isolate', params, status=404) |
72 | 72 |
73 def testPostPermissionDenied(self): | 73 def testPostPermissionDenied(self): |
74 testing_common.SetIpWhitelist([]) | 74 testing_common.SetIpWhitelist([]) |
75 self.testapp.post('/isolate', status=403) | 75 self.testapp.post('/isolate', status=403) |
76 | 76 |
77 | 77 |
78 class ParameterValidationTest(_IsolateTest): | 78 class ParameterValidationTest(_IsolateTest): |
79 | 79 |
80 def testExtraParameter(self): | 80 def testExtraParameter(self): |
81 params = { | 81 params = { |
82 'builder_name': 'Mac Builder', | 82 'builder_name': 'Mac Builder', |
83 'change': '{"base_commit": {"repository": "src", "git_hash": "hash"}}', | 83 'change': '{"commits": [{"repository": "src", "git_hash": "hash"}]}', |
84 'target': 'telemetry_perf_tests', | 84 'target': 'telemetry_perf_tests', |
85 'extra_parameter': '', | 85 'extra_parameter': '', |
86 } | 86 } |
87 self.testapp.get('/isolate', params, status=400) | 87 self.testapp.get('/isolate', params, status=400) |
88 | 88 |
89 def testMissingParameter(self): | 89 def testMissingParameter(self): |
90 params = { | 90 params = { |
91 'builder_name': 'Mac Builder', | 91 'builder_name': 'Mac Builder', |
92 'change': '{"base_commit": {"repository": "src", "git_hash": "hash"}}', | 92 'change': '{"commits": [{"repository": "src", "git_hash": "hash"}]}', |
93 } | 93 } |
94 self.testapp.get('/isolate', params, status=400) | 94 self.testapp.get('/isolate', params, status=400) |
95 | 95 |
96 def testEmptyParameter(self): | 96 def testEmptyParameter(self): |
97 params = { | 97 params = { |
98 'builder_name': 'Mac Builder', | 98 'builder_name': 'Mac Builder', |
99 'change': '{"base_commit": {"repository": "src", "git_hash": "hash"}}', | 99 'change': '{"commits": [{"repository": "src", "git_hash": "hash"}]}', |
100 'target': '', | 100 'target': '', |
101 } | 101 } |
102 self.testapp.get('/isolate', params, status=400) | 102 self.testapp.get('/isolate', params, status=400) |
103 | 103 |
104 def testBadJson(self): | 104 def testBadJson(self): |
105 params = { | 105 params = { |
106 'builder_name': 'Mac Builder', | 106 'builder_name': 'Mac Builder', |
107 'change': '', | 107 'change': '', |
108 'target': 'telemetry_perf_tests', | 108 'target': 'telemetry_perf_tests', |
109 } | 109 } |
110 self.testapp.get('/isolate', params, status=400) | 110 self.testapp.get('/isolate', params, status=400) |
111 | 111 |
112 def testBadChange(self): | 112 def testBadChange(self): |
113 params = { | 113 params = { |
114 'builder_name': 'Mac Builder', | 114 'builder_name': 'Mac Builder', |
115 'change': '{"base_commit": {}}', | 115 'change': '{"commits": [{}]}', |
116 'target': 'telemetry_perf_tests', | 116 'target': 'telemetry_perf_tests', |
117 } | 117 } |
118 self.testapp.get('/isolate', params, status=400) | 118 self.testapp.get('/isolate', params, status=400) |
119 | 119 |
120 def testGetInvalidChangeBecauseOfUnknownRepository(self): | 120 def testGetInvalidChangeBecauseOfUnknownRepository(self): |
121 params = { | 121 params = { |
122 'builder_name': 'Mac Builder', | 122 'builder_name': 'Mac Builder', |
123 'change': '{"base_commit": {"repository": "foo", "git_hash": "hash"}}', | 123 'change': '{"commits": [{"repository": "foo", "git_hash": "hash"}]}', |
124 'target': 'telemetry_perf_tests', | 124 'target': 'telemetry_perf_tests', |
125 } | 125 } |
126 self.testapp.get('/isolate', params, status=400) | 126 self.testapp.get('/isolate', params, status=400) |
127 | 127 |
128 def testPostInvalidChangeBecauseOfUnknownRepository(self): | 128 def testPostInvalidChangeBecauseOfUnknownRepository(self): |
129 testing_common.SetIpWhitelist(['remote_ip']) | 129 testing_common.SetIpWhitelist(['remote_ip']) |
130 | 130 |
131 params = { | 131 params = { |
132 'builder_name': 'Mac Builder', | 132 'builder_name': 'Mac Builder', |
133 'change': '{"base_commit": {"repository": "foo", "git_hash": "hash"}}', | 133 'change': '{"commits": [{"repository": "foo", "git_hash": "hash"}]}', |
134 'isolate_map': '{"telemetry_perf_tests": "a0c28d9"}', | 134 'isolate_map': '{"telemetry_perf_tests": "a0c28d9"}', |
135 } | 135 } |
136 self.testapp.post('/isolate', params, status=400) | 136 self.testapp.post('/isolate', params, status=400) |
OLD | NEW |