from bs4 import BeautifulSoup

from addon.plugins import filmpalast_plugin as fp


def _soup(html: str):
    return BeautifulSoup(html, "html.parser")


def test_genres_parse_sidebar(monkeypatch):
    html = """
    <aside>
      <section id="genre">
        <ul>
          <li><a href="https://filmpalast.to/search/genre/Action">Action</a></li>
          <li><a href="https://filmpalast.to/search/genre/Drama">Drama</a></li>
        </ul>
      </section>
    </aside>
    """
    monkeypatch.setattr(fp, "_get_soup", lambda *args, **kwargs: _soup(html))
    plugin = fp.FilmpalastPlugin()
    genres = plugin.genres()
    assert genres == ["Action", "Drama"]


def test_titles_for_genre_page_parsing(monkeypatch):
    html = """
    <article class="liste"><h2><a href="//filmpalast.to/stream/test-film">Test Film</a></h2></article>
    <article class="liste"><h2><a href="//filmpalast.to/stream/test-show-s01e01">Test Show S01E01 Pilot</a></h2></article>
    <article class="liste"><h2><a href="//filmpalast.to/stream/test-show-s01e02">Test Show S01E02 Folge 2</a></h2></article>
    """
    plugin = fp.FilmpalastPlugin()
    plugin._genre_to_url = {"Action": "https://filmpalast.to/search/genre/Action"}
    monkeypatch.setattr(fp, "_get_soup", lambda *args, **kwargs: _soup(html))

    titles = plugin.titles_for_genre_page("Action", 1)

    assert titles == ["Test Film", "Test Show"]
    assert plugin.seasons_for("Test Show") == ["Staffel 1"]

