Commit c16287a1 authored by Samuel GAIST's avatar Samuel GAIST

[search] Add test for correct email creation

parent c5917e76
Pipeline #43035 failed with stage
in 15 minutes and 16 seconds
# vim: set fileencoding=utf-8 :
# encoding: utf-8
###############################################################################
# #
# Copyright (c) 2020 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import io
from unittest.mock import patch
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core import mail
from django.core.management import call_command
from django.test import override_settings
from ..algorithms.tests.core import setup_users
from ..common.testutils import BaseTestCase
from ..common.testutils import tearDownModule # noqa test runner will call it
from ..utils.tests.helpers import reload_urlconf
from .models import Leaderboard
from .models import Search
class UpdateLeaderBoardManagementTestCase(BaseTestCase):
def setUp(self):
setup_users()
self.johndoe = User.objects.get(username="johndoe")
self.jackdoe = User.objects.get(username="jackdoe")
self.janedoe = User.objects.get(username="janedoe")
def run_command(self):
new_io = io.StringIO()
call_command("update_leaderboards", stdout=new_io)
return new_io.getvalue().strip()
def test_leaderboard_update(self):
current_site = Site.objects.get_current()
search = Search.objects.create(author=self.johndoe, name="test")
search.filters = "{}"
search.settings = "{}"
search.save()
leaderboard = Leaderboard.objects.create(search=search)
leaderboard.notify.add(self.johndoe, self.jackdoe, self.janedoe)
leaderboard.save()
# Simulating update
with patch.object(Leaderboard, "update_experiments", return_value=True):
for prefix in ["", "/platform"]:
with self.subTest(url_prefix=prefix):
with override_settings(URL_PREFIX=prefix):
reload_urlconf()
mail.outbox = []
self.run_command()
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(
f"https://{current_site.domain}{prefix}"
in mail.outbox[0].body
)
class EmailOnLeaderboarDeletionTestCase(BaseTestCase):
def setUp(self):
setup_users()
self.johndoe = User.objects.get(username="johndoe")
self.jackdoe = User.objects.get(username="jackdoe")
self.janedoe = User.objects.get(username="janedoe")
def test_leaderboard_deletion(self):
current_site = Site.objects.get_current()
for prefix in ["", "/platform"]:
with self.subTest(url_prefix=prefix):
search = Search.objects.create(author=self.johndoe, name="test")
search.filters = "{}"
search.settings = "{}"
search.save()
leaderboard = Leaderboard.objects.create(search=search)
leaderboard.notify.add(self.johndoe, self.jackdoe, self.janedoe)
leaderboard.save()
with override_settings(URL_PREFIX=prefix):
reload_urlconf()
mail.outbox = []
leaderboard.delete()
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(
f"https://{current_site.domain}{prefix}" in mail.outbox[0].body
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment