Skip to content

Commit

Permalink
[back] feat: add hostname in the watch account creations msg (tournes…
Browse files Browse the repository at this point in the history
…ol-app#1389)


Co-authored-by: Gresille&Siffle <[email protected]>
  • Loading branch information
aidanjungo and GresilleSiffle authored Mar 1, 2023
1 parent 1de34bf commit 8f1bb9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion backend/core/management/commands/watch_account_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Send an alert on Discord when too many users have created accounts using email
addresses considered trusted during the last hours.
"""
from django.conf import settings
from django.core.management.base import BaseCommand

from core.lib.discord.api import write_in_channel
Expand Down Expand Up @@ -43,7 +44,7 @@ def handle(self, *args, **options):

for domain in email_domains_alert_qs:

msg = (f"{domain.cnt} accounts were created during the last "
msg = (f"**{settings.MAIN_URL}** - {domain.cnt} accounts were created during the last "
f"{options['since_n_hours']} hour(s) with the domain '{domain.domain}'")

self.stdout.write(msg)
Expand Down
15 changes: 9 additions & 6 deletions backend/core/tests/management/test_watch_account_creation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from io import StringIO
from unittest import mock

from django.conf import settings
from django.core.management import call_command
from django.test import TestCase

Expand All @@ -10,10 +11,9 @@


class WatchAccountCreationTestCase(TestCase):

@mock.patch("core.lib.discord.api.write_in_channel")
def test_cmd_watch_account_creation(self, write_in_channel_mock):

out = StringIO()

# Test which must trigger the alert
Expand All @@ -22,9 +22,13 @@ def test_cmd_watch_account_creation(self, write_in_channel_mock):

call_command("watch_account_creation", since_n_hours=1, n_accounts=1, stdout=out)
output = out.getvalue()

self.assertIn("1 accounts were created during the last 1 hour(s) "
"with the domain '@verified.test'", output)

self.assertIn(
f"**{settings.MAIN_URL}** - 1 accounts were created "
"during the last 1 hour(s) with the domain "
"'@verified.test'",
output,
)
self.assertIn("success", output)
self.assertEqual(write_in_channel_mock.call_count, 1)

Expand All @@ -37,4 +41,3 @@ def test_cmd_watch_account_creation(self, write_in_channel_mock):

self.assertIn("success", output)
self.assertEqual(write_in_channel_mock.call_count, 1)

0 comments on commit 8f1bb9b

Please sign in to comment.