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
da95676e
Commit
da95676e
authored
Oct 30, 2017
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedules: rename test class variables that aren't test methods
parent
08d31e1a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
42 deletions
+42
-42
openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py
+27
-27
openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py
+3
-3
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
+3
-3
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
+7
-7
openedx/core/djangoapps/schedules/management/commands/tests/upsell_base.py
+2
-2
No files found.
openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py
View file @
da95676e
...
...
@@ -75,13 +75,13 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
def
_calculate_bin_for_user
(
self
,
user
):
return
user
.
id
%
self
.
t
ested_t
ask
.
num_bins
return
user
.
id
%
self
.
task
.
num_bins
def
_get_dates
(
self
,
offset
=
None
):
current_day
=
_get_datetime_beginning_of_day
(
datetime
.
datetime
.
now
(
pytz
.
UTC
))
offset
=
offset
or
self
.
expected_offsets
[
0
]
target_day
=
current_day
+
datetime
.
timedelta
(
days
=
offset
)
if
self
.
tested_
resolver
.
schedule_date_field
==
'upgrade_deadline'
:
if
self
.
resolver
.
schedule_date_field
==
'upgrade_deadline'
:
upgrade_deadline
=
target_day
else
:
upgrade_deadline
=
current_day
+
datetime
.
timedelta
(
days
=
7
)
...
...
@@ -93,12 +93,12 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
return
templates_override
def
test_command_task_binding
(
self
):
self
.
assertEqual
(
self
.
tested_command
.
async_send_task
,
self
.
tested_
task
)
self
.
assertEqual
(
self
.
command
.
async_send_task
,
self
.
task
)
def
test_handle
(
self
):
with
patch
.
object
(
self
.
tested_
command
,
'async_send_task'
)
as
mock_send
:
with
patch
.
object
(
self
.
command
,
'async_send_task'
)
as
mock_send
:
test_day
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
self
.
tested_
command
()
.
handle
(
date
=
'2017-08-01'
,
site_domain_name
=
self
.
site_config
.
site
.
domain
)
self
.
command
()
.
handle
(
date
=
'2017-08-01'
,
site_domain_name
=
self
.
site_config
.
site
.
domain
)
for
offset
in
self
.
expected_offsets
:
mock_send
.
enqueue
.
assert_any_call
(
...
...
@@ -111,14 +111,14 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@patch.object
(
tasks
,
'ace'
)
def
test_resolver_send
(
self
,
mock_ace
):
current_day
,
offset
,
target_day
,
_
=
self
.
_get_dates
()
with
patch
.
object
(
self
.
t
ested_t
ask
,
'apply_async'
)
as
mock_apply_async
:
self
.
t
ested_t
ask
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
offset
)
with
patch
.
object
(
self
.
task
,
'apply_async'
)
as
mock_apply_async
:
self
.
task
.
enqueue
(
self
.
site_config
.
site
,
current_day
,
offset
)
mock_apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
target_day
),
offset
,
0
,
None
),
retry
=
False
,
)
mock_apply_async
.
assert_any_call
(
(
self
.
site_config
.
site
.
id
,
serialize
(
target_day
),
offset
,
self
.
t
ested_t
ask
.
num_bins
-
1
,
None
),
(
self
.
site_config
.
site
.
id
,
serialize
(
target_day
),
offset
,
self
.
task
.
num_bins
-
1
,
None
),
retry
=
False
,
)
self
.
assertFalse
(
mock_ace
.
send
.
called
)
...
...
@@ -127,7 +127,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@patch.object
(
tasks
,
'ace'
)
@patch.object
(
resolvers
,
'set_custom_metric'
)
def
test_schedule_bin
(
self
,
schedule_count
,
mock_metric
,
mock_ace
):
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
current_day
,
offset
,
target_day
,
upgrade_deadline
=
self
.
_get_dates
()
schedules
=
[
ScheduleFactory
.
create
(
...
...
@@ -141,7 +141,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
is_first_match
=
True
target_day_str
=
serialize
(
target_day
)
for
b
in
range
(
self
.
t
ested_t
ask
.
num_bins
):
for
b
in
range
(
self
.
task
.
num_bins
):
LOG
.
debug
(
'Running bin
%
d'
,
b
)
expected_queries
=
NUM_QUERIES_NO_MATCHING_SCHEDULES
if
b
in
bins_in_use
:
...
...
@@ -156,7 +156,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
expected_queries
=
NUM_QUERIES_WITH_MATCHES
with
self
.
assertNumQueries
(
expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
target_day_str
,
day_offset
=
offset
,
bin_num
=
b
,
))
...
...
@@ -179,9 +179,9 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
schedule
.
enrollment
.
course_id
=
CourseKey
.
from_string
(
'edX/toy/Not_2012_Fall'
)
schedule
.
enrollment
.
save
()
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
for
b
in
range
(
self
.
t
ested_t
ask
.
num_bins
):
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
for
b
in
range
(
self
.
task
.
num_bins
):
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
...
...
@@ -222,8 +222,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
ScheduleConfigFactory
.
create
(
**
schedule_config_kwargs
)
current_datetime
=
datetime
.
datetime
(
2017
,
8
,
1
,
tzinfo
=
pytz
.
UTC
)
with
patch
.
object
(
self
.
t
ested_t
ask
,
'apply_async'
)
as
mock_apply_async
:
self
.
t
ested_t
ask
.
enqueue
(
self
.
site_config
.
site
,
current_datetime
,
3
)
with
patch
.
object
(
self
.
task
,
'apply_async'
)
as
mock_apply_async
:
self
.
task
.
enqueue
(
self
.
site_config
.
site
,
current_datetime
,
3
)
if
is_enabled
:
self
.
assertTrue
(
mock_apply_async
.
called
)
...
...
@@ -245,8 +245,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
for
config
in
(
this_config
,
other_config
):
ScheduleConfigFactory
.
create
(
site
=
config
.
site
)
user1
=
UserFactory
.
create
(
id
=
self
.
t
ested_t
ask
.
num_bins
)
user2
=
UserFactory
.
create
(
id
=
self
.
t
ested_t
ask
.
num_bins
*
2
)
user1
=
UserFactory
.
create
(
id
=
self
.
task
.
num_bins
)
user2
=
UserFactory
.
create
(
id
=
self
.
task
.
num_bins
*
2
)
current_day
,
offset
,
target_day
,
upgrade_deadline
=
self
.
_get_dates
()
ScheduleFactory
.
create
(
...
...
@@ -271,8 +271,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
enrollment__user
=
user2
,
)
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
this_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
0
))
...
...
@@ -281,7 +281,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@ddt.data
(
True
,
False
)
def
test_course_end
(
self
,
has_course_ended
):
user1
=
UserFactory
.
create
(
id
=
self
.
t
ested_t
ask
.
num_bins
)
user1
=
UserFactory
.
create
(
id
=
self
.
task
.
num_bins
)
current_day
,
offset
,
target_day
,
upgrade_deadline
=
self
.
_get_dates
()
schedule
=
ScheduleFactory
.
create
(
...
...
@@ -296,8 +296,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
schedule
.
enrollment
.
course
.
end
=
current_day
+
datetime
.
timedelta
(
days
=
end_date_offset
)
schedule
.
enrollment
.
course
.
save
()
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
0
,
))
...
...
@@ -323,8 +323,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
additional_course_queries
=
num_courses
-
1
if
self
.
queries_deadline_for_each_course
else
0
expected_query_count
=
NUM_QUERIES_FIRST_MATCH
+
additional_course_queries
with
self
.
assertNumQueries
(
expected_query_count
,
table_blacklist
=
WAFFLE_TABLES
):
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
...
...
@@ -361,7 +361,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
sent_messages
=
[]
with
self
.
settings
(
TEMPLATES
=
self
.
_get_template_overrides
()):
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
)
num_expected_queries
=
NUM_QUERIES_FIRST_MATCH
...
...
@@ -369,7 +369,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
num_expected_queries
+=
(
message_count
-
1
)
with
self
.
assertNumQueries
(
num_expected_queries
,
table_blacklist
=
WAFFLE_TABLES
):
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
...
...
openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py
View file @
da95676e
...
...
@@ -19,10 +19,10 @@ class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase):
__test__
=
True
# pylint: disable=protected-access
tested_
resolver
=
resolvers
.
CourseUpdateResolver
t
ested_t
ask
=
tasks
.
ScheduleCourseUpdate
resolver
=
resolvers
.
CourseUpdateResolver
task
=
tasks
.
ScheduleCourseUpdate
deliver_task
=
tasks
.
_course_update_schedule_send
tested_
command
=
nudge
.
Command
command
=
nudge
.
Command
deliver_config
=
'deliver_course_update'
enqueue_config
=
'enqueue_course_update'
expected_offsets
=
xrange
(
-
7
,
-
77
,
-
7
)
...
...
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
View file @
da95676e
...
...
@@ -18,10 +18,10 @@ class TestSendRecurringNudge(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase)
__test__
=
True
# pylint: disable=protected-access
tested_
resolver
=
resolvers
.
RecurringNudgeResolver
t
ested_t
ask
=
tasks
.
ScheduleRecurringNudge
resolver
=
resolvers
.
RecurringNudgeResolver
task
=
tasks
.
ScheduleRecurringNudge
deliver_task
=
tasks
.
_recurring_nudge_schedule_send
tested_
command
=
nudge
.
Command
command
=
nudge
.
Command
deliver_config
=
'deliver_recurring_nudge'
enqueue_config
=
'enqueue_recurring_nudge'
expected_offsets
=
(
-
3
,
-
10
)
...
...
openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py
View file @
da95676e
...
...
@@ -27,10 +27,10 @@ LOG = logging.getLogger(__name__)
class
TestUpgradeReminder
(
ScheduleSendEmailTestBase
):
__test__
=
True
tested_
resolver
=
resolvers
.
UpgradeReminderResolver
t
ested_t
ask
=
tasks
.
ScheduleUpgradeReminder
resolver
=
resolvers
.
UpgradeReminderResolver
task
=
tasks
.
ScheduleUpgradeReminder
deliver_task
=
tasks
.
_upgrade_reminder_schedule_send
tested_
command
=
reminder
.
Command
command
=
reminder
.
Command
deliver_config
=
'deliver_upgrade_reminder'
enqueue_config
=
'enqueue_upgrade_reminder'
expected_offsets
=
(
2
,)
...
...
@@ -41,7 +41,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
@ddt.data
(
True
,
False
)
@patch.object
(
tasks
,
'ace'
)
def
test_verified_learner
(
self
,
is_verified
,
mock_ace
):
user
=
UserFactory
.
create
(
id
=
self
.
t
ested_t
ask
.
num_bins
)
user
=
UserFactory
.
create
(
id
=
self
.
task
.
num_bins
)
current_day
,
offset
,
target_day
,
upgrade_deadline
=
self
.
_get_dates
()
ScheduleFactory
.
create
(
upgrade_deadline
=
upgrade_deadline
,
...
...
@@ -50,7 +50,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
enrollment__mode
=
CourseMode
.
VERIFIED
if
is_verified
else
CourseMode
.
AUDIT
,
)
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
...
...
@@ -73,10 +73,10 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
]
sent_messages
=
[]
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
[
1
])
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
self
.
_calculate_bin_for_user
(
user
),
))
...
...
openedx/core/djangoapps/schedules/management/commands/tests/upsell_base.py
View file @
da95676e
...
...
@@ -41,9 +41,9 @@ class ScheduleUpsellTestMixin(object):
)
sent_messages
=
[]
with
patch
.
object
(
self
.
t
ested_t
ask
,
'async_send_task'
)
as
mock_schedule_send
:
with
patch
.
object
(
self
.
task
,
'async_send_task'
)
as
mock_schedule_send
:
mock_schedule_send
.
apply_async
=
lambda
args
,
*
_a
,
**
_kw
:
sent_messages
.
append
(
args
[
1
])
self
.
t
ested_t
ask
.
apply
(
kwargs
=
dict
(
self
.
task
.
apply
(
kwargs
=
dict
(
site_id
=
self
.
site_config
.
site
.
id
,
target_day_str
=
serialize
(
target_day
),
day_offset
=
offset
,
bin_num
=
self
.
_calculate_bin_for_user
(
schedule
.
enrollment
.
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