Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
0aa2edbc
Commit
0aa2edbc
authored
4 years ago
by
Calen Pennington
Committed by
Calen Pennington
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean up some radically dirty global state pollition to fix a flaky test
parent
4a120a9e
Branches
Branches containing commit
Tags
release-2020-07-09-11.20
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/lib/xmodule/xmodule/split_test_module.py
+28
-17
28 additions, 17 deletions
common/lib/xmodule/xmodule/split_test_module.py
common/lib/xmodule/xmodule/tests/test_split_test_module.py
+11
-6
11 additions, 6 deletions
common/lib/xmodule/xmodule/tests/test_split_test_module.py
with
39 additions
and
23 deletions
common/lib/xmodule/xmodule/split_test_module.py
+
28
−
17
View file @
0aa2edbc
...
...
@@ -5,6 +5,7 @@ Module for running content split tests
import
json
import
logging
import
threading
from
functools
import
reduce
from
operator
import
itemgetter
from
uuid
import
uuid4
...
...
@@ -32,31 +33,41 @@ _ = lambda text: text
DEFAULT_GROUP_NAME
=
_
(
u
'
Group ID {group_id}
'
)
class
SplitTestFields
(
object
):
"""
Fields needed for split test module
"""
has_children
=
True
# All available user partitions (with value and display name). This is updated each time
# editable_metadata_fields is called.
user_partition_values
=
[]
# Default value used for user_partition_id
no_partition_selected
=
{
'
display_name
'
:
_
(
"
Not Selected
"
),
'
value
'
:
-
1
}
class
UserPartitionValues
(
threading
.
local
):
"""
A thread-local storage for available user_partitions
"""
def
__init__
(
self
):
super
().
__init__
()
self
.
values
=
[]
@staticmethod
def
build_partition_values
(
all_user_partitions
,
selected_user_partition
):
def
build_partition_values
(
self
,
all_user_partitions
,
selected_user_partition
):
"""
This helper method builds up the user_partition values that will
be passed to the Studio editor
"""
SplitTestFields
.
user_partition_
values
=
[]
self
.
values
=
[]
# Add "No selection" value if there is not a valid selected user partition.
if
not
selected_user_partition
:
SplitTestFields
.
user_partition_
values
.
append
(
SplitTestFields
.
no_partition_selected
)
self
.
values
.
append
(
SplitTestFields
.
no_partition_selected
)
for
user_partition
in
get_split_user_partitions
(
all_user_partitions
):
SplitTestFields
.
user_partition_
values
.
append
(
self
.
values
.
append
(
{
"
display_name
"
:
user_partition
.
name
,
"
value
"
:
user_partition
.
id
}
)
return
SplitTestFields
.
user_partition_values
return
self
.
values
# All available user partitions (with value and display name). This is updated each time
# editable_metadata_fields is called.
user_partition_values
=
UserPartitionValues
()
class
SplitTestFields
(
object
):
"""
Fields needed for split test module
"""
has_children
=
True
# Default value used for user_partition_id
no_partition_selected
=
{
'
display_name
'
:
_
(
"
Not Selected
"
),
'
value
'
:
-
1
}
display_name
=
String
(
display_name
=
_
(
"
Display Name
"
),
...
...
@@ -77,7 +88,7 @@ class SplitTestFields(object):
scope
=
Scope
.
content
,
display_name
=
_
(
"
Group Configuration
"
),
default
=
no_partition_selected
[
"
value
"
],
values
=
lambda
:
SplitTestFields
.
user_partition_values
# Will be populated before the Studio editor is shown.
values
=
lambda
:
user_partition_values
.
values
# Will be populated before the Studio editor is shown.
)
# group_id is an int
...
...
@@ -478,7 +489,7 @@ class SplitTestDescriptor(SplitTestFields, SequenceDescriptor, StudioEditableDes
@property
def
editable_metadata_fields
(
self
):
# Update the list of partitions based on the currently available user_partitions.
SplitTestField
s
.
build_partition_values
(
self
.
user_partitions
,
self
.
get_selected_partition
())
user_partition_value
s
.
build_partition_values
(
self
.
user_partitions
,
self
.
get_selected_partition
())
editable_fields
=
super
(
SplitTestDescriptor
,
self
).
editable_metadata_fields
...
...
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/tests/test_split_test_module.py
+
11
−
6
View file @
0aa2edbc
...
...
@@ -11,7 +11,12 @@ from mock import Mock, patch
from
xmodule.partitions.partitions
import
MINIMUM_STATIC_PARTITION_ID
,
Group
,
UserPartition
from
xmodule.partitions.tests.test_partitions
import
MockPartitionService
,
MockUserPartitionScheme
,
PartitionTestCase
from
xmodule.split_test_module
import
SplitTestDescriptor
,
SplitTestFields
,
get_split_user_partitions
from
xmodule.split_test_module
import
(
SplitTestDescriptor
,
SplitTestFields
,
get_split_user_partitions
,
user_partition_values
,
)
from
xmodule.tests
import
get_test_system
from
xmodule.tests.xml
import
XModuleXmlImportTest
from
xmodule.tests.xml
import
factories
as
xml
...
...
@@ -276,12 +281,12 @@ class SplitTestModuleStudioTest(SplitTestModuleTest):
"""
Tests that the available partitions are populated correctly when editable_metadata_fields are called
"""
self
.
assertEqual
([],
SplitTestDescriptor
.
user_partition_
id
.
values
)
self
.
assertEqual
([],
user_partition_
values
.
values
)
# user_partitions is empty, only the "Not Selected" item will appear.
self
.
split_test_module
.
user_partition_id
=
SplitTestFields
.
no_partition_selected
[
'
value
'
]
self
.
split_test_module
.
editable_metadata_fields
# pylint: disable=pointless-statement
partitions
=
SplitTestDescriptor
.
user_partition_
id
.
values
partitions
=
user_partition_
values
.
values
self
.
assertEqual
(
1
,
len
(
partitions
))
self
.
assertEqual
(
SplitTestFields
.
no_partition_selected
[
'
value
'
],
partitions
[
0
][
'
value
'
])
...
...
@@ -298,7 +303,7 @@ class SplitTestModuleStudioTest(SplitTestModuleTest):
)
]
self
.
split_test_module
.
editable_metadata_fields
# pylint: disable=pointless-statement
partitions
=
SplitTestDescriptor
.
user_partition_
id
.
values
partitions
=
user_partition_
values
.
values
self
.
assertEqual
(
2
,
len
(
partitions
))
self
.
assertEqual
(
SplitTestFields
.
no_partition_selected
[
'
value
'
],
partitions
[
0
][
'
value
'
])
self
.
assertEqual
(
0
,
partitions
[
1
][
'
value
'
])
...
...
@@ -307,7 +312,7 @@ class SplitTestModuleStudioTest(SplitTestModuleTest):
# Try again with a selected partition and verify that there is no option for "No Selection"
self
.
split_test_module
.
user_partition_id
=
0
self
.
split_test_module
.
editable_metadata_fields
# pylint: disable=pointless-statement
partitions
=
SplitTestDescriptor
.
user_partition_
id
.
values
partitions
=
user_partition_
values
.
values
self
.
assertEqual
(
1
,
len
(
partitions
))
self
.
assertEqual
(
0
,
partitions
[
0
][
'
value
'
])
self
.
assertEqual
(
"
first_partition
"
,
partitions
[
0
][
'
display_name
'
])
...
...
@@ -315,7 +320,7 @@ class SplitTestModuleStudioTest(SplitTestModuleTest):
# Finally try again with an invalid selected partition and verify that "No Selection" is an option
self
.
split_test_module
.
user_partition_id
=
999
self
.
split_test_module
.
editable_metadata_fields
# pylint: disable=pointless-statement
partitions
=
SplitTestDescriptor
.
user_partition_
id
.
values
partitions
=
user_partition_
values
.
values
self
.
assertEqual
(
2
,
len
(
partitions
))
self
.
assertEqual
(
SplitTestFields
.
no_partition_selected
[
'
value
'
],
partitions
[
0
][
'
value
'
])
self
.
assertEqual
(
0
,
partitions
[
1
][
'
value
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment