Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
geant-swd
compendium-v2
Commits
d8ba7513
Commit
d8ba7513
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
fix tests
parent
50b65716
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_send_mail.py
+16
-2
16 additions, 2 deletions
test/test_send_mail.py
with
16 additions
and
2 deletions
test/test_send_mail.py
+
16
−
2
View file @
d8ba7513
from
typing
import
List
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
# noqa: F401
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
compendium_v2.db.auth_model
import
User
from
compendium_v2.db.auth_model
import
User
from
compendium_v2.email
import
send_admin_signup_notification
,
send_user_signup_notification
from
compendium_v2.email
import
send_admin_signup_notification
,
send_user_signup_notification
def
decode_message
(
msg
:
MIMEMultipart
):
message
:
List
[
MIMEText
]
=
msg
.
get_payload
()
text
:
MIMEText
=
message
[
0
]
decoded
=
text
.
get_payload
(
decode
=
True
).
decode
(
'
utf-8
'
)
return
decoded
@contextmanager
@contextmanager
def
test_user
(
app
):
def
test_user
(
app
):
with
app
.
app_context
():
with
app
.
app_context
():
...
@@ -18,8 +28,10 @@ def test_user(app):
...
@@ -18,8 +28,10 @@ def test_user(app):
def
test_signup_email_admin
(
app
,
mocked_admin_user
,
mocker
):
def
test_signup_email_admin
(
app
,
mocked_admin_user
,
mocker
):
def
_send_mail
(
*
args
,
**
kwargs
):
def
_send_mail
(
*
args
,
**
kwargs
):
_msg
=
args
[
-
1
]
decoded
=
decode_message
(
_msg
)
message
=
'
testname has just signed up with the email testmail321@email.com and provider ID testsub
'
message
=
'
testname has just signed up with the email testmail321@email.com and provider ID testsub
'
assert
args
[
-
1
].
split
(
'
\n\n
'
)[
-
1
]
==
message
assert
decoded
==
message
mocker
.
patch
(
'
compendium_v2.email._send_mail
'
,
_send_mail
)
mocker
.
patch
(
'
compendium_v2.email._send_mail
'
,
_send_mail
)
with
test_user
(
app
)
as
user
:
with
test_user
(
app
)
as
user
:
...
@@ -29,7 +41,9 @@ def test_signup_email_admin(app, mocked_admin_user, mocker):
...
@@ -29,7 +41,9 @@ def test_signup_email_admin(app, mocked_admin_user, mocker):
def
test_signup_email_user
(
app
,
mocker
):
def
test_signup_email_user
(
app
,
mocker
):
def
_send_mail
(
*
args
,
**
kwargs
):
def
_send_mail
(
*
args
,
**
kwargs
):
assert
len
(
args
[
-
1
].
split
(
'
\n\n
'
,
1
)[
-
1
])
>
50
# check that there's a message
_msg
=
args
[
-
1
]
decoded
=
decode_message
(
_msg
)
assert
len
(
decoded
)
>
50
# check that there's a message
mocker
.
patch
(
'
compendium_v2.email._send_mail
'
,
_send_mail
)
mocker
.
patch
(
'
compendium_v2.email._send_mail
'
,
_send_mail
)
with
test_user
(
app
)
as
user
:
with
test_user
(
app
)
as
user
:
...
...
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