diff --git a/blurb_it/util.py b/blurb_it/util.py index 4cc536a..5d84df9 100644 --- a/blurb_it/util.py +++ b/blurb_it/util.py @@ -9,6 +9,8 @@ async def get_misc_news_filename(issue_number, section, body): + if " " in section: + raise ValueError(f"Use underscores not spaces in section name: {section}") date = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) nonce = await nonceify(body) path = f"Misc/NEWS.d/next/{section}/{date}.gh-issue-{issue_number}.{nonce}.rst" diff --git a/templates/add_blurb.html b/templates/add_blurb.html index 87f1ae3..25fe9d0 100644 --- a/templates/add_blurb.html +++ b/templates/add_blurb.html @@ -38,7 +38,7 @@

📜🤖 Blurb it again?

diff --git a/tests/test_util.py b/tests/test_util.py index 8de474e..00dcf2a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -57,6 +57,28 @@ async def test_get_misc_news_filename(): assert path.endswith(".gh-issue-123.Ps4kgC.rst") +async def test_get_misc_news_filename_sections_with_dashes(): + path = await util.get_misc_news_filename( + issue_number=123, + section="Core_and_Builtins", + body="Lorem ipsum dolor amet flannel squid normcore tbh raclette enim", + ) + + assert path.startswith("Misc/NEWS.d/next/Core_and_Builtins/") + + +async def test_get_misc_news_filename_sections_with_space(): + with pytest.raises( + ValueError, + match="Use underscores not spaces in section name: Core and Builtins", + ): + await util.get_misc_news_filename( + issue_number=123, + section="Core and Builtins", + body="Lorem ipsum dolor amet flannel squid normcore tbh raclette enim", + ) + + async def test_has_session(): request = mock_request_session()