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
OpenEdx
edx-platform
Commits
5e792ea2
Commit
5e792ea2
authored
Oct 13, 2017
by
Tyler Hallada
Committed by
Dillon Dumesnil
Oct 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standardize on var names: *_datetime and *_day
parent
e6d88b14
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
93 deletions
+91
-93
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
+27
-27
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
+27
-27
openedx/core/djangoapps/schedules/tasks.py
+37
-39
No files found.
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
View file @
5e792ea2
...
...
@@ -62,9 +62,9 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
@patch.object
(
nudge
.
Command
,
'resolver_class'
)
def
test_handle
(
self
,
mock_resolver
):
test_
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
test_
day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
nudge
.
Command
()
.
handle
(
date
=
'2017-08-01'
,
site_domain_name
=
self
.
site_config
.
site
.
domain
)
mock_resolver
.
assert_called_with
(
self
.
site_config
.
site
,
test_
time
)
mock_resolver
.
assert_called_with
(
self
.
site_config
.
site
,
test_
day
)
for
day
in
(
-
3
,
-
10
):
mock_resolver
()
.
send
.
assert_any_call
(
day
,
None
)
...
...
@@ -72,16 +72,16 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
resolvers
.
ScheduleStartResolver
,
'async_send_task'
)
def
test_resolver_send
(
self
,
mock_schedule_bin
,
mock_ace
):
current_
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
nudge
.
ScheduleStartResolver
(
self
.
site_config
.
site
,
current_
time
)
.
send
(
-
3
)
test_
time
=
current_time
+
datetime
.
timedelta
(
days
=-
3
)
current_
day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
nudge
.
ScheduleStartResolver
(
self
.
site_config
.
site
,
current_
day
)
.
send
(
-
3
)
test_
day
=
current_day
+
datetime
.
timedelta
(
days
=-
3
)
self
.
assertFalse
(
mock_schedule_bin
.
called
)
mock_schedule_bin
.
apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
time
),
-
3
,
0
,
[],
True
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
day
),
-
3
,
0
,
[],
True
,
None
),
retry
=
False
,
)
mock_schedule_bin
.
apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
time
),
-
3
,
tasks
.
RECURRING_NUDGE_NUM_BINS
-
1
,
[],
True
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
day
),
-
3
,
tasks
.
RECURRING_NUDGE_NUM_BINS
-
1
,
[],
True
,
None
),
retry
=
False
,
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
...
...
@@ -99,8 +99,8 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
bins_in_use
=
frozenset
((
s
.
enrollment
.
user
.
id
%
tasks
.
RECURRING_NUDGE_NUM_BINS
)
for
s
in
schedules
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
18
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
18
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
for
b
in
range
(
tasks
.
RECURRING_NUDGE_NUM_BINS
):
expected_queries
=
NUM_QUERIES_NO_MATCHING_SCHEDULES
if
b
in
bins_in_use
:
...
...
@@ -109,7 +109,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
recurring_nudge_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=-
3
,
bin_num
=
b
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=-
3
,
bin_num
=
b
,
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
self
.
assertEqual
(
mock_schedule_send
.
apply_async
.
call_count
,
schedule_count
)
...
...
@@ -124,12 +124,12 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
schedule
.
enrollment
.
course_id
=
CourseKey
.
from_string
(
'edX/toy/Not_2012_Fall'
)
schedule
.
enrollment
.
save
()
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
for
b
in
range
(
tasks
.
RECURRING_NUDGE_NUM_BINS
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
recurring_nudge_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=-
3
,
bin_num
=
b
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=-
3
,
bin_num
=
b
,
org_list
=
[
schedule
.
enrollment
.
course
.
org
],
)
...
...
@@ -152,11 +152,11 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
schedule
.
enrollment
.
course
=
CourseOverviewFactory
()
schedule
.
enrollment
.
course
.
end
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
-
datetime
.
timedelta
(
days
=
1
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
tasks
.
recurring_nudge_schedule_bin
.
apply_async
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=-
3
,
bin_num
=
0
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=-
3
,
bin_num
=
0
,
org_list
=
[
schedule
.
enrollment
.
course
.
org
],
)
...
...
@@ -175,8 +175,8 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
def
test_enqueue_disabled
(
self
,
mock_schedule_bin
,
mock_ace
):
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_recurring_nudge
=
False
)
current_time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
nudge
.
ScheduleStartResolver
(
self
.
site_config
.
site
,
current_time
)
.
send
(
3
)
current_
date
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
nudge
.
ScheduleStartResolver
(
self
.
site_config
.
site
,
current_
date
time
)
.
send
(
3
)
self
.
assertFalse
(
mock_schedule_bin
.
called
)
self
.
assertFalse
(
mock_schedule_bin
.
apply_async
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
...
...
@@ -218,11 +218,11 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
enrollment__user
=
user2
,
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
17
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
17
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
recurring_nudge_schedule_bin
(
limited_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=-
3
,
bin_num
=
0
,
limited_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=-
3
,
bin_num
=
0
,
org_list
=
org_list
,
exclude_orgs
=
exclude_orgs
,
)
...
...
@@ -242,11 +242,11 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
for
course_num
in
(
1
,
2
,
3
)
]
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
recurring_nudge_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=-
3
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=-
3
,
bin_num
=
user
.
id
%
tasks
.
RECURRING_NUDGE_NUM_BINS
,
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
...
...
@@ -267,8 +267,8 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
for
course_num
in
range
(
message_count
)
]
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
patch_policies
(
self
,
[
StubPolicy
([
ChannelType
.
PUSH
])])
mock_channel
=
Mock
(
...
...
@@ -285,7 +285,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
recurring_nudge_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
day
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
day
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
...
...
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
View file @
5e792ea2
...
...
@@ -62,27 +62,27 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
@patch.object
(
reminder
.
Command
,
'resolver_class'
)
def
test_handle
(
self
,
mock_resolver
):
test_
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
test_
day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
reminder
.
Command
()
.
handle
(
date
=
'2017-08-01'
,
site_domain_name
=
self
.
site_config
.
site
.
domain
)
mock_resolver
.
assert_called_with
(
self
.
site_config
.
site
,
test_
time
)
mock_resolver
.
assert_called_with
(
self
.
site_config
.
site
,
test_
day
)
mock_resolver
()
.
send
.
assert_any_call
(
2
,
None
)
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
resolvers
.
UpgradeReminderResolver
,
'async_send_task'
)
def
test_resolver_send
(
self
,
mock_schedule_bin
,
mock_ace
):
current_
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
test_
time
=
current_time
+
datetime
.
timedelta
(
days
=
2
)
current_
day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
test_
day
=
current_day
+
datetime
.
timedelta
(
days
=
2
)
ScheduleFactory
.
create
(
upgrade_deadline
=
datetime
.
datetime
(
2017
,
8
,
3
,
15
,
34
,
30
,
tzinfo
=
pytz
.
UTC
))
reminder
.
UpgradeReminderResolver
(
self
.
site_config
.
site
,
current_
time
)
.
send
(
2
)
reminder
.
UpgradeReminderResolver
(
self
.
site_config
.
site
,
current_
day
)
.
send
(
2
)
self
.
assertFalse
(
mock_schedule_bin
.
called
)
mock_schedule_bin
.
apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
time
),
2
,
0
,
[],
True
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
day
),
2
,
0
,
[],
True
,
None
),
retry
=
False
,
)
mock_schedule_bin
.
apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
time
),
2
,
tasks
.
UPGRADE_REMINDER_NUM_BINS
-
1
,
[],
True
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
test_
day
),
2
,
tasks
.
UPGRADE_REMINDER_NUM_BINS
-
1
,
[],
True
,
None
),
retry
=
False
,
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
...
...
@@ -100,8 +100,8 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
bins_in_use
=
frozenset
((
s
.
enrollment
.
user
.
id
%
tasks
.
UPGRADE_REMINDER_NUM_BINS
)
for
s
in
schedules
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
18
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
18
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
for
b
in
range
(
tasks
.
UPGRADE_REMINDER_NUM_BINS
):
expected_queries
=
NUM_QUERIES_NO_MATCHING_SCHEDULES
if
b
in
bins_in_use
:
...
...
@@ -110,7 +110,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
upgrade_reminder_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
2
,
bin_num
=
b
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
2
,
bin_num
=
b
,
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
...
...
@@ -126,12 +126,12 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
schedule
.
enrollment
.
course_id
=
CourseKey
.
from_string
(
'edX/toy/Not_2012_Fall'
)
schedule
.
enrollment
.
save
()
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
for
b
in
range
(
tasks
.
UPGRADE_REMINDER_NUM_BINS
):
with
self
.
assertNumQueries
(
NUM_QUERIES_NO_MATCHING_SCHEDULES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
upgrade_reminder_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
2
,
bin_num
=
b
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
2
,
bin_num
=
b
,
org_list
=
[
schedule
.
enrollment
.
course
.
org
],
)
...
...
@@ -156,8 +156,8 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
def
test_enqueue_disabled
(
self
,
mock_schedule_bin
,
mock_ace
):
ScheduleConfigFactory
.
create
(
site
=
self
.
site_config
.
site
,
enqueue_upgrade_reminder
=
False
)
current_
time
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
reminder
.
UpgradeReminderResolver
(
self
.
site_config
.
site
,
current_
time
)
.
send
(
3
)
current_
day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
reminder
.
UpgradeReminderResolver
(
self
.
site_config
.
site
,
current_
day
)
.
send
(
3
)
self
.
assertFalse
(
mock_schedule_bin
.
called
)
self
.
assertFalse
(
mock_schedule_bin
.
apply_async
.
called
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
...
...
@@ -199,11 +199,11 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
enrollment__user
=
user2
,
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
17
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
17
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
upgrade_reminder_schedule_bin
(
limited_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
2
,
bin_num
=
0
,
limited_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
2
,
bin_num
=
0
,
org_list
=
org_list
,
exclude_orgs
=
exclude_orgs
,
)
...
...
@@ -223,11 +223,11 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
for
course_num
in
(
1
,
2
,
3
)
]
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_
time_str
=
serialize
(
test_
time
)
test_
date
time
=
datetime
.
datetime
(
2017
,
8
,
3
,
19
,
44
,
30
,
tzinfo
=
pytz
.
UTC
)
test_
datetime_str
=
serialize
(
test_date
time
)
with
self
.
assertNumQueries
(
NUM_QUERIES_WITH_MATCHES
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
upgrade_reminder_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
2
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
2
,
bin_num
=
user
.
id
%
tasks
.
UPGRADE_REMINDER_NUM_BINS
,
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
...
...
@@ -239,12 +239,12 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
def
test_templates
(
self
,
message_count
,
day
):
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
now
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
future_date
=
now
+
datetime
.
timedelta
(
days
=
21
)
future_date
time
=
now
+
datetime
.
timedelta
(
days
=
21
)
user
=
UserFactory
.
create
()
schedules
=
[
ScheduleFactory
.
create
(
upgrade_deadline
=
future_date
,
upgrade_deadline
=
future_date
time
,
enrollment__user
=
user
,
enrollment__course__id
=
CourseLocator
(
'edX'
,
'toy'
,
'Course{}'
.
format
(
course_num
))
)
...
...
@@ -258,11 +258,11 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
CourseModeFactory
(
course_id
=
schedule
.
enrollment
.
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
,
expiration_datetime
=
future_date
expiration_datetime
=
future_date
time
)
test_
time
=
future_dat
e
test_
time_str
=
serialize
(
test_
time
)
test_
datetime
=
future_datetim
e
test_
datetime_str
=
serialize
(
test_date
time
)
patch_policies
(
self
,
[
StubPolicy
([
ChannelType
.
PUSH
])])
mock_channel
=
Mock
(
...
...
@@ -284,7 +284,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
num_expected_queries
=
NUM_QUERIES_WITH_MATCHES
+
NUM_QUERIES_WITH_DEADLINE
+
message_count
with
self
.
assertNumQueries
(
num_expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
tasks
.
upgrade_reminder_schedule_bin
(
self
.
site_config
.
site
.
id
,
target_day_str
=
test_time_str
,
day_offset
=
day
,
self
.
site_config
.
site
.
id
,
target_day_str
=
test_
date
time_str
,
day_offset
=
day
,
bin_num
=
user
.
id
%
tasks
.
UPGRADE_REMINDER_NUM_BINS
,
org_list
=
[
schedules
[
0
]
.
enrollment
.
course
.
org
],
)
...
...
openedx/core/djangoapps/schedules/tasks.py
View file @
5e792ea2
...
...
@@ -90,15 +90,15 @@ def _recurring_nudge_schedule_send(site_id, msg_str):
def
recurring_nudge_schedule_bin
(
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
):
target_date
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date instead of reproducing it here
current_date
=
target_dat
e
-
datetime
.
timedelta
(
days
=
day_offset
)
target_date
time
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date
time
instead of reproducing it here
current_date
time
=
target_datetim
e
-
datetime
.
timedelta
(
days
=
day_offset
)
msg_type
=
RecurringNudge
(
abs
(
day_offset
))
for
(
user
,
language
,
context
)
in
_recurring_nudge_schedules_for_bin
(
Site
.
objects
.
get
(
id
=
site_id
),
current_date
,
target_date
,
current_date
time
,
target_date
time
,
bin_num
,
org_list
,
exclude_orgs
...
...
@@ -114,11 +114,11 @@ def recurring_nudge_schedule_bin(
_recurring_nudge_schedule_send
.
apply_async
((
site_id
,
str
(
msg
)),
retry
=
False
)
def
_recurring_nudge_schedules_for_bin
(
site
,
current_date
,
target_dat
e
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
def
_recurring_nudge_schedules_for_bin
(
site
,
current_date
time
,
target_datetim
e
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'start'
,
current_date
=
current_dat
e
,
target_date
=
target_dat
e
,
current_date
time
=
current_datetim
e
,
target_date
time
=
target_datetim
e
,
bin_num
=
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
org_list
,
...
...
@@ -157,15 +157,15 @@ class UpgradeReminder(ScheduleMessageType):
def
upgrade_reminder_schedule_bin
(
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
):
target_date
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date instead of reproducing it here
current_date
=
target_dat
e
-
datetime
.
timedelta
(
days
=
day_offset
)
target_date
time
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date
time
instead of reproducing it here
current_date
time
=
target_datetim
e
-
datetime
.
timedelta
(
days
=
day_offset
)
msg_type
=
UpgradeReminder
()
for
(
user
,
language
,
context
)
in
_upgrade_reminder_schedules_for_bin
(
Site
.
objects
.
get
(
id
=
site_id
),
current_date
,
target_date
,
current_date
time
,
target_date
time
,
bin_num
,
org_list
,
exclude_orgs
...
...
@@ -191,11 +191,11 @@ def _upgrade_reminder_schedule_send(site_id, msg_str):
ace
.
send
(
msg
)
def
_upgrade_reminder_schedules_for_bin
(
site
,
current_date
,
target_dat
e
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
def
_upgrade_reminder_schedules_for_bin
(
site
,
current_date
time
,
target_datetim
e
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'upgrade_deadline'
,
current_date
=
current_dat
e
,
target_date
=
target_dat
e
,
current_date
time
=
current_datetim
e
,
target_date
time
=
target_datetim
e
,
bin_num
=
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
org_list
,
...
...
@@ -232,7 +232,6 @@ def _upgrade_reminder_schedules_for_bin(site, current_date, target_date, bin_num
yield
(
user
,
first_schedule
.
enrollment
.
course
.
language
,
template_context
)
<<<<<<<
HEAD
class
CourseUpdate
(
ScheduleMessageType
):
pass
...
...
@@ -241,12 +240,15 @@ class CourseUpdate(ScheduleMessageType):
def
course_update_schedule_bin
(
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
):
target_day
=
deserialize
(
target_day_str
)
target_datetime
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
current_datetime
=
target_datetime
-
datetime
.
timedelta
(
days
=
day_offset
)
msg_type
=
CourseUpdate
()
for
(
user
,
language
,
context
)
in
_course_update_schedules_for_bin
(
Site
.
objects
.
get
(
id
=
site_id
),
target_day
,
current_datetime
,
target_datetime
,
day_offset
,
bin_num
,
org_list
,
...
...
@@ -273,12 +275,13 @@ def _course_update_schedule_send(site_id, msg_str):
ace
.
send
(
msg
)
def
_course_update_schedules_for_bin
(
site
,
target_day
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
def
_course_update_schedules_for_bin
(
site
,
current_datetime
,
target_datetime
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
week_num
=
abs
(
day_offset
)
/
7
beginning_of_day
=
target_day
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
)
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'start'
,
target_date
=
beginning_of_day
,
current_datetime
=
current_datetime
,
target_datetime
=
target_datetime
,
bin_num
=
bin_num
,
num_bins
=
COURSE_UPDATE_NUM_BINS
,
org_list
=
org_list
,
...
...
@@ -323,43 +326,38 @@ def get_course_week_summary(course_id, week_num):
raise
CourseUpdateDoesNotExist
()
def
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
,
target_date
,
bin_num
,
num_bins
=
DEFAULT_NUM_BINS
,
org_list
=
None
,
exclude_orgs
=
False
,
order_by
=
'enrollment__user__id'
):
|||||||
parent
of
c6f507c4b7
...
Address
Gabe
's comments
def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_date, bin_num, num_bins=DEFAULT_NUM_BINS,
org_list=None, exclude_orgs=False):
=======
def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, current_date, target_date, bin_num,
num_bins=DEFAULT_NUM_BINS, org_list=None, exclude_orgs=False):
>>>>>>> c6f507c4b7... Address Gabe'
s
comments
def
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
,
current_datetime
,
target_datetime
,
bin_num
,
num_bins
=
DEFAULT_NUM_BINS
,
org_list
=
None
,
exclude_orgs
=
False
,
order_by
=
'enrollment__user__id'
):
"""
Returns Schedules with the target_date, related to Users whose id matches the bin_num, and filtered by org_list.
Arguments:
schedule_date_field -- string field name to query on the User's Schedule model
current_date -- datetime that will be used as "right now" in the query
target_date -- datetime that the User's Schedule's schedule_date_field value should fall under
current_date
time
-- datetime that will be used as "right now" in the query
target_date
time
-- datetime that the User's Schedule's schedule_date_field value should fall under
bin_num -- int for selecting the bin of Users whose id
%
num_bins == bin_num
num_bin -- int specifying the number of bins to separate the Users into (default: DEFAULT_NUM_BINS)
org_list -- list of course_org names (strings) that the returned Schedules must or must not be in (default: None)
exclude_orgs -- boolean indicating whether the returned Schedules should exclude (True) the course_orgs in org_list
or strictly include (False) them (default: False)
order_by -- string for field to sort the resulting Schedules by
"""
target_day
=
_get_datetime_beginning_of_day
(
target_date
)
schedule_da
te_equals_target_date
_filter
=
{
target_day
=
_get_datetime_beginning_of_day
(
target_date
time
)
schedule_da
y_equals_target_day
_filter
=
{
'courseenrollment__schedule__{}__gte'
.
format
(
schedule_date_field
):
target_day
,
'courseenrollment__schedule__{}__lt'
.
format
(
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
}
users
=
User
.
objects
.
filter
(
courseenrollment__is_active
=
True
,
**
schedule_da
te_equals_target_date
_filter
**
schedule_da
y_equals_target_day
_filter
)
.
annotate
(
id_mod
=
F
(
'id'
)
%
num_bins
)
.
filter
(
id_mod
=
bin_num
)
schedule_da
te_equals_target_date
_filter
=
{
schedule_da
y_equals_target_day
_filter
=
{
'{}__gte'
.
format
(
schedule_date_field
):
target_day
,
'{}__lt'
.
format
(
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
}
...
...
@@ -369,10 +367,10 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, current_
)
.
prefetch_related
(
'enrollment__course__modes'
)
.
filter
(
Q
(
enrollment__course__end__isnull
=
True
)
|
Q
(
enrollment__course__end__gte
=
current_date
),
Q
(
enrollment__course__end__isnull
=
True
)
|
Q
(
enrollment__course__end__gte
=
current_date
time
),
enrollment__user__in
=
users
,
enrollment__is_active
=
True
,
**
schedule_da
te_equals_target_date
_filter
**
schedule_da
y_equals_target_day
_filter
)
.
order_by
(
order_by
)
if
org_list
is
not
None
:
...
...
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