diff options
author | Martin Fischer <martin@push-f.com> | 2025-03-22 21:52:51 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-03-23 20:54:46 +0100 |
commit | bb1f5e7d97b5a2d63024071dbed91697e8bc8bcc (patch) | |
tree | 4cd0af9714866fe57a997e4c3faa04fb3d426ea8 | |
parent | 8388b50e1a16483edcb508bcd7a513bf55b50391 (diff) |
test: add basic tests for parse_proposal
-rw-r--r-- | default.nix | 4 | ||||
-rw-r--r-- | tests/test_proposals.py | 56 |
2 files changed, 60 insertions, 0 deletions
diff --git a/default.nix b/default.nix index d923d2e..fc9e1b0 100644 --- a/default.nix +++ b/default.nix @@ -24,4 +24,8 @@ buildPythonApplication rec { mkdir -p $out/share/osm-proposals cp -r ${./static}/. $out/share/osm-proposals/ ''; + + nativeCheckInputs = [ + pytestCheckHook + ]; } diff --git a/tests/test_proposals.py b/tests/test_proposals.py new file mode 100644 index 0000000..e11c1be --- /dev/null +++ b/tests/test_proposals.py @@ -0,0 +1,56 @@ +import textwrap + +import pytest + +from osm_proposals import proposals + + +@pytest.mark.parametrize("has_heading", (True, False)) +@pytest.mark.parametrize("has_text", (True, False)) +def test_parse_proposal_with_template(has_heading: bool, has_text: bool): + proposal = proposals.parse_proposal( + "some title", + textwrap.dedent( + ''' + {{Proposal page + | name = some name + | status = draft + | user = SomeUser + | key = <!-- The key of the proposed new tag, if relevant --> + | value = <!-- The value of the proposed new tag, if relevant --> + | tagging = <!-- If your proposal is about multiple tags, you may link them here like: {{tag|foo|bar}}, {{tag|bar}} --> + | type = <!-- node, way, area, relation ({{IconNode}} / {{IconWay}} / {{IconArea}} / {{IconRelation}}) --> + | definition = <!-- A short, clear definition of the feature or property which the new tag represents --> + | taginfo = yes <!-- yes / no: to show taginfo statistics box --> + | appearance = <!-- A possible rendering, if relevant – optional --> + | draftStartDate = 2022-12-07 + | rfcStartDate = <!-- Date the RFC email is sent to the Tagging list: YYYY-MM-DD --> + | voteStartDate = <!-- YYYY-MM-DD 00:00:00 (UTC) – date voting starts: at least 2 weeks after RFC --> + | voteEndDate = <!-- YYYY-MM-DD 23:59:59 (UTC) – date voting will end: at least 2 weeks after start of voting --> + }} + ''' + f''' + {"== Heading ==" * has_heading} + {"Some text." * has_text} + ''' + ), + (), + ) + if not has_heading or not has_text: + assert proposal is None + else: + assert proposal == { + 'page_title': 'some title', + 'lang': None, + 'name': 'some name', + 'status': 'draft', + 'authors': 'SomeUser', + 'definition': None, + 'draft_start': '2022-12-07', + 'rfc_start': None, + 'vote_start': None, + } + + +def test_parse_proposal_without_template(): + assert proposals.parse_proposal("test", "nothing", ()) is None |