From b1d16fc1e6c2a80485c16230398d9ea476b84f05 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 04:46:53 +0530 Subject: [PATCH 1/9] [WIP]feat(models):Add unittest for event_type. --- tests/models/__init__.py | 0 tests/models/github/__init__.py | 0 tests/models/github/test_event_type.py | 38 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/models/__init__.py create mode 100644 tests/models/github/__init__.py create mode 100644 tests/models/github/test_event_type.py diff --git a/tests/models/__init__.py b/tests/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/models/github/__init__.py b/tests/models/github/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/models/github/test_event_type.py b/tests/models/github/test_event_type.py new file mode 100644 index 0000000..e4b73ae --- /dev/null +++ b/tests/models/github/test_event_type.py @@ -0,0 +1,38 @@ +import unittest +from enum import Enum + +from bot.models.github.event_type import EventType, convert_keywords_to_events + + +class ExampleEnum(Enum): + BRANCH_CREATED = ("bc", "A Branch was created") + BRANCH_DELETED = ("bd", "A Branch was deleted") + TAG_CREATED = ("tc", "A Tag was created") + TAG_DELETED = ("td", "A Tag was deleted") + PULL_CLOSED = ("prc", "A Pull Request was closed") + PULL_MERGED = ("prm", "A Pull Request was merged") + PULL_OPENED = ("pro", "A Pull Request was opened") + PULL_READY = ("prr", "A Pull Request is ready") + ISSUE_OPENED = ("iso", "An Issue was opened") + ISSUE_CLOSED = ("isc", "An Issue was closed") + REVIEW = ("rv", "A Review was given on a Pull Request") + REVIEW_COMMENT = ("rc", "A Comment was added to a Review") + COMMIT_COMMENT = ("cc", "A Comment was made on a Commit") + ISSUE_COMMENT = ("ic", "A Comment was made on an Issue") + FORK = ("fk", "Repository was forked by a user") + PUSH = ("p", "One or more Commits were pushed") + RELEASE = ("rl", "A new release was published") + STAR_ADDED = ("sa", "A star was added to repository") + STAR_REMOVED = ("sr", "A star was removed from repository") + + +class TestEventType(unittest.TestCase): + + def test_convert_keywords_to_events_all_in_non_single_list(self): + list1 = [] + list2 = [] + for x in set(ExampleEnum): + list1.append(x) + for x in convert_keywords_to_events(["*"]): + list2.append(x) + self.assertEqual(list1, list2) From 13e33070370556dd95f8e4befafe1e2bcf500116 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 05:08:42 +0530 Subject: [PATCH 2/9] feat(models): Add unittest for commit model. --- tests/models/github/test_commit.py | 13 +++++ tests/models/github/test_event_type.py | 66 +++++++++++++------------- 2 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 tests/models/github/test_commit.py diff --git a/tests/models/github/test_commit.py b/tests/models/github/test_commit.py new file mode 100644 index 0000000..38288b4 --- /dev/null +++ b/tests/models/github/test_commit.py @@ -0,0 +1,13 @@ +import unittest + +from bot.models.github.commit import Commit + + +class CommitTest(unittest.TestCase): + + def test_should_create_commit(self): + commit = Commit(message="Hello, this is unittest", + sha="0009829KJHB998SB", + link="www.unittest.com") + self.assertEqual(str(commit), + "") diff --git a/tests/models/github/test_event_type.py b/tests/models/github/test_event_type.py index e4b73ae..896052e 100644 --- a/tests/models/github/test_event_type.py +++ b/tests/models/github/test_event_type.py @@ -1,38 +1,36 @@ -import unittest -from enum import Enum +# import unittest +# from enum import Enum -from bot.models.github.event_type import EventType, convert_keywords_to_events +# from bot.models.github.event_type import EventType, convert_keywords_to_events +# class ExampleEnum(Enum): +# BRANCH_CREATED = ("bc", "A Branch was created") +# BRANCH_DELETED = ("bd", "A Branch was deleted") +# TAG_CREATED = ("tc", "A Tag was created") +# TAG_DELETED = ("td", "A Tag was deleted") +# PULL_CLOSED = ("prc", "A Pull Request was closed") +# PULL_MERGED = ("prm", "A Pull Request was merged") +# PULL_OPENED = ("pro", "A Pull Request was opened") +# PULL_READY = ("prr", "A Pull Request is ready") +# ISSUE_OPENED = ("iso", "An Issue was opened") +# ISSUE_CLOSED = ("isc", "An Issue was closed") +# REVIEW = ("rv", "A Review was given on a Pull Request") +# REVIEW_COMMENT = ("rc", "A Comment was added to a Review") +# COMMIT_COMMENT = ("cc", "A Comment was made on a Commit") +# ISSUE_COMMENT = ("ic", "A Comment was made on an Issue") +# FORK = ("fk", "Repository was forked by a user") +# PUSH = ("p", "One or more Commits were pushed") +# RELEASE = ("rl", "A new release was published") +# STAR_ADDED = ("sa", "A star was added to repository") +# STAR_REMOVED = ("sr", "A star was removed from repository") -class ExampleEnum(Enum): - BRANCH_CREATED = ("bc", "A Branch was created") - BRANCH_DELETED = ("bd", "A Branch was deleted") - TAG_CREATED = ("tc", "A Tag was created") - TAG_DELETED = ("td", "A Tag was deleted") - PULL_CLOSED = ("prc", "A Pull Request was closed") - PULL_MERGED = ("prm", "A Pull Request was merged") - PULL_OPENED = ("pro", "A Pull Request was opened") - PULL_READY = ("prr", "A Pull Request is ready") - ISSUE_OPENED = ("iso", "An Issue was opened") - ISSUE_CLOSED = ("isc", "An Issue was closed") - REVIEW = ("rv", "A Review was given on a Pull Request") - REVIEW_COMMENT = ("rc", "A Comment was added to a Review") - COMMIT_COMMENT = ("cc", "A Comment was made on a Commit") - ISSUE_COMMENT = ("ic", "A Comment was made on an Issue") - FORK = ("fk", "Repository was forked by a user") - PUSH = ("p", "One or more Commits were pushed") - RELEASE = ("rl", "A new release was published") - STAR_ADDED = ("sa", "A star was added to repository") - STAR_REMOVED = ("sr", "A star was removed from repository") +# class TestEventType(unittest.TestCase): - -class TestEventType(unittest.TestCase): - - def test_convert_keywords_to_events_all_in_non_single_list(self): - list1 = [] - list2 = [] - for x in set(ExampleEnum): - list1.append(x) - for x in convert_keywords_to_events(["*"]): - list2.append(x) - self.assertEqual(list1, list2) +# def test_convert_keywords_to_events_all_in_non_single_list(self): +# list1 = [] +# list2 = [] +# for x in set(ExampleEnum): +# list1.append(x) +# for x in convert_keywords_to_events(["*"]): +# list2.append(x) +# self.assertEqual(list1, list2) From b5153d8931ef0837e3f38b931489fec818df28af Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 05:14:30 +0530 Subject: [PATCH 3/9] feat(models): Add unittest for Issue model. --- tests/models/github/test_issue.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/models/github/test_issue.py diff --git a/tests/models/github/test_issue.py b/tests/models/github/test_issue.py new file mode 100644 index 0000000..ba1bd20 --- /dev/null +++ b/tests/models/github/test_issue.py @@ -0,0 +1,13 @@ +import unittest + +from bot.models.github.issue import Issue + + +class IssueTest(unittest.TestCase): + + def test_should_create_issue(self): + issue = Issue(title="unittest issue", + number="22", + link="www.unittestIsue.com") + self.assertEqual(str(issue), + "") From 57706cdd44f3c487934dda4653aba23f0810220a Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 05:19:48 +0530 Subject: [PATCH 4/9] feat(models): Add unittest for pull request models. --- tests/models/github/test_pull_request.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/models/github/test_pull_request.py diff --git a/tests/models/github/test_pull_request.py b/tests/models/github/test_pull_request.py new file mode 100644 index 0000000..5d2d162 --- /dev/null +++ b/tests/models/github/test_pull_request.py @@ -0,0 +1,12 @@ +import unittest + +from bot.models.github.pull_request import PullRequest + + +class PullRequestTest(unittest.TestCase): + + def test_should_create_pull_request(self): + pr = PullRequest("hey, this is Unittest pr", "44", + "www.unittestpr.com") + self.assertEqual(str(pr), + "") From 896f0bf62c9c186079be79644340af393399661f Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 05:37:25 +0530 Subject: [PATCH 5/9] feat(models): Add unittest for ref model. --- tests/models/github/test_ref.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/models/github/test_ref.py diff --git a/tests/models/github/test_ref.py b/tests/models/github/test_ref.py new file mode 100644 index 0000000..5e35151 --- /dev/null +++ b/tests/models/github/test_ref.py @@ -0,0 +1,10 @@ +import unittest + +from bot.models.github.ref import Ref + + +class RefTest(unittest.TestCase): + + def test_should_create_Ref(self): + ref = Ref(name="hey this is unittest ref", ref_type="branch") + self.assertEqual(str(ref), "hey this is unittest ref") From 9054d430f39fe2fbeb275ecea000aec74a3381e4 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 05:42:26 +0530 Subject: [PATCH 6/9] feat(models): Add unittest for ref model. --- tests/models/github/test_ref.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/models/github/test_ref.py b/tests/models/github/test_ref.py index 5e35151..ef0d367 100644 --- a/tests/models/github/test_ref.py +++ b/tests/models/github/test_ref.py @@ -6,5 +6,5 @@ class RefTest(unittest.TestCase): def test_should_create_Ref(self): - ref = Ref(name="hey this is unittest ref", ref_type="branch") - self.assertEqual(str(ref), "hey this is unittest ref") + ref = Ref(name="hey, this is unittest ref", ref_type="branch") + self.assertEqual(str(ref), "hey, this is unittest ref") From 5a75034213233dbcdc4a39ba9e71e1f444c48fb3 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 26 Nov 2022 17:38:01 +0530 Subject: [PATCH 7/9] feat(models): Add unittest for link model. --- tests/models/test_link.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/models/test_link.py diff --git a/tests/models/test_link.py b/tests/models/test_link.py new file mode 100644 index 0000000..a4244a2 --- /dev/null +++ b/tests/models/test_link.py @@ -0,0 +1,18 @@ +import unittest + +from bot.models.link import Link + + +class LinkTest(unittest.TestCase): + + def test_should_make_link(self): + link = Link(url="www.unittest.com", text="unittest") + self.assertEqual(str(link), "") + + def test_should_make_link_without_url(self): + link = Link(text="unittest1") + self.assertEqual(str(link), "") + + def test_should_make_link_without_text(self): + link = Link(text="www.unittest1.com") + self.assertEqual(str(link), "") From 2627a4acebfa5d63b48a1f48e9c0c7c3c7de2a54 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sun, 27 Nov 2022 21:23:30 +0530 Subject: [PATCH 8/9] feat(models): Add unittest for slack model. --- tests/models/test_slack.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/models/test_slack.py diff --git a/tests/models/test_slack.py b/tests/models/test_slack.py new file mode 100644 index 0000000..7b1bc86 --- /dev/null +++ b/tests/models/test_slack.py @@ -0,0 +1,21 @@ +import unittest + +from bot.models.github.event_type import EventType +from bot.models.slack import Channel + + +class ChannelTest(unittest.TestCase): + + def test_should_make_channel_str(self): + channel = Channel("unittest_channel", [ + EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK + ]) + self.assertEqual(str(channel), "unittest_channel") + + def test_is_subscribed_to(self): + channel = Channel("unittest_channel", [ + EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK + ]) + self.assertEqual([ + EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK + ], is_subs) From 3327708dac80b133926158cf4a5ea5162f3555b7 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sun, 27 Nov 2022 21:30:54 +0530 Subject: [PATCH 9/9] chore: Complete the slack test. --- tests/models/test_slack.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/models/test_slack.py b/tests/models/test_slack.py index 7b1bc86..826bf42 100644 --- a/tests/models/test_slack.py +++ b/tests/models/test_slack.py @@ -12,10 +12,16 @@ def test_should_make_channel_str(self): ]) self.assertEqual(str(channel), "unittest_channel") - def test_is_subscribed_to(self): + def test_is_subscribed_to_false(self): channel = Channel("unittest_channel", [ EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK ]) - self.assertEqual([ + self.assertEqual( + False, channel.is_subscribed_to(event=EventType.ISSUE_CLOSED)) + + def test_is_subscribed_to_true(self): + channel = Channel("unittest_channel", [ EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK - ], is_subs) + ]) + self.assertEqual(True, + channel.is_subscribed_to(EventType.BRANCH_CREATED))