Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.web
Commits
c16287a1
Commit
c16287a1
authored
4 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[search] Add test for correct email creation
parent
c5917e76
No related branches found
Branches containing commit
No related tags found
2 merge requests
!382
Cleanup url prefix use in search
,
!342
Django 3 migration
Pipeline
#43035
failed
4 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/search/tests.py
+114
-0
114 additions, 0 deletions
beat/web/search/tests.py
with
114 additions
and
0 deletions
beat/web/search/tests.py
0 → 100644
+
114
−
0
View file @
c16287a1
# 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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment