/
/
1"""Test Tidal Page Parser."""
2
3import json
4import pathlib
5from unittest.mock import Mock
6
7import pytest
8from music_assistant_models.enums import MediaType
9
10from music_assistant.providers.tidal.tidal_page_parser import TidalPageParser
11
12FIXTURES_DIR = pathlib.Path(__file__).parent / "fixtures"
13PAGE_FIXTURES = list(FIXTURES_DIR.glob("pages/*.json"))
14
15
16@pytest.mark.parametrize("example", PAGE_FIXTURES, ids=lambda val: str(val.stem))
17def test_page_parser(example: pathlib.Path, provider_mock: Mock) -> None:
18 """Test page parser with fixtures."""
19 with open(example) as f:
20 data = json.load(f)
21
22 parser = TidalPageParser(provider_mock)
23 parser.parse_page_structure(data, "pages/home")
24
25 assert len(parser._module_map) == 3
26
27 # Test first module (Playlists)
28 module_info = parser._module_map[0]
29 items, content_type = parser.get_module_items(module_info)
30 assert content_type == MediaType.PLAYLIST
31 assert len(items) == 1
32 assert items[0].name == "Test Playlist"
33
34 # Test second module (Albums)
35 module_info = parser._module_map[1]
36 items, content_type = parser.get_module_items(module_info)
37 assert content_type == MediaType.ALBUM
38 assert len(items) == 1
39 assert items[0].name == "Test Album"
40
41 # Test third module (Mixes)
42 module_info = parser._module_map[2]
43 items, content_type = parser.get_module_items(module_info)
44 assert content_type == MediaType.PLAYLIST
45 assert len(items) == 1
46 assert items[0].name == "My Mix"
47