Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Hsin-Yu Chien
edx-platform-release
Commits
62f3171c
Commit
62f3171c
authored
6 years ago
by
John Eskew
Browse files
Options
Downloads
Patches
Plain Diff
Add test for bulk email optout mgmt cmd.
parent
dfbdfe04
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py
+49
-0
49 additions, 0 deletions
...r_api/management/tests/test_bulk_user_org_email_optout.py
with
49 additions
and
0 deletions
openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py
0 → 100644
+
49
−
0
View file @
62f3171c
"""
Test the test_bulk_user_org_email_optout management command
"""
import
os
import
tempfile
from
contextlib
import
contextmanager
import
mock
import
pytest
from
django.core.management
import
call_command
pytestmark
=
pytest
.
mark
.
django_db
CSV_DATA
=
"""
1,UniversityX
2,CollegeX
3,StateUX
"""
@contextmanager
def
_create_test_csv
(
csv_data
):
"""
Context manager to create and populate a CSV file - and delete it after usage.
"""
__
,
file_name
=
tempfile
.
mkstemp
(
text
=
True
)
with
open
(
file_name
,
'
w
'
)
as
file_pointer
:
file_pointer
.
write
(
csv_data
.
encode
(
'
utf-8
'
))
yield
file_name
os
.
unlink
(
file_name
)
@mock.patch
(
'
openedx.core.djangoapps.user_api.management.commands.bulk_user_org_email_optout.log.info
'
)
def
test_successful_dry_run
(
mock_logger
):
"""
Run the command with default states for a successful initial population
"""
with
_create_test_csv
(
CSV_DATA
)
as
tmp_csv_file
:
args
=
[
'
--dry_run
'
,
'
--optout_csv_path={}
'
.
format
(
tmp_csv_file
)]
call_command
(
'
bulk_user_org_email_optout
'
,
*
args
)
assert
mock_logger
.
call_count
==
3
mock_logger
.
assert_any_call
(
"
Read %s opt-out rows from CSV file
'
%s
'
.
"
,
3
,
tmp_csv_file
)
mock_logger
.
assert_any_call
(
'
Attempting opt-out for rows (%s, %s) through (%s, %s)...
'
,
'
1
'
,
'
UniversityX
'
,
'
3
'
,
'
StateUX
'
)
mock_logger
.
assert_any_call
(
'
INSERT INTO user_api_userorgtag (`user_id`, `org`, `key`, `value`, `created`, `modified`)
\
VALUES (1,
"
UniversityX
"
,
"
email-optin
"
,
"
False
"
,NOW(),NOW()),(2,
"
CollegeX
"
,
"
email-optin
"
,
"
False
"
,NOW(),NOW()),
\
(3,
"
StateUX
"
,
"
email-optin
"
,
"
False
"
,NOW(),NOW()) ON DUPLICATE KEY UPDATE value=
"
False
"
, modified=NOW();
'
)
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