import pathlib
import sys


SCRIPTS_DIR = pathlib.Path(__file__).resolve().parents[1] / "scripts"
sys.path.insert(0, str(SCRIPTS_DIR))

import staging_manager


def test_staged_content_is_isolated_by_course_id(tmp_path, monkeypatch):
    monkeypatch.setattr(staging_manager, "get_plugin_root", lambda: str(tmp_path))
    course_a = "course-A"
    course_b = "course-B"
    obj_id = "module-1"

    result_a = staging_manager.stage(
        course_a, "pages", obj_id, "<h2>Course A Content</h2>",
        validate=False
    )
    result_b = staging_manager.stage(
        course_b, "pages", obj_id, "<h2>Course B Content</h2>",
        validate=False
    )

    assert staging_manager.get_staged(
        course_a, "pages", obj_id
    ) == "<h2>Course A Content</h2>"
    assert staging_manager.get_staged(
        course_b, "pages", obj_id
    ) == "<h2>Course B Content</h2>"

    assert pathlib.Path(result_a["path"]) == (
        tmp_path / "courses" / course_a / "staging" / "pages" / "module-1.html"
    )
    assert pathlib.Path(result_b["path"]) == (
        tmp_path / "courses" / course_b / "staging" / "pages" / "module-1.html"
    )
    assert result_a["path"] != result_b["path"]
