Skip to content

Commit

Permalink
Add some extra tests for code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
TOUFIKIzakarya committed Jul 30, 2024
1 parent e6c4e65 commit 2257df0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import demistomock as demisto
from SekoiaXDRAddComment import get_username, post_comment # type: ignore
from SekoiaXDRAddComment import get_username, post_comment, main # type: ignore


def test_get_username(mocker):
Expand All @@ -16,3 +16,18 @@ def test_post_comment(mocker):
]
mocker.patch.object(demisto, "executeCommand", return_value=output_data)
assert not post_comment("1", "test", "admin")


def test_main(mocker):
mocker.patch.object(
demisto, "args", return_value={"short_id": "1", "comment": "test"}
)
mocker.patch("SekoiaXDRAddComment.get_username", return_value="admin")
mocker.patch("SekoiaXDRAddComment.post_comment", return_value=None)
mocker.patch.object(demisto, "results")

main()
assert (
demisto.results.call_args[0][0]["HumanReadable"]
== "### Comment added by admin:\n test"
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import demistomock as demisto
import SekoiaXDRCloseAlert # type: ignore
from SekoiaXDRCloseAlert import get_status_name, get_username, post_closure_comment, close_alert # type: ignore
from SekoiaXDRCloseAlert import get_status_name, get_username, post_closure_comment, close_alert, main # type: ignore


def test_get_status_name(mocker):
Expand Down Expand Up @@ -45,3 +45,21 @@ def test_close_alert(mocker):
close_alert("1", "false", "Out", "reason", "notes", "admin")
except Exception as e:
assert str(e) == "**** The alert is already closed or rejected. ****"


def test_main(mocker):
mocker.patch.object(
demisto,
"incidents",
return_value=[
{
"dbotMirrorDirection": "Out",
"CustomFields": {"alertid": "1"},
"owner": "admin",
}
],
)
mocker.patch.object(demisto, "getArg", return_value="admin")
mocker.patch.object(SekoiaXDRCloseAlert, "close_alert", return_value=None)

assert main() is None
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import demistomock as demisto
from SekoiaXDRPrintCase import get_case_info, create_case_object # type: ignore
from SekoiaXDRPrintCase import get_case_info, create_case_object, main # type: ignore


def test_create_case_object():
Expand Down Expand Up @@ -65,3 +65,26 @@ def test_get_case_info(mocker):
assert "title1" in get_case_info("1")
assert "title2" in get_case_info("1")
assert "1, 2, 3" in get_case_info("1")


def test_main(mocker):
mocker.patch.object(
demisto, "incident", return_value={"CustomFields": {"caseid": "1"}}
)
mocker.patch(
"SekoiaXDRPrintCase.get_case_info",
return_value="### Case Info:\n\
|title|description|status|priority|related alerts|\n\
|---|---|---|---|---|\n\
| title1 | description1 | Status1 | Priority1 | 1, 2, 3 |\n",
)
mocker.patch.object(demisto, "results")

main()
assert (
demisto.results.call_args[0][0]["HumanReadable"]
== "### Case Info:\n\
|title|description|status|priority|related alerts|\n\
|---|---|---|---|---|\n\
| title1 | description1 | Status1 | Priority1 | 1, 2, 3 |\n"
)
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ def test_get_comments_no_comments(mocker):
return_value=[{"Type": 3, "Contents": comments_output}],
)
assert "There is no comments in this alert" in get_comments("alert_id")


def test_main(mocker):
mocker.patch.object(
demisto, "incident", return_value={"CustomFields": {"alertid": "alert_id"}}
)
mocker.patch(
"SekoiaXDRPrintComments.get_comments", return_value="Comments: testcomment"
)
mocker.patch.object(demisto, "results")

main()
assert demisto.results.call_args[0][0]["HumanReadable"] == "Comments: testcomment"

0 comments on commit 2257df0

Please sign in to comment.