Skip to content

Commit

Permalink
Add testing for the comment processor module
Browse files Browse the repository at this point in the history
  • Loading branch information
penguineer committed May 5, 2022
1 parent c90b0a0 commit 4e8c7d2
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions test/test_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
""" Test the processor module """

import pytest

# noinspection PyUnresolvedReferences
# noinspection PyPackageRequirements
import form
# noinspection PyUnresolvedReferences
# noinspection PyPackageRequirements
import processor


class TestCommentFormatter:
def test_null_comment(self):
with pytest.raises(ValueError):
processor.CommentFormatter(None)

def test_full_comment(self):
values = {
"slug": "1",
"name": "2",
"email": "3",
"url": "4",
"message": "5"
}
cmt = form.Comment(**values)
formatter = processor.CommentFormatter(cmt)

assert formatter.branch_name() == "comment-" + str(cmt.cid)
assert formatter.file_content() == """\
id: """ + str(cmt.cid) + """
name: 2
email: 3
url: 4
date: """ + cmt.date + """
message: |
5
"""
assert formatter.commit_path() == "_data/comments/" + cmt.slug + "/" + str(cmt.cid) + ".yml"
assert formatter.commit_message() == "Comment " + str(cmt.cid)
assert formatter.pr_title() == "Blog Comment " + str(cmt.cid)
assert formatter.pr_body() == """\
Please consider this blog comment.
## Meta Data
Slug: 1
Date: """ + cmt.date + """
Name: 2
E-Mail: 3
URL: 4
## Message
5"""

def test_multiline_comment(self):
values = {
"slug": "1",
"name": "2",
"email": "3",
"url": "4",
"message": """\
This
is
a
multiline
message.
"""
}
cmt = form.Comment(**values)
formatter = processor.CommentFormatter(cmt)

assert formatter.file_content() == """\
id: """ + str(cmt.cid) + """
name: 2
email: 3
url: 4
date: """ + cmt.date + """
message: |
This
is
a
multiline
message.
"""

assert formatter.pr_body() == """\
Please consider this blog comment.
## Meta Data
Slug: 1
Date: """ + cmt.date + """
Name: 2
E-Mail: 3
URL: 4
## Message
This
is
a
multiline
message.
"""


class TestCommentProcessor:
def test_null_cfg(self):
with pytest.raises(ValueError):
processor.CommentProcessor(None)

# TODO mock tests here

0 comments on commit 4e8c7d2

Please sign in to comment.