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
07bb3ea5
Unverified
Commit
07bb3ea5
authored
Oct 24, 2017
by
Calen Pennington
Committed by
Gabe Mulley
Oct 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the exclude orgs a bit more natural by returning a filtered query
parent
fa7b9a13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
26 deletions
+30
-26
openedx/core/djangoapps/schedules/resolvers.py
+6
-14
openedx/core/djangoapps/schedules/tests/test_resolvers.py
+24
-12
No files found.
openedx/core/djangoapps/schedules/resolvers.py
View file @
07bb3ea5
...
...
@@ -78,7 +78,6 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
def
__attrs_post_init__
(
self
):
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
self
.
current_datetime
=
self
.
target_datetime
-
datetime
.
timedelta
(
days
=
self
.
day_offset
)
self
.
exclude_orgs
,
self
.
org_list
=
self
.
get_course_org_filter
()
def
send
(
self
,
msg_type
):
for
(
user
,
language
,
context
)
in
self
.
schedules_for_bin
():
...
...
@@ -133,11 +132,7 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
**
schedule_day_equals_target_day_filter
)
.
order_by
(
order_by
)
if
self
.
org_list
is
not
None
:
if
self
.
exclude_orgs
:
schedules
=
schedules
.
exclude
(
enrollment__course__org__in
=
self
.
org_list
)
else
:
schedules
=
schedules
.
filter
(
enrollment__course__org__in
=
self
.
org_list
)
schedules
=
self
.
filter_by_org
(
schedules
)
if
"read_replica"
in
settings
.
DATABASES
:
schedules
=
schedules
.
using
(
"read_replica"
)
...
...
@@ -153,7 +148,7 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
return
schedules
def
get_course_org_filter
(
self
):
def
filter_by_org
(
self
,
schedules
):
"""
Given the configuration of sites, get the list of orgs that should be included or excluded from this send.
...
...
@@ -165,7 +160,6 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
try
:
site_config
=
self
.
site
.
configuration
org_list
=
site_config
.
get_value
(
'course_org_filter'
)
exclude_orgs
=
False
if
not
org_list
:
not_orgs
=
set
()
for
other_site_config
in
SiteConfiguration
.
objects
.
all
():
...
...
@@ -175,15 +169,13 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
not_orgs
.
add
(
other
)
else
:
not_orgs
.
update
(
other
)
org_list
=
list
(
not_orgs
)
exclude_orgs
=
True
return
schedules
.
exclude
(
enrollment__course__org__in
=
not_orgs
)
elif
not
isinstance
(
org_list
,
list
):
org_list
=
[
org_list
]
return
schedules
.
filter
(
enrollment__course__org
=
org_list
)
except
SiteConfiguration
.
DoesNotExist
:
org_list
=
None
exclude_orgs
=
False
return
schedules
return
exclude_orgs
,
org_list
return
schedules
.
filter
(
enrollment__course__org__in
=
org_list
)
def
schedules_for_bin
(
self
):
schedules
=
self
.
get_schedules_with_target_date_by_bin_and_orgs
()
...
...
openedx/core/djangoapps/schedules/tests/test_resolvers.py
View file @
07bb3ea5
...
...
@@ -30,28 +30,40 @@ class TestBinnedSchedulesBaseResolver(CacheIsolationTestCase):
bin_num
=
2
,
)
@ddt.data
(
'course1'
)
def
test_get_course_org_filter_equal
(
self
,
course_org_filter
):
self
.
site_config
.
values
[
'course_org_filter'
]
=
course_org_filter
self
.
site_config
.
save
()
mock_query
=
Mock
()
result
=
self
.
resolver
.
filter_by_org
(
mock_query
)
self
.
assertEqual
(
result
,
mock_query
.
filter
.
return_value
)
mock_query
.
filter
.
assert_called_once_with
(
enrollment__course__org
=
course_org_filter
)
@ddt.unpack
@ddt.data
(
(
'course1'
,
[
'course1'
]),
([
'course1'
,
'course2'
],
[
'course1'
,
'course2'
])
)
def
test_get_course_org_filter_include
(
self
,
course_org_filter
,
expected_org_list
):
def
test_get_course_org_filter_include
__in
(
self
,
course_org_filter
,
expected_org_list
):
self
.
site_config
.
values
[
'course_org_filter'
]
=
course_org_filter
self
.
site_config
.
save
()
exclude_orgs
,
org_list
=
self
.
resolver
.
get_course_org_filter
()
assert
not
exclude_orgs
assert
org_list
==
expected_org_list
mock_query
=
Mock
()
result
=
self
.
resolver
.
filter_by_org
(
mock_query
)
self
.
assertEqual
(
result
,
mock_query
.
filter
.
return_value
)
mock_query
.
filter
.
assert_called_once_with
(
enrollment__course__org__in
=
expected_org_list
)
@ddt.unpack
@ddt.data
(
(
None
,
[]
),
(
'course1'
,
[
u'course1'
]
),
([
'course1'
,
'course2'
],
[
u'course1'
,
u'course2'
]
)
(
None
,
set
([])
),
(
'course1'
,
set
([
u'course1'
])
),
([
'course1'
,
'course2'
],
set
([
u'course1'
,
u'course2'
])
)
)
def
test_get_course_org_filter_exclude
(
self
,
course_org_filter
,
expected_org_list
):
def
test_get_course_org_filter_exclude
__in
(
self
,
course_org_filter
,
expected_org_list
):
SiteConfigurationFactory
.
create
(
values
=
{
'course_org_filter'
:
course_org_filter
},
)
exclude_orgs
,
org_list
=
self
.
resolver
.
get_course_org_filter
()
assert
exclude_orgs
self
.
assertItemsEqual
(
org_list
,
expected_org_list
)
mock_query
=
Mock
()
result
=
self
.
resolver
.
filter_by_org
(
mock_query
)
mock_query
.
exclude
.
assert_called_once_with
(
enrollment__course__org__in
=
expected_org_list
)
self
.
assertEqual
(
result
,
mock_query
.
exclude
.
return_value
)
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