funkwhale/api/tests/music/test_wikidata.py

45 lines
1.3 KiB
Python

from unittest.mock import patch
from funkwhale_api.music import wikidata
# to test agaitnst the actual database disable r_mock autouse in conftest.py
def test_get_far_right_artists():
mock_item_data = {
"labels": {"en": {"value": "Mock Artist"}},
"claims": {
"P434": [
{
"mainsnak": {
"datavalue": {"value": "e29eb6ec-7773-41cb-8a72-a575d647e6ab"}
}
}
]
},
}
with patch(
"wikibaseintegrator.wbi_helpers.execute_sparql_query"
) as mock_query, patch(
"wikibaseintegrator.entities.item.ItemEntity.get"
) as mock_item_get:
# Mock SPARQL query result
mock_query.return_value = {
"results": {
"bindings": [
{"itemLabel": {"value": "Q123456"}} # Fake Wikidata item ID
]
}
}
# Mock the item.get().get_json() call
mock_item_get.return_value.get_json.return_value = mock_item_data
# Call the actual function
artists = wikidata.get_far_right_artists()
assert len(artists) == 1
assert artists[0].name == "Mock Artist"
assert artists[0].mbid == "e29eb6ec-7773-41cb-8a72-a575d647e6ab"
assert artists[0].far_right == "Q123456"