|
8 | 8 |
|
9 | 9 | from oc4ids_datastore_pipeline.pipeline import (
|
10 | 10 | download_json,
|
| 11 | + fetch_license_mappings, |
11 | 12 | fetch_registered_datasets,
|
12 | 13 | process_dataset,
|
13 | 14 | validate_json,
|
@@ -43,6 +44,70 @@ def test_fetch_registered_datasets_raises_failure_exception(
|
43 | 44 | assert "Mocked exception" in str(exc_info.value)
|
44 | 45 |
|
45 | 46 |
|
| 47 | +def test_fetch_license_mappings(mocker: MockerFixture) -> None: |
| 48 | + mock_response = MagicMock() |
| 49 | + mock_response.json.return_value = { |
| 50 | + "records": { |
| 51 | + "license_1": { |
| 52 | + "fields": { |
| 53 | + "title": {"value": "License 1"}, |
| 54 | + "urls": { |
| 55 | + "values": [ |
| 56 | + { |
| 57 | + "fields": { |
| 58 | + "url": {"value": "https://license_1.com/license"} |
| 59 | + } |
| 60 | + }, |
| 61 | + { |
| 62 | + "fields": { |
| 63 | + "url": { |
| 64 | + "value": "https://license_1.com/different_url" |
| 65 | + } |
| 66 | + } |
| 67 | + }, |
| 68 | + ] |
| 69 | + }, |
| 70 | + } |
| 71 | + }, |
| 72 | + "license_2": { |
| 73 | + "fields": { |
| 74 | + "title": {"value": "License 2"}, |
| 75 | + "urls": { |
| 76 | + "values": [ |
| 77 | + { |
| 78 | + "fields": { |
| 79 | + "url": {"value": "https://license_2.com/license"} |
| 80 | + } |
| 81 | + }, |
| 82 | + ] |
| 83 | + }, |
| 84 | + } |
| 85 | + }, |
| 86 | + } |
| 87 | + } |
| 88 | + patch_get = mocker.patch("oc4ids_datastore_pipeline.pipeline.requests.get") |
| 89 | + patch_get.return_value = mock_response |
| 90 | + |
| 91 | + result = fetch_license_mappings() |
| 92 | + |
| 93 | + assert result == { |
| 94 | + "https://license_1.com/license": "License 1", |
| 95 | + "https://license_1.com/different_url": "License 1", |
| 96 | + "https://license_2.com/license": "License 2", |
| 97 | + } |
| 98 | + |
| 99 | + |
| 100 | +def test_fetch_license_mappings_catches_exception( |
| 101 | + mocker: MockerFixture, |
| 102 | +) -> None: |
| 103 | + patch_get = mocker.patch("oc4ids_datastore_pipeline.pipeline.requests.get") |
| 104 | + patch_get.side_effect = Exception("Mocked exception") |
| 105 | + |
| 106 | + result = fetch_license_mappings() |
| 107 | + |
| 108 | + assert result == {} |
| 109 | + |
| 110 | + |
46 | 111 | def test_download_json_raises_failure_exception(mocker: MockerFixture) -> None:
|
47 | 112 | patch_get = mocker.patch("oc4ids_datastore_pipeline.pipeline.requests.get")
|
48 | 113 | patch_get.side_effect = Exception("Mocked exception")
|
|
0 commit comments