| # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Tests for gerrit URL parsing.""" |
| |
| from __future__ import absolute_import |
| from __future__ import division |
| from __future__ import print_function |
| |
| import pytest |
| from chromite.lib import clactions |
| |
| from exonerator import gerrit_urls |
| |
| |
| @pytest.mark.parametrize("url", [ |
| "http://crrev.com/c/1234", |
| "crrev.com/c/1234", |
| "http://crosreview.com/1234", |
| "crosreview.com/c/1234", |
| "https://chromium-review.googlesource.com/c/1234", |
| "https://chromium-review.googlesource.com/1234", |
| "chromium-review.googlesource.com/1234", |
| ]) |
| def TestMatchingExternalPatterns(url): |
| got = gerrit_urls.CLFromBlameURL(url) |
| assert got == clactions.GerritChangeTuple(1234, internal=False) |
| |
| |
| @pytest.mark.parametrize("url", [ |
| "http://crrev.com/i/1234", |
| "crrev.com/i/1234", |
| "http://crosreview.com/i/1234", |
| "crosreview.com/i/1234", |
| "https://chrome-internal-review.googlesource.com/c/1234", |
| "https://chrome-internal-review.googlesource.com/1234", |
| "chrome-internal-review.googlesource.com/1234", |
| ]) |
| def TestMatchingInternalPatterns(url): |
| got = gerrit_urls.CLFromBlameURL(url) |
| assert got == clactions.GerritChangeTuple(1234, internal=True) |
| |
| |
| @pytest.mark.parametrize("url", [ |
| "crrev.com/1234", |
| "http://crrev-evil.com/c/1234", |
| "http://crrev-evil.com/i/1234", |
| "evil.com/1234", |
| "example.com/c/1234", |
| "https://chromium-review.evil.com/c/1234", |
| "chromium-review.googlesource.evil.com/1234", |
| "chrome-internal-review.googlesource.evil.com/1234", |
| ]) |
| def TestNonMatchingPatterns(url): |
| with pytest.raises(ValueError): |
| gerrit_urls.CLFromBlameURL(url) |