|
| 1 | +# fetchcode is a free software tool from nexB Inc. and others. |
| 2 | +# Visit https://github.com/aboutcode-org/fetchcode for support and download. |
| 3 | +# |
| 4 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 5 | +# http://nexb.com and http://aboutcode.org |
| 6 | +# |
| 7 | +# This software is licensed under the Apache License version 2.0. |
| 8 | +# |
| 9 | +# You may not use this software except in compliance with the License. |
| 10 | +# You may obtain a copy of the License at: |
| 11 | +# http://apache.org/licenses/LICENSE-2.0 |
| 12 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 13 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 14 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations under the License. |
| 16 | + |
| 17 | +from unittest.mock import patch |
| 18 | + |
| 19 | +import pytest |
| 20 | +from packageurl.contrib.route import NoRouteAvailable |
| 21 | + |
| 22 | +from fetchcode.download_urls import download_url |
| 23 | +from fetchcode.download_urls import router |
| 24 | + |
| 25 | + |
| 26 | +def test_right_class_being_called_for_the_purls(): |
| 27 | + purls = [ |
| 28 | + |
| 29 | + "pkg:cpan/EXAMPLE/[email protected]", |
| 30 | + "pkg:composer/laravel/[email protected]", |
| 31 | + |
| 32 | + ] |
| 33 | + |
| 34 | + with patch("fetchcode.download_urls.Router.process") as mock_fetch: |
| 35 | + for purl in purls: |
| 36 | + assert download_url(purl) is not None, f"Failed for purl: {purl}" |
| 37 | + |
| 38 | + |
| 39 | +def test_with_invalid_purls(): |
| 40 | + invalid_purls = [ |
| 41 | + "pkg:invalid/requests", |
| 42 | + "pkg:xyz/dplyr", |
| 43 | + ] |
| 44 | + for purl in invalid_purls: |
| 45 | + with pytest.raises(NoRouteAvailable): |
| 46 | + router.process(purl) |
0 commit comments