|
| 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 fetchcode import package_versions |
| 18 | + |
| 19 | + |
| 20 | +def test_nuget_fetches_external_registration_pages(monkeypatch): |
| 21 | + calls = [] |
| 22 | + |
| 23 | + def response(url): |
| 24 | + calls.append(url) |
| 25 | + return { |
| 26 | + "items": [{"catalogEntry": {"version": "2.0", "published": "2024-01-01T00:00:00Z"}}] |
| 27 | + } |
| 28 | + |
| 29 | + monkeypatch.setattr(package_versions, "get_response", response) |
| 30 | + index = { |
| 31 | + "items": [ |
| 32 | + {"@id": "https://example.org/inline", "items": [{"catalogEntry": {"version": "1.0"}}]}, |
| 33 | + {"@id": "https://example.org/page2"}, |
| 34 | + {"@id": "https://example.org/empty", "items": []}, |
| 35 | + ] |
| 36 | + } |
| 37 | + versions = list(package_versions.nuget_extract_versions(index)) |
| 38 | + assert [version.value for version in versions] == ["1.0", "2.0"] |
| 39 | + assert calls == ["https://example.org/page2"] |
| 40 | + assert versions[1].release_date.isoformat() == "2024-01-01T00:00:00+00:00" |
0 commit comments