Skip to content

Commit 2d552c0

Browse files
committed
oc4ids_datastore_pipeline/registry.py: Change to getting individual data records
This means we can get all the dataset fields datatig has, previously we could only get fields in list_fields in the datatig config
1 parent 2fc7dca commit 2d552c0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

oc4ids_datastore_pipeline/registry.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ def fetch_registered_datasets() -> dict[str, dict[str, str]]:
1616
r = requests.get(url)
1717
r.raise_for_status()
1818
json_data = r.json()
19-
registered_datasets = {
20-
key: {
21-
"source_url": value["fields"]["url"]["value"],
22-
"country": value["fields"]["country"]["value"],
19+
registered_datasets = {}
20+
for key, value in json_data["records"].items():
21+
r_data = requests.get(value["api_url"])
22+
r_data.raise_for_status()
23+
r_data_json = r_data.json()
24+
registered_datasets[key] = {
25+
"source_url": r_data_json["fields"]["url"]["value"],
26+
"country": r_data_json["fields"]["country"]["value"],
2327
}
24-
for (key, value) in json_data["records"].items()
25-
}
2628
registered_datasets_count = len(registered_datasets)
2729
logger.info(f"Fetched URLs for {registered_datasets_count} datasets")
2830
except Exception as e:

tests/test_registry.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
1212

1313
def test_fetch_registered_datasets(mocker: MockerFixture) -> None:
1414
mock_response = MagicMock()
15-
mock_response.json.return_value = {
16-
"records": {
17-
"test_dataset": {
18-
"fields": {
19-
"url": {"value": "https://test_dataset.json"},
20-
"country": {"value": "ab"},
15+
mock_response.json.side_effect = [
16+
{
17+
"records": {
18+
"test_dataset": {
19+
"api_url": "http://www.example.com",
20+
"fields": {
21+
"url": {"value": "https://test_dataset.json"},
22+
"country": {"value": "ab"},
23+
},
2124
}
2225
}
23-
}
24-
}
26+
},
27+
{
28+
"fields": {
29+
"url": {"value": "https://test_dataset.json"},
30+
"country": {"value": "ab"},
31+
}
32+
},
33+
]
2534
patch_get = mocker.patch("oc4ids_datastore_pipeline.pipeline.requests.get")
2635
patch_get.return_value = mock_response
2736

0 commit comments

Comments
 (0)