Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
config
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
Container registry
Model registry
Operate
Environments
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
config
Commits
bdae25a5
Commit
bdae25a5
authored
5 months ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add a test for Mailman delivery
parent
0927b101
No related branches found
No related tags found
No related merge requests found
Pipeline
#83739
failed
5 months ago
Stage: docker_build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/ai3test/test_mail.py
+27
-14
27 additions, 14 deletions
test/ai3test/test_mail.py
with
27 additions
and
14 deletions
test/ai3test/test_mail.py
+
27
−
14
View file @
bdae25a5
...
...
@@ -81,40 +81,44 @@ class TestMail(TestBase):
return
unique_id
# Send an email from a to b and find it in c's IMAP account.
def
_send_email_and_read_it
(
self
,
sender
,
sender_password
,
rcpt
,
imap_user
,
imap_password
):
unique_id
=
self
.
_send_email
(
sender
,
sender_password
,
rcpt
)
def
_wait_for_message
(
self
,
imap_user
,
imap_password
,
match_header
,
match_value
,
timeout
=
300
):
imap
=
imaplib
.
IMAP4_SSL
(
self
.
frontend_ip
())
imap
.
login
(
imap_user
,
imap_password
)
imap
.
select
(
'
INBOX
'
)
def
_check_for_msg
():
logging
.
info
(
'
looking for message
<
%s
>
'
,
unique_id
)
logging
.
info
(
'
looking for message %s
'
,
match_value
)
typ
,
data
=
imap
.
uid
(
'
search
'
,
None
,
'
HEADER
'
,
'
X-UniqueID
'
,
unique_id
)
'
search
'
,
None
,
'
HEADER
'
,
match_header
,
match_value
)
if
typ
==
'
OK
'
and
data
[
0
]:
logging
.
info
(
'
message
<
%s
>
found, fetching uuid
"
%s
"'
,
unique_id
,
data
[
0
])
logging
.
info
(
'
message %s found, fetching uuid
"
%s
"'
,
match_value
,
data
[
0
])
typ
,
msgdata
=
imap
.
uid
(
'
fetch
'
,
data
[
0
],
'
(RFC822)
'
)
if
typ
!=
'
OK
'
:
raise
Exception
(
'
error fetching message: %s
'
%
typ
)
msg
=
msgdata
[
0
][
1
]
imap
.
uid
(
'
store
'
,
data
[
0
],
'
+FLAGS
'
,
r
'
(\Deleted)
'
)
imap
.
expunge
()
logging
.
info
(
'
message
<
%s
>
deleted successfully
'
,
unique_id
)
logging
.
info
(
'
message %s deleted successfully
'
,
match_value
)
return
msg
return
None
deadline
=
time
.
time
()
+
300
delivered
=
False
deadline
=
time
.
time
()
+
timeout
while
time
.
time
()
<
deadline
:
msg
=
_check_for_msg
()
if
msg
:
delivered
=
True
break
return
True
time
.
sleep
(
1
)
return
False
# Send an email from a to b and find it in c's IMAP account.
def
_send_email_and_read_it
(
self
,
sender
,
sender_password
,
rcpt
,
imap_user
,
imap_password
):
unique_id
=
self
.
_send_email
(
sender
,
sender_password
,
rcpt
)
delivered
=
self
.
_wait_for_message
(
imap_user
,
imap_password
,
'
X-UniqueID
'
,
unique_id
)
self
.
assertTrue
(
delivered
)
return
msg
...
...
@@ -230,3 +234,12 @@ class TestMail(TestBase):
'
password
'
,
'
uno@investici.org
'
,
from_addr
=
'
uno@investici.org
'
)
def
test_mailman_send_message
(
self
):
# Test user sends an email to a list it is subscribed to.
self
.
_send_email_and_read_it
(
self
.
users
[
'
nonpriv
'
][
'
name
'
],
self
.
users
[
'
nonpriv
'
][
'
password
'
],
'
lista@investici.org
'
,
self
.
users
[
'
nonpriv
'
][
'
name
'
],
self
.
users
[
'
nonpriv
'
][
'
password
'
])
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