def test_analyze_pr_dangerous_content(): doc = { "doc": { "mdn_url": "/en-US/docs/Foo", "title": "Foo", "body": [ { "type": "prose", "value": { "content": """ <p> <a href="https://www.peterbe.com">Peterbe.com</a> <a href="">Empty href</a> </p> """ }, } ], "source": {"github_url": "https://github.com/foo"}, } } with mock_build_directory(doc) as build_directory: comment = analyze_pr( build_directory, dict(DEFAULT_CONFIG, analyze_dangerous_content=True) ) assert "## External URLs" in comment assert " - <https://www.peterbe.com> (1 time)" in comment
def test_analyze_pr_flaws(): doc = { "doc": { "mdn_url": "/en-US/docs/Foo", "title": "Foo", "flaws": { "faux_pas": [ {"explanation": "Socks in sandals"}, {"explanation": "Congrats on losing your cat"}, ], }, "source": {"github_url": "https://github.com/foo"}, } } no_flaws_doc = { "doc": { "mdn_url": "/en-US/docs/Bar", "title": "Bar", "flaws": {}, "source": {"github_url": "https://github.com/bar"}, } } with mock_build_directory(no_flaws_doc, doc) as build_directory: comment = analyze_pr(build_directory, dict(DEFAULT_CONFIG, analyze_flaws=True)) assert "## Flaws" in comment assert "1 document with no flaws that don't need to be listed" in comment assert "Flaw count: 2" in comment assert len(comment.split("\n---\n")) == 1 assert "- **faux_pas**:" in comment assert " - `Socks in sandals`" in comment assert " - `Congrats on losing your cat`" in comment
def test_analyze_pr_prefix(): doc = {"doc": {"mdn_url": "/en-US/docs/Foo"}} with mock_build_directory(doc) as build_directory: comment = analyze_pr(build_directory, dict(DEFAULT_CONFIG, prefix="pr007")) assert "## Preview deployment URLs" in comment assert "- <https://pr007.content.dev.mdn.mozit.cloud/en-US/docs/Foo>" in comment
def test_analyze_pr_prefix_and_postcomment(mocked_github): doc = {"doc": {"mdn_url": "/en-US/docs/Foo"}} with mock_build_directory(doc) as build_directory: comment = analyze_pr( build_directory, dict(DEFAULT_CONFIG, prefix="pr007", pr_number=123, github_token="abc123"), ) assert "## Preview URLs" in comment assert "- <https://pr007.content.dev.mdn.mozit.cloud/en-US/docs/Foo>" in comment mocked_github().get_repo().get_issue().create_comment.assert_called()
def test_analyze_pr_dangerous_content_with_diff_file_not_matched(): doc = { "doc": { "mdn_url": "/en-US/docs/Foo", "title": "Foo", "body": [ { "type": "prose", "value": { "content": """ <p> <a href="https://www.mozilla.org">Mozilla.org</a> </p> """ }, } ], "source": { "github_url": "https://github.com/foo", "folder": "en-us/mozilla/firefox/releases/4", "filename": "index.html", }, } } with mock_build_directory(doc) as build_directory: diff_file = Path(__file__).parent / "sample.diff" comment = analyze_pr( build_directory, dict( DEFAULT_CONFIG, analyze_dangerous_content=True, diff_file=diff_file, ), ) assert "## External URLs" in comment assert "No *new* external URLs" in comment assert "https://www.mozilla.org" not in comment