import os

from GramAddict.core.utils import is_ad

FIX_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fixtures")


def test_real_sponsored_reel_flexcode_is_detected():
    """
    Test: The manual_interrupt dump is a sponsored Reel (flexcode_systems).
    is_ad MUST return True.
    """
    xml_path = os.path.join(FIX_DIR, "sponsored_reel.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is True, "Failed to detect Sponsored Reel ad in realistic dump!"


def test_normal_post_not_ad():
    """
    Test: The manual_interrupt dump is a normal post.
    is_ad MUST return False to avoid false positives.
    """
    xml_path = os.path.join(FIX_DIR, "organic_post.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is False, "False positive! Detected normal post as ad!"


def test_peugeot_carousel_ad_is_detected():
    """
    Test: The 'peugeot.deutschland' carousel ad from manual_interrupt dump.
    is_ad MUST return True.
    """
    xml_path = os.path.join(FIX_DIR, "peugeot_ad.xml")
    with open(xml_path, "r") as f:
        xml = f.read()

    assert is_ad(xml) is True, "Failed to detect Peugeot Carousel ad from manual dump!"
