|
| 1 | +import textwrap |
| 2 | + |
| 3 | +from readme.markdown import render |
| 4 | + |
| 5 | + |
| 6 | +def test_markdown_001(): |
| 7 | + markdown_markup = 'Hello' |
| 8 | + out, rendered = render(markdown_markup) |
| 9 | + assert rendered |
| 10 | + assert out == '<p>Hello</p>' |
| 11 | + |
| 12 | + |
| 13 | +def test_markdown_002(): |
| 14 | + markdown_markup = textwrap.dedent("""\ |
| 15 | + # Required packages |
| 16 | + To run the PyPI software, you need Python 2.5+ and PostgreSQL |
| 17 | + # Quick development setup |
| 18 | + Make sure you ...""") |
| 19 | + expected_html = textwrap.dedent("""\ |
| 20 | + <h1>Required packages</h1> |
| 21 | + <p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p> |
| 22 | + <h1>Quick development setup</h1> |
| 23 | + <p>Make sure you ...</p>""") |
| 24 | + out, rendered = render(markdown_markup) |
| 25 | + assert rendered |
| 26 | + assert out == expected_html |
| 27 | + |
| 28 | + |
| 29 | +def test_markdown_003(): |
| 30 | + markdown_markup = textwrap.dedent("""\ |
| 31 | + Then, you can create a *development environment* like this, |
| 32 | + if you have **virtualenv** installed: |
| 33 | +
|
| 34 | + $ virtualenv --no-site-packages . |
| 35 | + $ pip install -r requirements.txt |
| 36 | +
|
| 37 | + Then you can launch the server using the `pypi.wsgi` script: |
| 38 | +
|
| 39 | + $ python pypi.wsgi |
| 40 | + Serving on port 8000... |
| 41 | +
|
| 42 | + PyPI will be available in your browser at http://localhost:8000 |
| 43 | + """) |
| 44 | + expected_html = '\n'.join([ |
| 45 | + '<p>Then, you can create a <em>development environment</em> ' |
| 46 | + 'like this,', |
| 47 | + 'if you have <strong>virtualenv</strong> installed:</p>', |
| 48 | + '<pre><code>$ virtualenv --no-site-packages .', |
| 49 | + '$ pip install -r requirements.txt', |
| 50 | + '</code></pre>', |
| 51 | + '<p>Then you can launch the server using the ' |
| 52 | + '<code>pypi.wsgi</code> script:</p>', |
| 53 | + '<pre><code>$ python pypi.wsgi', |
| 54 | + 'Serving on port 8000...', |
| 55 | + '</code></pre>', |
| 56 | + '<p>PyPI will be available in your browser at ' |
| 57 | + 'http://localhost:8000</p>']) |
| 58 | + out, rendered = render(markdown_markup) |
| 59 | + assert rendered |
| 60 | + assert out == expected_html |
| 61 | + |
| 62 | + |
| 63 | +def test_markdown_004(): |
| 64 | + markdown_markup = 'http://mymalicioussite.com/' |
| 65 | + out, rendered = render(markdown_markup) |
| 66 | + expected_html = '<p>http://mymalicioussite.com/</p>' |
| 67 | + assert rendered |
| 68 | + assert out == expected_html |
| 69 | + |
| 70 | + |
| 71 | +def test_markdown_005(): |
| 72 | + markdown_markup = '<a href="http://mymalicioussite.com/">Click here</a>' |
| 73 | + out, rendered = render(markdown_markup) |
| 74 | + expected_htmls = [ |
| 75 | + ''.join(['<p><a rel="nofollow" href="http://mymalicioussite.com/">', |
| 76 | + 'Click here</a></p>']), |
| 77 | + ''.join(['<p><a href="http://mymalicioussite.com/" rel="nofollow">', |
| 78 | + 'Click here</a></p>']), |
| 79 | + ] |
| 80 | + assert rendered |
| 81 | + assert out in expected_htmls |
| 82 | + |
| 83 | + |
| 84 | +def test_markdown_006(): |
| 85 | + markdown_markup = """\ |
| 86 | + <iframe src="http://mymalicioussite.com/">Click here</iframe> |
| 87 | + """.strip() |
| 88 | + out, rendered = render(markdown_markup) |
| 89 | + expected_html = ''.join([ |
| 90 | + '<iframe src="http://mymalicioussite.com/">' |
| 91 | + 'Click here</iframe>']) |
| 92 | + assert rendered |
| 93 | + assert out == expected_html |
| 94 | + |
| 95 | + |
| 96 | +def test_markdown_007(): |
| 97 | + markdown_markup = textwrap.dedent("""\ |
| 98 | + <script> |
| 99 | + alert("Hello"); |
| 100 | + </script>""") |
| 101 | + out, rendered = render(markdown_markup) |
| 102 | + expected_html = textwrap.dedent("""\ |
| 103 | + <script> |
| 104 | + alert("Hello"); |
| 105 | + </script>""") |
| 106 | + assert rendered |
| 107 | + assert out == expected_html |
0 commit comments