✨ Suppression de la partie légal
This commit is contained in:
1 parent
0c5189d9ca
commit
d0a95adeb9
36 files changed
+73
-572
No files matched your search
@@ -7,7 +7,7 @@ from scalper.cleaner import clean_chapter, detect_language
|
||||
class TestCleaner(unittest.TestCase):
|
||||
def setUp(self):
|
||||
raw = (resources.files("scalper") / "data" / "demo" / "chapter-1.html").read_text(encoding="utf-8")
|
||||
self.chapter = clean_chapter(raw, {"source": "demo", "license": "fixture"})
|
||||
self.chapter = clean_chapter(raw, {"source": "demo"})
|
||||
|
||||
def test_boilerplate_removed(self):
|
||||
text = self.chapter.full_text().lower()
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from scalper import legal
|
||||
|
||||
|
||||
class TestLegal(unittest.TestCase):
|
||||
def test_demo_allowed(self):
|
||||
v = legal.check_source("demo")
|
||||
self.assertTrue(v.allowed)
|
||||
|
||||
def test_mangas_origines_blocked(self):
|
||||
for url in ("https://mangas-origines.fr/", "https://www.mangas-origines.fr/manga/x", "mangas-origines.fr"):
|
||||
v = legal.check_source(url)
|
||||
self.assertFalse(v.allowed, url)
|
||||
self.assertIn("blocage", v.reasons[0])
|
||||
|
||||
def test_keiyoushi_extensions_blocked(self):
|
||||
for url in ("https://keiyoushi.github.io", "https://keiyoushi.github.io/extensions", "keiyoushi.com"):
|
||||
v = legal.check_source(url)
|
||||
self.assertFalse(v.allowed, url)
|
||||
self.assertIn("blocage", v.reasons[0])
|
||||
|
||||
def test_unknown_domain_blocked(self):
|
||||
v = legal.check_source("https://site-inconnu.example/manga")
|
||||
self.assertFalse(v.allowed)
|
||||
|
||||
def test_mangadex_trusted(self):
|
||||
v = legal.check_source("api.mangadex.org")
|
||||
self.assertTrue(v.allowed)
|
||||
self.assertIn("MangaDex", v.license)
|
||||
|
||||
def test_domain_of(self):
|
||||
self.assertEqual(legal.domain_of("https://WWW.Example.COM/x"), "www.example.com")
|
||||
self.assertEqual(legal.domain_of("demo"), "demo")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -3,7 +3,6 @@ import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from scalper import legal
|
||||
from scalper.ocr import FakeOCR, ocr_chapter
|
||||
from scalper.typeset import replace_texts, typeset_chapter, wrap_text
|
||||
|
||||
@@ -15,17 +14,6 @@ except ImportError:
|
||||
HAS_PIL = False
|
||||
|
||||
|
||||
class TestDerivativeGate(unittest.TestCase):
|
||||
def test_demo_license_allows_derivatives(self):
|
||||
self.assertTrue(legal.allows_derivatives("fixture de test interne (texte inventé, domaine public)"))
|
||||
|
||||
def test_mangadex_license_refuses_derivatives(self):
|
||||
self.assertFalse(legal.allows_derivatives("API officielle MangaDex (données publiques ; images selon licence de l'œuvre)"))
|
||||
|
||||
def test_cc_license_allows_derivatives(self):
|
||||
self.assertTrue(legal.allows_derivatives("Creative Commons CC BY 4.0"))
|
||||
|
||||
|
||||
@unittest.skipUnless(HAS_PIL, "Pillow requis")
|
||||
class TestOCRTypeset(unittest.TestCase):
|
||||
def _make_image(self, path: Path, size=(300, 120)) -> None:
|
||||
|
||||
@@ -10,11 +10,6 @@ from scalper.sources import get_adapter
|
||||
|
||||
|
||||
class TestPipeline(unittest.TestCase):
|
||||
def test_blocked_source(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
res = pipeline.run_pipeline("https://mangas-origines.fr", "x", "fr", out_root=tmp, mock_llm=True)
|
||||
self.assertEqual(res["status"], "blocked")
|
||||
|
||||
def test_demo_end_to_end_mock_llm(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
res = pipeline.run_pipeline("demo", "demo-1", "fr", out_root=tmp, mock_llm=True)
|
||||
@@ -37,14 +32,14 @@ class TestPipeline(unittest.TestCase):
|
||||
|
||||
|
||||
class TestExporter(unittest.TestCase):
|
||||
def test_exports_contain_license(self):
|
||||
def test_exports(self):
|
||||
ch = Chapter(
|
||||
meta={"source": "demo", "license": "fixture test", "fetched_at": "2026-01-01", "url": "demo://x", "title": "T", "language": "fr"},
|
||||
meta={"source": "demo", "fetched_at": "2026-01-01", "url": "demo://x", "title": "T", "language": "fr"},
|
||||
blocks=[Block(index=0, type="narration", text="Bonjour"), Block(index=1, type="image", image="images/p.png")],
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
md = export_chapter(ch, "md", Path(tmp))
|
||||
self.assertIn("Source et licence", md.read_text(encoding="utf-8"))
|
||||
self.assertIn("Bonjour", md.read_text(encoding="utf-8"))
|
||||
self.assertIn("[IMG:1]", md.read_text(encoding="utf-8"))
|
||||
js = export_chapter(ch, "json", Path(tmp))
|
||||
self.assertEqual(json.loads(js.read_text(encoding="utf-8"))["blocks"][1]["image"], "images/p.png")
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from scalper import legal
|
||||
|
||||
ALLOW_ALL = "User-agent: *\nAllow: /\n"
|
||||
|
||||
|
||||
class TestCustomSourceRegistry(unittest.TestCase):
|
||||
def setUp(self):
|
||||
legal.CUSTOM_SOURCES.clear()
|
||||
|
||||
def tearDown(self):
|
||||
legal.CUSTOM_SOURCES.clear()
|
||||
|
||||
def test_custom_source_with_license_allowed(self):
|
||||
with mock.patch.object(legal, "_fetch_robots_txt", return_value=ALLOW_ALL):
|
||||
legal.register_custom_sources({"exemple-cc.fr": {"license": "CC BY 4.0", "kind": "html"}})
|
||||
v = legal.check_source("https://exemple-cc.fr/manga/x")
|
||||
self.assertTrue(v.allowed)
|
||||
self.assertEqual(v.license, "CC BY 4.0")
|
||||
|
||||
def test_custom_source_without_license_rejected(self):
|
||||
with self.assertRaises(ValueError):
|
||||
legal.register_custom_sources({"pirate.example": {"kind": "html"}})
|
||||
self.assertNotIn("pirate.example", legal.CUSTOM_SOURCES)
|
||||
|
||||
def test_blocklist_wins_over_config(self):
|
||||
with mock.patch.object(legal, "_fetch_robots_txt", return_value=ALLOW_ALL):
|
||||
legal.register_custom_sources(
|
||||
{"mangas-origines.fr": {"license": "CC BY 4.0"}, "keiyoushi.github.io": {"license": "CC BY 4.0"}}
|
||||
)
|
||||
for url in ("https://mangas-origines.fr/", "https://keiyoushi.github.io/"):
|
||||
v = legal.check_source(url)
|
||||
self.assertFalse(v.allowed, url)
|
||||
|
||||
def test_unknown_source_still_blocked(self):
|
||||
v = legal.check_source("https://inconnu.example/")
|
||||
self.assertFalse(v.allowed)
|
||||
|
||||
def test_robots_disallow_blocks_custom_source(self):
|
||||
robots = "User-agent: *\nDisallow: /manga/\n"
|
||||
with mock.patch.object(legal, "_fetch_robots_txt", return_value=robots):
|
||||
legal.register_custom_sources({"exemple.fr": {"license": "Domaine public"}})
|
||||
v = legal.check_source("https://exemple.fr/manga/x", path="/manga/x")
|
||||
self.assertFalse(v.allowed)
|
||||
self.assertIn("robots.txt interdit", v.reasons[-1])
|
||||
|
||||
def test_demo_still_allowed(self):
|
||||
self.assertTrue(legal.check_source("demo").allowed)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -51,17 +51,6 @@ class TestServer(unittest.TestCase):
|
||||
self.assertIn("text/html", r.headers.get("Content-Type", ""))
|
||||
self.assertIn("Scalper", body)
|
||||
self.assertIn("/run", body)
|
||||
self.assertIn("/check-source", body)
|
||||
|
||||
def test_check_source_demo_allowed(self):
|
||||
status, body = self._get("/check-source?source=demo")
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(body["verdict"], "allowed")
|
||||
|
||||
def test_check_source_blocked(self):
|
||||
status, body = self._get("/check-source?source=https://mangas-origines.fr")
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(body["verdict"], "blocked")
|
||||
|
||||
def test_run_demo_mock_llm(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -70,11 +59,6 @@ class TestServer(unittest.TestCase):
|
||||
self.assertEqual(body["status"], "done")
|
||||
self.assertEqual(len(body["chapters"]), 2)
|
||||
|
||||
def test_run_blocked_source_returns_403(self):
|
||||
status, body = self._post("/run", {"source": "https://keiyoushi.github.io", "series": "x", "lang": "fr", "mock_llm": True})
|
||||
self.assertEqual(status, 403)
|
||||
self.assertEqual(body["status"], "blocked")
|
||||
|
||||
def test_run_missing_field_400(self):
|
||||
status, body = self._post("/run", {"source": "demo"})
|
||||
self.assertEqual(status, 400)
|
||||
|
||||
@@ -9,7 +9,7 @@ from scalper.translator import FakeLLM, chunk_blocks, translate_chapter
|
||||
|
||||
def demo_chapter():
|
||||
raw = (resources.files("scalper") / "data" / "demo" / "chapter-1.html").read_text(encoding="utf-8")
|
||||
return clean_chapter(raw, {"source": "demo", "license": "fixture", "language": "en"})
|
||||
return clean_chapter(raw, {"source": "demo", "language": "en"})
|
||||
|
||||
|
||||
class TestTranslator(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user