-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d98b207
commit e5e07c9
Showing
3 changed files
with
0 additions
and
174 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 |
---|---|---|
@@ -1,37 +0,0 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from sammich.plugins.contributors import ContributorPlugin, format_data | ||
|
||
|
||
class TestContributorPlugin: | ||
@pytest.fixture | ||
def set_up(self, mocker): | ||
self.contributor_plugin = ContributorPlugin( | ||
client=mocker.Mock(), settings=mocker.Mock(), storage=mocker.Mock() | ||
) | ||
yield | ||
|
||
@pytest.mark.asyncio | ||
async def test_contributors(self, mocker, set_up): | ||
with patch.dict( | ||
self.contributor_plugin.__dict__, | ||
{"contributor_data": {"test1": {"prs": "1", "issues": "1", "comments": "0"}}}, | ||
): | ||
prs = [{"user": {"login": "user1"}}] | ||
issues = [{"user": {"login": "user1"}}] | ||
comments = [] | ||
|
||
formatted = format_data(prs, issues, comments) | ||
|
||
expected_output_text = ( | ||
"*Contributor Data*\n" | ||
"```\n" | ||
"User PRs Merged Issues Resolved Comments \n" | ||
"----- ---------- --------------- ---------\n" | ||
"user1 1 1 0 \n" | ||
"\n```" | ||
) | ||
|
||
assert formatted[0]["text"]["text"] == expected_output_text | ||
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 |
---|---|---|
@@ -1,86 +0,0 @@ | ||
from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch | ||
|
||
import pytest | ||
from machine.clients.slack import SlackClient | ||
from machine.storage import PluginStorage | ||
from machine.utils.collections import CaseInsensitiveDict | ||
|
||
from sammich.plugins.project import ProjectPlugin | ||
|
||
|
||
@pytest.fixture | ||
def mock_slack_client(): | ||
"""Fixture to mock the SlackClient.""" | ||
return MagicMock(SlackClient) | ||
|
||
|
||
@pytest.fixture | ||
def mock_settings(): | ||
"""Fixture to mock settings.""" | ||
return CaseInsensitiveDict() | ||
|
||
|
||
@pytest.fixture | ||
def mock_storage(): | ||
"""Fixture to mock PluginStorage.""" | ||
return MagicMock(PluginStorage) | ||
|
||
|
||
@pytest.fixture | ||
def project_plugin(mock_slack_client, mock_settings, mock_storage): | ||
"""Fixture to create a ProjectPlugin instance with mocked dependencies.""" | ||
plugin = ProjectPlugin(mock_slack_client, mock_settings, mock_storage) | ||
plugin.project_data = { | ||
"project1": ["Task 1", "Task 2", "Task 3"], | ||
"project2": ["Task A", "Task B"], | ||
} | ||
with patch.object(ProjectPlugin, "web_client", new_callable=PropertyMock) as mock_web_client: | ||
mock_web_client.return_value.chat_postMessage = AsyncMock() | ||
plugin._web_client = mock_web_client | ||
yield plugin | ||
|
||
|
||
@pytest.fixture | ||
def mock_command(): | ||
"""Fixture to mock a command object.""" | ||
cmd = MagicMock() | ||
cmd.text.strip.return_value.lower.return_value = "project1" | ||
cmd._cmd_payload = {"channel_id": "test_channel"} | ||
cmd.say = AsyncMock() | ||
return cmd | ||
|
||
|
||
@pytest.fixture | ||
def mock_action(): | ||
"""Fixture to mock an action object.""" | ||
action = MagicMock() | ||
action.payload.actions[0].selected_option.value = "project1" | ||
action.say = AsyncMock() | ||
return action | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_project_command(project_plugin, mock_command): | ||
"""Test the project command with a valid project.""" | ||
await project_plugin.project(mock_command) | ||
mock_command.say.assert_awaited_once_with( | ||
"Hello, here the information about 'project1':\nTask 1\nTask 2\nTask 3" | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_project_command_no_project(project_plugin, mock_command): | ||
"""Test the project command with a nonexistent project.""" | ||
mock_command.text.strip.return_value.lower.return_value = "nonexistent" | ||
await project_plugin.project(mock_command) | ||
mock_command.say.assert_not_called() | ||
project_plugin._web_client.return_value.chat_postMessage.assert_awaited_once() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_handle_dropdown_selection(project_plugin, mock_action): | ||
"""Test handling dropdown selection action.""" | ||
await project_plugin.handle_dropdown_selection(mock_action) | ||
mock_action.say.assert_awaited_once_with( | ||
"Hello, here is the information about 'project1':\nTask 1\nTask 2\nTask 3" | ||
) | ||
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 |
---|---|---|
@@ -1,51 +0,0 @@ | ||
import pytest | ||
|
||
from sammich.plugins.repo import RepoPlugin | ||
|
||
|
||
class TestRepoPlugin: | ||
"""Repo plugin tests""" | ||
|
||
@pytest.fixture(autouse=True) | ||
def set_up(self, mocker): | ||
self.repo_plugin = RepoPlugin( | ||
client=mocker.Mock(), settings=mocker.Mock(), storage=mocker.Mock() | ||
) | ||
|
||
yield | ||
|
||
@pytest.mark.asyncio | ||
async def test_repo_command(self, mocker): | ||
mocker.patch.dict( | ||
self.repo_plugin.repo_data, | ||
{ | ||
"test-1": [ | ||
"https://github.com/OWASP-BLT/test", | ||
"https://github.com/OWASP-BLT/test1", | ||
], | ||
"test-2": [ | ||
"https://github.com/OWASP-BLT/test", | ||
"https://github.com/OWASP-BLT/test2", | ||
], | ||
}, | ||
) | ||
|
||
mock_command = mocker.AsyncMock() | ||
mock_command.say = mocker.AsyncMock() | ||
|
||
expected = { | ||
"test-1": ( | ||
"Hello, you can implement your 'test-1' knowledge here:\n" | ||
"https://github.com/OWASP-BLT/test\nhttps://github.com/OWASP-BLT/test1" | ||
), | ||
"test-2": ( | ||
"Hello, you can implement your 'test-2' knowledge here:\n" | ||
"https://github.com/OWASP-BLT/test\nhttps://github.com/OWASP-BLT/test2" | ||
), | ||
} | ||
|
||
for query, response in expected.items(): | ||
mock_command.text = query | ||
await self.repo_plugin.repo(mock_command) | ||
mock_command.say.assert_called_once_with(response) | ||
mock_command.reset_mock() | ||