Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
9b4c0540
Commit
9b4c0540
authored
Oct 25, 2017
by
Calen Pennington
Committed by
Nimisha Asthagiri
Oct 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move task being tested into a class attribute
parent
b774e0a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
38 deletions
+41
-38
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
+22
-21
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
+19
-17
No files found.
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
View file @
9b4c0540
...
@@ -48,6 +48,7 @@ NUM_COURSE_MODES_QUERIES = 1
...
@@ -48,6 +48,7 @@ NUM_COURSE_MODES_QUERIES = 1
"Can't test schedules if the app isn't installed"
)
"Can't test schedules if the app isn't installed"
)
class
TestSendRecurringNudge
(
ScheduleBaseEmailTestBase
):
class
TestSendRecurringNudge
(
ScheduleBaseEmailTestBase
):
# pylint: disable=protected-access
# pylint: disable=protected-access
tested_task
=
tasks
.
ScheduleRecurringNudge
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestSendRecurringNudge
,
self
)
.
setUp
()
super
(
TestSendRecurringNudge
,
self
)
.
setUp
()
...
@@ -77,8 +78,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -77,8 +78,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
def
test_resolver_send
(
self
,
mock_ace
):
def
test_resolver_send
(
self
,
mock_ace
):
current_day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
current_day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
with
patch
.
object
(
tasks
.
ScheduleRecurringNudge
,
'apply_async'
)
as
mock_apply_async
:
with
patch
.
object
(
self
.
tested_task
,
'apply_async'
)
as
mock_apply_async
:
tasks
.
ScheduleRecurringNudge
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
-
3
)
self
.
tested_task
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
-
3
)
test_day
=
current_day
+
datetime
.
timedelta
(
days
=-
3
)
test_day
=
current_day
+
datetime
.
timedelta
(
days
=-
3
)
mock_apply_async
.
assert_any_call
(
mock_apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_day
),
-
3
,
0
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_day
),
-
3
,
0
,
None
),
...
@@ -92,7 +93,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -92,7 +93,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
@ddt.data
(
1
,
10
,
100
)
@ddt.data
(
1
,
10
,
100
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleRecurringNudge
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_schedule_bin
(
self
,
schedule_count
,
mock_schedule_send
,
mock_ace
):
def
test_schedule_bin
(
self
,
schedule_count
,
mock_schedule_send
,
mock_ace
):
schedules
=
[
schedules
=
[
ScheduleFactory
.
create
(
ScheduleFactory
.
create
(
...
@@ -113,13 +114,13 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -113,13 +114,13 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
b
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
b
,
))
))
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
schedule_count
)
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
schedule_count
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
t
asks
.
ScheduleRecurringNudge
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_no_course_overview
(
self
,
mock_schedule_send
):
def
test_no_course_overview
(
self
,
mock_schedule_send
):
schedule
=
ScheduleFactory
.
create
(
schedule
=
ScheduleFactory
.
create
(
start
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
34
,
30
,
tzinfo
=
pytz
.
UTC
),
start
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
34
,
30
,
tzinfo
=
pytz
.
UTC
),
...
@@ -132,7 +133,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -132,7 +133,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
test_datetime_str
=
serialize
(
test_datetime
)
test_datetime_str
=
serialize
(
test_datetime
)
for
b
in
range
(
resolvers
.
RECURRING_NUDGE_NUM_BINS
):
for
b
in
range
(
resolvers
.
RECURRING_NUDGE_NUM_BINS
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
b
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
b
))
))
...
@@ -144,7 +145,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -144,7 +145,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
# is null.
# is null.
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
0
)
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
0
)
@patch.object
(
t
asks
.
ScheduleRecurringNudge
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_send_after_course_end
(
self
,
mock_schedule_send
):
def
test_send_after_course_end
(
self
,
mock_schedule_send
):
user1
=
UserFactory
.
create
(
id
=
resolvers
.
RECURRING_NUDGE_NUM_BINS
)
user1
=
UserFactory
.
create
(
id
=
resolvers
.
RECURRING_NUDGE_NUM_BINS
)
...
@@ -162,7 +163,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -162,7 +163,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
test_datetime
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_datetime
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_datetime_str
=
serialize
(
test_datetime
)
test_datetime_str
=
serialize
(
test_datetime
)
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
,
))
))
...
@@ -182,7 +183,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -182,7 +183,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_recurring_nudge
=
False
)
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_recurring_nudge
=
False
)
current_datetime
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
current_datetime
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
tasks
.
ScheduleRecurringNudge
.
enqueue
(
self
.
tested_task
.
enqueue
(
self
.
site_config
.
site
,
self
.
site_config
.
site
,
current_datetime
,
current_datetime
,
3
3
...
@@ -191,7 +192,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -191,7 +192,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleRecurringNudge
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
@ddt.data
(
@ddt.data
(
(([
'filtered_org'
],
[],
1
)),
(([
'filtered_org'
],
[],
1
)),
(([],
[
'filtered_org'
],
2
))
(([],
[
'filtered_org'
],
2
))
...
@@ -233,7 +234,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -233,7 +234,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
this_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
site_id
=
this_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
))
))
...
@@ -241,7 +242,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -241,7 +242,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleRecurringNudge
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_multiple_enrollments
(
self
,
mock_schedule_send
,
mock_ace
):
def
test_multiple_enrollments
(
self
,
mock_schedule_send
,
mock_ace
):
user
=
UserFactory
.
create
()
user
=
UserFactory
.
create
()
schedules
=
[
schedules
=
[
...
@@ -256,7 +257,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -256,7 +257,7 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
test_datetime
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_datetime
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_datetime_str
=
serialize
(
test_datetime
)
test_datetime_str
=
serialize
(
test_datetime
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
user
.
id
%
resolvers
.
RECURRING_NUDGE_NUM_BINS
,
bin_num
=
user
.
id
%
resolvers
.
RECURRING_NUDGE_NUM_BINS
,
))
))
...
@@ -290,11 +291,11 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -290,11 +291,11 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
sent_messages
=
[]
sent_messages
=
[]
with
self
.
settings
(
TEMPLATES
=
self
.
_get_template_overrides
()):
with
self
.
settings
(
TEMPLATES
=
self
.
_get_template_overrides
()):
with
patch
.
object
(
tasks
.
ScheduleRecurringNudge
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
tested_task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
)
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleRecurringNudge
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
day
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
day
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
))
...
@@ -343,8 +344,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -343,8 +344,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
user
,
user
,
schedule
.
enrollment
.
course
.
org
schedule
.
enrollment
.
course
.
org
]
]
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
tasks
.
ScheduleRecurringNudge
,
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
self
.
tested_task
,
stubbed_send_task
=
patch
.
object
(
tasks
.
ScheduleRecurringNudge
,
'async_send_task'
),
stubbed_send_task
=
patch
.
object
(
self
.
tested_task
,
'async_send_task'
),
bin_task_params
=
bin_task_parameters
)
bin_task_params
=
bin_task_parameters
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
...
@@ -375,8 +376,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -375,8 +376,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
user
,
user
,
schedule
.
enrollment
.
course
.
org
schedule
.
enrollment
.
course
.
org
]
]
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
tasks
.
ScheduleRecurringNudge
,
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
self
.
tested_task
,
stubbed_send_task
=
patch
.
object
(
tasks
.
ScheduleRecurringNudge
,
'async_send_task'
),
stubbed_send_task
=
patch
.
object
(
self
.
tested_task
,
'async_send_task'
),
bin_task_params
=
bin_task_parameters
)
bin_task_params
=
bin_task_parameters
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
...
@@ -414,8 +415,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
...
@@ -414,8 +415,8 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
user
,
user
,
schedule
.
enrollment
.
course
.
org
schedule
.
enrollment
.
course
.
org
]
]
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
tasks
.
ScheduleRecurringNudge
,
sent_messages
=
self
.
_stub_sender_and_collect_sent_messages
(
bin_task
=
self
.
tested_task
,
stubbed_send_task
=
patch
.
object
(
tasks
.
ScheduleRecurringNudge
,
'async_send_task'
),
stubbed_send_task
=
patch
.
object
(
self
.
tested_task
,
'async_send_task'
),
bin_task_params
=
bin_task_parameters
)
bin_task_params
=
bin_task_parameters
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
self
.
assertEqual
(
len
(
sent_messages
),
1
)
...
...
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
View file @
9b4c0540
...
@@ -62,6 +62,8 @@ LOG = logging.getLogger(__name__)
...
@@ -62,6 +62,8 @@ LOG = logging.getLogger(__name__)
@freeze_time
(
'2017-08-01 00:00:00'
,
tz_offset
=
0
,
tick
=
True
)
@freeze_time
(
'2017-08-01 00:00:00'
,
tz_offset
=
0
,
tick
=
True
)
class
TestUpgradeReminder
(
ScheduleBaseEmailTestBase
,
SharedModuleStoreTestCase
):
class
TestUpgradeReminder
(
ScheduleBaseEmailTestBase
,
SharedModuleStoreTestCase
):
tested_task
=
tasks
.
ScheduleUpgradeReminder
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
super
(
TestUpgradeReminder
,
cls
)
.
setUpClass
()
super
(
TestUpgradeReminder
,
cls
)
.
setUpClass
()
...
@@ -111,8 +113,8 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -111,8 +113,8 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
test_day
=
current_day
+
datetime
.
timedelta
(
days
=
2
)
test_day
=
current_day
+
datetime
.
timedelta
(
days
=
2
)
ScheduleFactory
.
create
(
upgrade_deadline
=
datetime
.
datetime
(
2017
,
8
,
3
,
15
,
34
,
30
,
tzinfo
=
pytz
.
UTC
))
ScheduleFactory
.
create
(
upgrade_deadline
=
datetime
.
datetime
(
2017
,
8
,
3
,
15
,
34
,
30
,
tzinfo
=
pytz
.
UTC
))
with
patch
.
object
(
tasks
.
ScheduleUpgradeReminder
,
'apply_async'
)
as
mock_apply_async
:
with
patch
.
object
(
self
.
tested_task
,
'apply_async'
)
as
mock_apply_async
:
tasks
.
ScheduleUpgradeReminder
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
2
)
self
.
tested_task
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
2
)
mock_apply_async
.
assert_any_call
(
mock_apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_day
),
2
,
0
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_day
),
2
,
0
,
None
),
retry
=
False
,
retry
=
False
,
...
@@ -125,7 +127,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -125,7 +127,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
@ddt.data
(
1
,
10
,
100
)
@ddt.data
(
1
,
10
,
100
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_schedule_bin
(
self
,
schedule_count
,
mock_schedule_send
,
mock_ace
):
def
test_schedule_bin
(
self
,
schedule_count
,
mock_schedule_send
,
mock_ace
):
upgrade_deadline
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
+
datetime
.
timedelta
(
days
=
2
)
upgrade_deadline
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
+
datetime
.
timedelta
(
days
=
2
)
schedules
=
[
schedules
=
[
...
@@ -160,14 +162,14 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -160,14 +162,14 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
b
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
b
,
))
))
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
schedule_count
)
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
schedule_count
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
t
asks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_no_course_overview
(
self
,
mock_schedule_send
):
def
test_no_course_overview
(
self
,
mock_schedule_send
):
schedule
=
ScheduleFactory
.
create
(
schedule
=
ScheduleFactory
.
create
(
...
@@ -181,7 +183,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -181,7 +183,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
for
b
in
range
(
resolvers
.
UPGRADE_REMINDER_NUM_BINS
):
for
b
in
range
(
resolvers
.
UPGRADE_REMINDER_NUM_BINS
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
+
NUM_QUERIES_NO_ORG_LIST
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
b
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
b
,
))
))
...
@@ -202,12 +204,12 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -202,12 +204,12 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleUpgradeReminder
,
'apply_async'
)
@patch.object
(
t
ested_task
,
'apply_async'
)
def
test_enqueue_disabled
(
self
,
mock_ace
,
mock_apply_async
):
def
test_enqueue_disabled
(
self
,
mock_ace
,
mock_apply_async
):
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_upgrade_reminder
=
False
)
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_upgrade_reminder
=
False
)
current_day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
current_day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
tasks
.
ScheduleUpgradeReminder
.
enqueue
(
self
.
tested_task
.
enqueue
(
self
.
site_config
.
site
,
self
.
site_config
.
site
,
current_day
,
current_day
,
day_offset
=
3
,
day_offset
=
3
,
...
@@ -216,7 +218,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -216,7 +218,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
@ddt.data
(
@ddt.data
(
(([
'filtered_org'
],
[],
1
)),
(([
'filtered_org'
],
[],
1
)),
(([],
[
'filtered_org'
],
2
))
(([],
[
'filtered_org'
],
2
))
...
@@ -263,7 +265,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -263,7 +265,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
expected_queries
+=
NUM_QUERIES_NO_ORG_LIST
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
this_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
site_id
=
this_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=-
3
,
bin_num
=
0
))
))
...
@@ -271,7 +273,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -271,7 +273,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
self
.
assertFalse
(
mock_ace
.
send
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
t
asks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
@patch.object
(
t
ested_task
,
'async_send_task'
)
def
test_multiple_enrollments
(
self
,
mock_schedule_send
,
mock_ace
):
def
test_multiple_enrollments
(
self
,
mock_schedule_send
,
mock_ace
):
user
=
UserFactory
.
create
()
user
=
UserFactory
.
create
()
schedules
=
[
schedules
=
[
...
@@ -293,7 +295,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -293,7 +295,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
NUM_QUERIES_FIRST_MATCH
+
course_switch_queries
+
org_switch_queries
+
NUM_QUERIES_NO_ORG_LIST
NUM_QUERIES_FIRST_MATCH
+
course_switch_queries
+
org_switch_queries
+
NUM_QUERIES_NO_ORG_LIST
)
)
with
self
.
assertNumQueries
(
expected_query_count
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
expected_query_count
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
))
...
@@ -340,7 +342,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -340,7 +342,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
sent_messages
=
[]
sent_messages
=
[]
with
self
.
settings
(
TEMPLATES
=
self
.
_get_template_overrides
()):
with
self
.
settings
(
TEMPLATES
=
self
.
_get_template_overrides
()):
with
patch
.
object
(
tasks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
tested_task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
)
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
)
# we execute one query per course to see if it's opted out of dynamic upgrade deadlines
# we execute one query per course to see if it's opted out of dynamic upgrade deadlines
...
@@ -349,7 +351,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -349,7 +351,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
)
)
with
self
.
assertNumQueries
(
num_expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
with
self
.
assertNumQueries
(
num_expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
))
...
@@ -388,7 +390,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -388,7 +390,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
)
)
test_datetime_str
=
serialize
(
datetime
.
datetime
.
now
(
pytz
.
UTC
))
test_datetime_str
=
serialize
(
datetime
.
datetime
.
now
(
pytz
.
UTC
))
tasks
.
ScheduleUpgradeReminder
.
delay
(
self
.
tested_task
.
delay
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
0
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
0
,
org_list
=
[
self
.
course
.
org
],
org_list
=
[
self
.
course
.
org
],
)
)
...
@@ -424,10 +426,10 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
...
@@ -424,10 +426,10 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
test_datetime_str
=
serialize
(
test_datetime
)
test_datetime_str
=
serialize
(
test_datetime
)
sent_messages
=
[]
sent_messages
=
[]
with
patch
.
object
(
tasks
.
ScheduleUpgradeReminder
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
tested_task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
[
1
])
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
[
1
])
tasks
.
ScheduleUpgradeReminder
.
apply
(
kwargs
=
dict
(
self
.
tested_task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
test_datetime_str
,
day_offset
=
2
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment