| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 Google Inc. | 2 # Copyright 2016 Google Inc. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. | 14 # limitations under the License. |
| 15 | 15 |
| 16 """Tests for utils.""" | 16 """Tests for utils.""" |
| 17 | 17 |
| 18 import unittest | 18 import unittest |
| 19 | 19 |
| 20 import setup | 20 import setup |
| 21 setup.process_args() | 21 setup.process_args() |
| 22 | 22 |
| 23 from codereview import utils | 23 from codereview import utils |
| 24 | 24 |
| 25 | 25 |
| 26 class UtilsTest(unittest.TestCase): | 26 class UtilsTest(unittest.TestCase): |
| 27 def test_parse_cq_status_url_message_v2(self): | 27 def test_parse_cq_status_url_v2(self): |
| 28 url = ('https://chromium-cq-status.appspot.com/v2/' | 28 url = ('https://chromium-cq-status.appspot.com/v2/' |
| 29 'patch-status/codereview.chromium.org/213/1') | 29 'patch-status/codereview.chromium.org/213/1') |
| 30 msg = 'CQ is trying da patch. Follow status at\n' + url | 30 self.assertEqual(utils.parse_cq_status_url(url), (213, 1)) |
| 31 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 32 msg += '\n' | |
| 33 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 34 msg = 'Dry run: ' + msg | |
| 35 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 36 | 31 |
| 37 def test_parse_cq_status_url_message_v1(self): | 32 def test_parse_cq_status_url_message_v1(self): |
| 38 url = 'https://chromium-cq-status.appspot.com/patch-status/213/1' | 33 url = 'https://chromium-cq-status.appspot.com/patch-status/213/1' |
| 39 msg = 'CQ is trying da patch. Follow status at\n' + url | 34 self.assertEqual(utils.parse_cq_status_url(url), (213, 1)) |
| 40 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 41 msg += '\n' | |
| 42 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 43 msg = 'Dry run: ' + msg | |
| 44 self.assertEqual(utils.parse_cq_status_url_message(msg), (url, 213, 1)) | |
| 45 | 35 |
| 46 def test_parse_cq_status_url_message_fail(self): | 36 def test_parse_cq_status_url_message_fail(self): |
| 47 self.assertEqual(utils.parse_cq_status_url_message(''), (None, None, None)) | 37 self.assertEqual(utils.parse_cq_status_url(''), (None, None)) |
| 48 msg = 'Dry run failed because https://weird.url/patch-status/123/4' | 38 self.assertEqual(utils.parse_cq_status_url('https://bad.url'), (None, None)) |
| 49 self.assertEqual(utils.parse_cq_status_url_message(msg), (None, None, None)) | |
| 50 | 39 |
| 51 | 40 |
| 52 if __name__ == '__main__': | 41 if __name__ == '__main__': |
| 53 unittest.main() | 42 unittest.main() |
| OLD | NEW |