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
03e496bd
Unverified
Commit
03e496bd
authored
Oct 30, 2017
by
Andy Armstrong
Committed by
GitHub
Oct 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16370 from edx/andya/waffle-fix
Allow Waffle flags to work when outside a request context
parents
c7ed394f
c55dbb2c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
6 deletions
+49
-6
lms/djangoapps/courseware/tests/test_course_tools.py
+6
-0
openedx/core/djangoapps/waffle_utils/__init__.py
+12
-2
openedx/core/djangoapps/waffle_utils/tests/test_init.py
+25
-4
openedx/core/djangoapps/waffle_utils/tests/test_testutils.py
+6
-0
No files found.
lms/djangoapps/courseware/tests/test_course_tools.py
View file @
03e496bd
"""
Unit tests for course tools.
"""
import
crum
import
datetime
import
datetime
from
mock
import
patch
from
mock
import
patch
...
@@ -59,6 +64,7 @@ class VerifiedUpgradeToolTest(SharedModuleStoreTestCase):
...
@@ -59,6 +64,7 @@ class VerifiedUpgradeToolTest(SharedModuleStoreTestCase):
)
)
self
.
request
=
RequestFactory
()
.
request
()
self
.
request
=
RequestFactory
()
.
request
()
self
.
request
.
user
=
self
.
enrollment
.
user
self
.
request
.
user
=
self
.
enrollment
.
user
crum
.
set_current_request
(
self
.
request
)
def
test_tool_visible
(
self
):
def
test_tool_visible
(
self
):
self
.
assertTrue
(
VerifiedUpgradeTool
()
.
is_enabled
(
self
.
request
,
self
.
course
.
id
))
self
.
assertTrue
(
VerifiedUpgradeTool
()
.
is_enabled
(
self
.
request
,
self
.
course
.
id
))
...
...
openedx/core/djangoapps/waffle_utils/__init__.py
View file @
03e496bd
...
@@ -45,6 +45,7 @@ To test WaffleSwitchNamespace, use the provided context managers. For example:
...
@@ -45,6 +45,7 @@ To test WaffleSwitchNamespace, use the provided context managers. For example:
...
...
"""
"""
import
crum
import
logging
import
logging
from
abc
import
ABCMeta
from
abc
import
ABCMeta
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
...
@@ -54,7 +55,6 @@ from opaque_keys.edx.keys import CourseKey
...
@@ -54,7 +55,6 @@ from opaque_keys.edx.keys import CourseKey
from
waffle
import
flag_is_active
,
switch_is_active
from
waffle
import
flag_is_active
,
switch_is_active
from
request_cache
import
get_cache
as
get_request_cache
from
request_cache
import
get_cache
as
get_request_cache
from
request_cache
import
get_request
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -256,7 +256,17 @@ class WaffleFlagNamespace(WaffleNamespace):
...
@@ -256,7 +256,17 @@ class WaffleFlagNamespace(WaffleNamespace):
value
=
flag_undefined_default
value
=
flag_undefined_default
if
value
is
None
:
if
value
is
None
:
value
=
flag_is_active
(
get_request
(),
namespaced_flag_name
)
request
=
crum
.
get_current_request
()
if
request
:
value
=
flag_is_active
(
request
,
namespaced_flag_name
)
else
:
log
.
warn
(
u"
%
sFlag '
%
s' accessed without a request"
,
self
.
log_prefix
,
namespaced_flag_name
)
# Return the default value if not in a request context.
# Note: this skips the cache as the value might be different
# in a normal request context. This case seems to occur when
# a page redirects to a 404. In this case, we'll just return
# the default value.
return
bool
(
flag_undefined_default
)
self
.
_cached_flags
[
namespaced_flag_name
]
=
value
self
.
_cached_flags
[
namespaced_flag_name
]
=
value
return
value
return
value
...
...
openedx/core/djangoapps/waffle_utils/tests/test_init.py
View file @
03e496bd
"""
"""
Tests for waffle utils features.
Tests for waffle utils features.
"""
"""
import
crum
import
ddt
import
ddt
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
mock
import
patch
from
mock
import
patch
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys.edx.keys
import
CourseKey
from
request_cache.middleware
import
RequestCache
from
request_cache.middleware
import
RequestCache
...
@@ -27,6 +29,12 @@ class TestCourseWaffleFlag(TestCase):
...
@@ -27,6 +29,12 @@ class TestCourseWaffleFlag(TestCase):
TEST_NAMESPACE
=
WaffleFlagNamespace
(
NAMESPACE_NAME
)
TEST_NAMESPACE
=
WaffleFlagNamespace
(
NAMESPACE_NAME
)
TEST_COURSE_FLAG
=
CourseWaffleFlag
(
TEST_NAMESPACE
,
FLAG_NAME
)
TEST_COURSE_FLAG
=
CourseWaffleFlag
(
TEST_NAMESPACE
,
FLAG_NAME
)
def
setUp
(
self
):
super
(
TestCourseWaffleFlag
,
self
)
.
setUp
()
request
=
RequestFactory
()
.
request
()
crum
.
set_current_request
(
request
)
RequestCache
.
clear_request_cache
()
@ddt.data
(
@ddt.data
(
{
'course_override'
:
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
on
,
'waffle_enabled'
:
False
,
'result'
:
True
},
{
'course_override'
:
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
on
,
'waffle_enabled'
:
False
,
'result'
:
True
},
{
'course_override'
:
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
off
,
'waffle_enabled'
:
True
,
'result'
:
False
},
{
'course_override'
:
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
off
,
'waffle_enabled'
:
True
,
'result'
:
False
},
...
@@ -38,8 +46,6 @@ class TestCourseWaffleFlag(TestCase):
...
@@ -38,8 +46,6 @@ class TestCourseWaffleFlag(TestCase):
Tests various combinations of a flag being set in waffle and overridden
Tests various combinations of a flag being set in waffle and overridden
for a course.
for a course.
"""
"""
RequestCache
.
clear_request_cache
()
with
patch
.
object
(
WaffleFlagCourseOverrideModel
,
'override_value'
,
return_value
=
data
[
'course_override'
]):
with
patch
.
object
(
WaffleFlagCourseOverrideModel
,
'override_value'
,
return_value
=
data
[
'course_override'
]):
with
override_flag
(
self
.
NAMESPACED_FLAG_NAME
,
active
=
data
[
'waffle_enabled'
]):
with
override_flag
(
self
.
NAMESPACED_FLAG_NAME
,
active
=
data
[
'waffle_enabled'
]):
# check twice to test that the result is properly cached
# check twice to test that the result is properly cached
...
@@ -70,8 +76,6 @@ class TestCourseWaffleFlag(TestCase):
...
@@ -70,8 +76,6 @@ class TestCourseWaffleFlag(TestCase):
"""
"""
Test flag with various defaults provided for undefined waffle flags.
Test flag with various defaults provided for undefined waffle flags.
"""
"""
RequestCache
.
clear_request_cache
()
test_course_flag
=
CourseWaffleFlag
(
test_course_flag
=
CourseWaffleFlag
(
self
.
TEST_NAMESPACE
,
self
.
TEST_NAMESPACE
,
self
.
FLAG_NAME
,
self
.
FLAG_NAME
,
...
@@ -91,3 +95,20 @@ class TestCourseWaffleFlag(TestCase):
...
@@ -91,3 +95,20 @@ class TestCourseWaffleFlag(TestCase):
self
.
NAMESPACED_FLAG_NAME
,
self
.
NAMESPACED_FLAG_NAME
,
self
.
TEST_COURSE_KEY
self
.
TEST_COURSE_KEY
)
)
@ddt.data
(
{
'flag_undefined_default'
:
None
,
'result'
:
False
},
{
'flag_undefined_default'
:
False
,
'result'
:
False
},
{
'flag_undefined_default'
:
True
,
'result'
:
True
},
)
def
test_without_request
(
self
,
data
):
"""
Test the flag behavior when outside a request context.
"""
crum
.
set_current_request
(
None
)
test_course_flag
=
CourseWaffleFlag
(
self
.
TEST_NAMESPACE
,
self
.
FLAG_NAME
,
flag_undefined_default
=
data
[
'flag_undefined_default'
]
)
self
.
assertEqual
(
test_course_flag
.
is_enabled
(
self
.
TEST_COURSE_KEY
),
data
[
'result'
])
openedx/core/djangoapps/waffle_utils/tests/test_testutils.py
View file @
03e496bd
"""
"""
Tests for waffle utils test utilities.
Tests for waffle utils test utilities.
"""
"""
import
crum
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys.edx.keys
import
CourseKey
from
request_cache.middleware
import
RequestCache
from
request_cache.middleware
import
RequestCache
...
@@ -25,6 +29,8 @@ class OverrideWaffleFlagTests(TestCase):
...
@@ -25,6 +29,8 @@ class OverrideWaffleFlagTests(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
OverrideWaffleFlagTests
,
self
)
.
setUp
()
super
(
OverrideWaffleFlagTests
,
self
)
.
setUp
()
request
=
RequestFactory
()
.
request
()
crum
.
set_current_request
(
request
)
RequestCache
.
clear_request_cache
()
RequestCache
.
clear_request_cache
()
@override_waffle_flag
(
TEST_COURSE_FLAG
,
True
)
@override_waffle_flag
(
TEST_COURSE_FLAG
,
True
)
...
...
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