-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fresh-team-overview
- Loading branch information
Showing
9 changed files
with
396 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,23 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
# from django.core import management | ||
from django.utils import timezone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Runs commands scheduled to execute daily" | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
logger.info(f"Starting daily scheduled tasks at {timezone.now()}") | ||
|
||
# Add commands to be executed daily | ||
# management.call_command('daily_command1') | ||
# management.call_command('daily_command2') | ||
except Exception as e: | ||
logger.error(f"Error in daily tasks: {str(e)}") | ||
raise |
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,23 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
# from django.core import management | ||
from django.utils import timezone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Runs commands scheduled to execute hourly" | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
logger.info(f"Starting hourly scheduled tasks at {timezone.now()}") | ||
|
||
# We can add hourly commands here | ||
# management.call_command('hourly_command1') | ||
# management.call_command('hourly_command2') | ||
except Exception as e: | ||
logger.error(f"Error in hourly tasks: {str(e)}") | ||
raise |
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,23 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
# from django.core import management | ||
from django.utils import timezone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Runs commands scheduled to execute monthly" | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
logger.info(f"Starting monthly scheduled tasks at {timezone.now()}") | ||
|
||
# Add commands to be executed monthly | ||
# management.call_command('monthly_command1') | ||
# management.call_command('monthly_command2') | ||
except Exception as e: | ||
logger.error(f"Error in monthly tasks: {str(e)}") | ||
raise |
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,23 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
# from django.core import management | ||
from django.utils import timezone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Runs commands scheduled to execute weekly" | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
logger.info(f"Starting weekly scheduled tasks at {timezone.now()}") | ||
|
||
# Add commands to be executed weekly | ||
# management.call_command('weekly_command1') | ||
# management.call_command('weekly_command2') | ||
except Exception as e: | ||
logger.error(f"Error in weekly tasks: {str(e)}") | ||
raise |
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,89 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from django.test import TestCase | ||
|
||
from website.views.slack_handlers import ( | ||
_handle_contribute_message, | ||
_handle_team_join, | ||
extract_text_from_blocks, | ||
handle_message, | ||
) | ||
|
||
|
||
class SlackFunctionTests(TestCase): | ||
def setUp(self): | ||
self.mock_client = MagicMock() | ||
|
||
def test_extract_text_from_blocks(self): | ||
"""Test extracting text from Slack block format""" | ||
# Test rich text blocks | ||
blocks = [ | ||
{ | ||
"type": "rich_text", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "I want to contribute"}], | ||
} | ||
], | ||
} | ||
] | ||
|
||
self.assertEqual(extract_text_from_blocks(blocks), "I want to contribute") | ||
|
||
# Test empty blocks | ||
self.assertEqual(extract_text_from_blocks([]), "") | ||
|
||
# Test invalid blocks | ||
self.assertEqual(extract_text_from_blocks(None), "") | ||
|
||
@patch("website.views.slack_handlers.client") | ||
def test_handle_contribute_message(self, mock_client): | ||
"""Test contribute message handler""" | ||
message = { | ||
"user": "U123", | ||
"channel": "C123", | ||
"text": "How do I contribute?", | ||
"subtype": None, | ||
} | ||
|
||
_handle_contribute_message(message) | ||
|
||
mock_client.chat_postMessage.assert_called_once() | ||
|
||
# Test message without contribute keyword | ||
message["text"] = "Hello world" | ||
mock_client.chat_postMessage.reset_mock() | ||
_handle_contribute_message(message) | ||
mock_client.chat_postMessage.assert_not_called() | ||
|
||
@patch("website.views.slack_handlers.client") | ||
def test_handle_team_join(self, mock_client): | ||
"""Test team join handler""" | ||
mock_client.conversations_open.return_value = {"ok": True, "channel": {"id": "D123"}} | ||
|
||
_handle_team_join("U123") | ||
|
||
# Should send welcome message in joins channel | ||
mock_client.chat_postMessage.assert_called() | ||
|
||
# Should try to open DM | ||
mock_client.conversations_open.assert_called_once_with(users=["U123"]) | ||
|
||
@patch("website.views.slack_handlers.client") | ||
def test_handle_message(self, mock_client): | ||
"""Test main message handler""" | ||
# Mock bot user ID | ||
mock_client.auth_test.return_value = {"user_id": "BOT123"} | ||
|
||
# Test normal user message | ||
payload = {"user": "U123", "text": "contribute", "channel": "C123"} | ||
|
||
handle_message(payload) | ||
mock_client.chat_postMessage.assert_called() | ||
|
||
# Test bot message (should be ignored) | ||
payload["user"] = "BOT123" | ||
mock_client.chat_postMessage.reset_mock() | ||
handle_message(payload) | ||
mock_client.chat_postMessage.assert_not_called() |
Oops, something went wrong.