-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing for the comment processor module
- Loading branch information
1 parent
c90b0a0
commit 4e8c7d2
Showing
1 changed file
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |