|
9 | 9 | from readthedocs.builds.storage import BuildMediaFileSystemStorage
|
10 | 10 | from readthedocs.projects.constants import GENERIC, MKDOCS, SPHINX
|
11 | 11 | from readthedocs.projects.models import HTMLFile, Project
|
| 12 | +from readthedocs.search.parsers import GenericParser |
12 | 13 |
|
13 | 14 | data_path = Path(__file__).parent.resolve() / "data"
|
14 | 15 |
|
@@ -344,3 +345,40 @@ def test_generic_pelican_default_theme(self, storage_open, storage_exists):
|
344 | 345 | parsed_json = [file.processed_json]
|
345 | 346 | expected_json = json.load(open(data_path / "pelican/out/default.json"))
|
346 | 347 | assert parsed_json == expected_json
|
| 348 | + |
| 349 | + @mock.patch.object(BuildMediaFileSystemStorage, "exists") |
| 350 | + @mock.patch.object(BuildMediaFileSystemStorage, "open") |
| 351 | + def test_truncate_content(self, storage_open, storage_exists): |
| 352 | + html_content = """ |
| 353 | + <!DOCTYPE html> |
| 354 | + <html> |
| 355 | + <head> |
| 356 | + <meta charset="utf-8"> |
| 357 | + <title>Title of the page</title> |
| 358 | + </head> |
| 359 | + <body> |
| 360 | + """ |
| 361 | + # More than ~1.5 MB of content |
| 362 | + html_content += "A" * (GenericParser.max_content_length + 100) + "!" + "B" * 1000 |
| 363 | + html_content += "</body></html>" |
| 364 | + storage_open.side_effect = self._mock_open(html_content) |
| 365 | + storage_exists.return_value = True |
| 366 | + |
| 367 | + self.version.save() |
| 368 | + |
| 369 | + page_file = get( |
| 370 | + HTMLFile, |
| 371 | + project=self.project, |
| 372 | + version=self.version, |
| 373 | + path="page.html", |
| 374 | + ) |
| 375 | + |
| 376 | + parsed_json = page_file.processed_json |
| 377 | + assert parsed_json["path"] == "page.html" |
| 378 | + assert parsed_json["title"] == "Title of the page" |
| 379 | + assert len(parsed_json["sections"]) == 1 |
| 380 | + section = parsed_json["sections"][0] |
| 381 | + assert section["title"] == "Title of the page" |
| 382 | + assert len(section["content"]) <= GenericParser.max_content_length |
| 383 | + assert section["content"].startswith("A") |
| 384 | + assert not section["content"].endswith("B") |
0 commit comments