|
| 1 | +from unittest import mock |
| 2 | + |
1 | 3 | import docutils
|
2 | 4 | import pytest
|
3 | 5 | import sphinx
|
4 | 6 | from django.core.cache import cache
|
5 | 7 | from django.urls import reverse
|
6 | 8 | from packaging.version import Version
|
7 | 9 |
|
8 |
| -from .utils import get_anchor_link_title, srcdir |
| 10 | +from .utils import compare_content_without_blank_lines, get_anchor_link_title, srcdir |
9 | 11 |
|
10 | 12 |
|
11 | 13 | @pytest.mark.django_db
|
@@ -40,16 +42,49 @@ def test_default_main_section(self, app, client, requests_mock):
|
40 | 42 | # The output is different because docutils is outputting this,
|
41 | 43 | # and we're not sanitizing it, but just passing it through.
|
42 | 44 | if Version(docutils.__version__) >= Version("0.17"):
|
43 |
| - content = f'<div class="body" role="main">\n \n <section id="title">\n<h1>Title<a class="headerlink" href="https://docs.project.com#title" title="{title}">¶</a></h1>\n<p>This is an example page used to test EmbedAPI parsing features.</p>\n<section id="sub-title">\n<h2>Sub-title<a class="headerlink" href="https://docs.project.com#sub-title" title="{title}">¶</a></h2>\n<p>This is a reference to <a class="reference internal" href="https://docs.project.com#sub-title"><span class="std std-ref">Sub-title</span></a>.</p>\n</section>\n<section id="manual-reference-section">\n<span id="manual-reference"></span><h2>Manual Reference Section<a class="headerlink" href="https://docs.project.com#manual-reference-section" title="{title}">¶</a></h2>\n<p>This is a reference to a manual reference <a class="reference internal" href="https://docs.project.com#manual-reference"><span class="std std-ref">Manual Reference Section</span></a>.</p>\n</section>\n</section>\n\n\n </div>' |
| 45 | + content = f""" |
| 46 | + <div class="body" role="main"> |
| 47 | + <section id="title"> |
| 48 | + <h1>Title<a class="headerlink" href="https://docs.project.com#title" title="{title}">¶</a></h1> |
| 49 | + <p>This is an example page used to test EmbedAPI parsing features.</p> |
| 50 | + <section id="sub-title"> |
| 51 | + <h2>Sub-title<a class="headerlink" href="https://docs.project.com#sub-title" title="{title}">¶</a></h2> |
| 52 | + <p>This is a reference to <a class="reference internal" href="https://docs.project.com#sub-title"><span class="std std-ref">Sub-title</span></a>.</p> |
| 53 | + </section> |
| 54 | + <section id="manual-reference-section"> |
| 55 | + <span id="manual-reference"></span><h2>Manual Reference Section<a class="headerlink" href="https://docs.project.com#manual-reference-section" title="{title}">¶</a></h2> |
| 56 | + <p>This is a reference to a manual reference <a class="reference internal" href="https://docs.project.com#manual-reference"><span class="std std-ref">Manual Reference Section</span></a>.</p> |
| 57 | + </section> |
| 58 | + </section> |
| 59 | + <div class="clearer"></div> |
| 60 | + </div> |
| 61 | + """ |
44 | 62 | else:
|
45 |
| - content = f'<div class="body" role="main">\n \n <div class="section" id="title">\n<h1>Title<a class="headerlink" href="https://docs.project.com#title" title="{title}">¶</a></h1>\n<p>This is an example page used to test EmbedAPI parsing features.</p>\n<div class="section" id="sub-title">\n<h2>Sub-title<a class="headerlink" href="https://docs.project.com#sub-title" title="{title}">¶</a></h2>\n<p>This is a reference to <a class="reference internal" href="https://docs.project.com#sub-title"><span class="std std-ref">Sub-title</span></a>.</p>\n</div>\n<div class="section" id="manual-reference-section">\n<span id="manual-reference"></span><h2>Manual Reference Section<a class="headerlink" href="https://docs.project.com#manual-reference-section" title="{title}">¶</a></h2>\n<p>This is a reference to a manual reference <a class="reference internal" href="https://docs.project.com#manual-reference"><span class="std std-ref">Manual Reference Section</span></a>.</p>\n</div>\n</div>\n\n\n </div>' |
46 |
| - |
47 |
| - assert response.json() == { |
| 63 | + content = """ |
| 64 | + <div class="body" role="main"> |
| 65 | + <div class="section" id="title"> |
| 66 | + <h1>Title<a class="headerlink" href="https://docs.project.com#title" title="{title}">¶</a></h1> |
| 67 | + <p>This is an example page used to test EmbedAPI parsing features.</p> |
| 68 | + <div class="section" id="sub-title"> |
| 69 | + <h2>Sub-title<a class="headerlink" href="https://docs.project.com#sub-title" title="{title}">¶</a></h2> |
| 70 | + <p>This is a reference to <a class="reference internal" href="https://docs.project.com#sub-title"><span class="std std-ref">Sub-title</span></a>.</p> |
| 71 | + </div> |
| 72 | + <div class="section" id="manual-reference-section"> |
| 73 | + <span id="manual-reference"></span><h2>Manual Reference Section<a class="headerlink" href="https://docs.project.com#manual-reference-section" title="{title}">¶</a></h2> |
| 74 | + <p>This is a reference to a manual reference <a class="reference internal" href="https://docs.project.com#manual-reference"><span class="std std-ref">Manual Reference Section</span></a>.</p> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + """ |
| 79 | + |
| 80 | + json_response = response.json() |
| 81 | + assert json_response == { |
48 | 82 | "url": "https://docs.project.com",
|
49 | 83 | "fragment": None,
|
50 |
| - "content": content, |
| 84 | + "content": mock.ANY, |
51 | 85 | "external": True,
|
52 | 86 | }
|
| 87 | + compare_content_without_blank_lines(json_response["content"], content) |
53 | 88 |
|
54 | 89 | @pytest.mark.sphinx("html", srcdir=srcdir, freshenv=True)
|
55 | 90 | def test_specific_identifier(self, app, client, requests_mock):
|
|
0 commit comments