Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add models unittest. #116

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Empty file added tests/models/__init__.py
Empty file.
Empty file added tests/models/github/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions tests/models/github/test_commit.py
Original file line number Diff line number Diff line change
@@ -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),
"<Hello, this is unittest|www.unittest.com>")
36 changes: 36 additions & 0 deletions tests/models/github/test_event_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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)
13 changes: 13 additions & 0 deletions tests/models/github/test_issue.py
Original file line number Diff line number Diff line change
@@ -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),
"<www.unittestIsue.com|#22 unittest issue>")
12 changes: 12 additions & 0 deletions tests/models/github/test_pull_request.py
Original file line number Diff line number Diff line change
@@ -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),
"<www.unittestpr.com|#44 hey, this is Unittest pr>")
10 changes: 10 additions & 0 deletions tests/models/github/test_ref.py
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions tests/models/test_link.py
Original file line number Diff line number Diff line change
@@ -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), "<www.unittest.com|unittest>")

def test_should_make_link_without_url(self):
link = Link(text="unittest1")
self.assertEqual(str(link), "<None|unittest1>")

def test_should_make_link_without_text(self):
link = Link(text="www.unittest1.com")
self.assertEqual(str(link), "<None|www.unittest1.com>")
27 changes: 27 additions & 0 deletions tests/models/test_slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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_false(self):
channel = Channel("unittest_channel", [
EventType.BRANCH_CREATED, EventType.COMMIT_COMMENT, EventType.FORK
])
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
])
self.assertEqual(True,
channel.is_subscribed_to(EventType.BRANCH_CREATED))