Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
problem-builder
Commits
6af86c3d
Commit
6af86c3d
authored
Sep 11, 2014
by
dragonfi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add StepMixin
parent
0c0ce8d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
0 deletions
+97
-0
mentoring/step.py
+21
-0
test/unit/__init__.py
+0
-0
test/unit/test_step.py
+76
-0
No files found.
mentoring/step.py
0 → 100644
View file @
6af86c3d
class
StepParentMixin
(
object
):
"""
A parent containing the Step objects
The parent must have a get_children_objects() method.
"""
@property
def
steps
(
self
):
return
[
child
for
child
in
self
.
get_children_objects
()
if
isinstance
(
child
,
StepMixin
)]
class
StepMixin
(
object
):
@property
def
step_number
(
self
):
return
self
.
parent
.
steps
.
index
(
self
)
+
1
@property
def
lonely_step
(
self
):
if
self
not
in
self
.
parent
.
steps
:
raise
ValueError
(
"Step's parent should contain Step"
,
self
,
self
.
parents
.
steps
)
return
len
(
self
.
parent
.
steps
)
==
1
test/unit/__init__.py
0 → 100644
View file @
6af86c3d
test/unit/test_step.py
0 → 100644
View file @
6af86c3d
import
unittest
from
lxml
import
etree
from
mentoring
import
MentoringBlock
import
mentoring
from
mentoring.step
import
StepMixin
,
StepParentMixin
class
Parent
(
StepParentMixin
):
def
get_children_objects
(
self
):
return
list
(
self
.
_children
)
def
_set_children_for_test
(
self
,
*
children
):
self
.
_children
=
children
for
child
in
self
.
_children
:
try
:
child
.
parent
=
self
except
AttributeError
:
pass
class
Step
(
StepMixin
):
def
__init__
(
self
):
pass
class
NotAStep
(
object
):
pass
class
TestStepMixin
(
unittest
.
TestCase
):
def
test_single_step_is_returned_correctly
(
self
):
block
=
Parent
()
step
=
Step
()
block
.
_children
=
[
step
]
self
.
assertSequenceEqual
(
block
.
steps
,
[
step
])
def
test_only_steps_are_returned
(
self
):
block
=
Parent
()
step1
=
Step
()
step2
=
Step
()
block
.
_set_children_for_test
(
step1
,
1
,
"2"
,
"Step"
,
NotAStep
(),
False
,
step2
,
NotAStep
())
self
.
assertSequenceEqual
(
block
.
steps
,
[
step1
,
step2
])
def
test_proper_number_is_returned_for_step
(
self
):
block
=
Parent
()
step1
=
Step
()
step2
=
Step
()
block
.
_set_children_for_test
(
step1
,
1
,
"2"
,
"Step"
,
NotAStep
(),
False
,
step2
,
NotAStep
())
self
.
assertEquals
(
step1
.
step_number
,
1
)
self
.
assertEquals
(
step2
.
step_number
,
2
)
def
test_the_number_does_not_represent_the_order_of_creation
(
self
):
block
=
Parent
()
step1
=
Step
()
step2
=
Step
()
block
.
_set_children_for_test
(
step2
,
1
,
"2"
,
"Step"
,
NotAStep
(),
False
,
step1
,
NotAStep
())
self
.
assertEquals
(
step1
.
step_number
,
2
)
self
.
assertEquals
(
step2
.
step_number
,
1
)
def
test_lonely_step_is_true_for_stand_alone_steps
(
self
):
block
=
Parent
()
step1
=
Step
()
block
.
_set_children_for_test
(
1
,
"2"
,
step1
,
"Step"
,
NotAStep
(),
False
)
self
.
assertTrue
(
step1
.
lonely_step
)
def
test_lonely_step_is_true_if_parent_have_more_steps
(
self
):
block
=
Parent
()
step1
=
Step
()
step2
=
Step
()
block
.
_set_children_for_test
(
1
,
step2
,
"2"
,
step1
,
"Step"
,
NotAStep
(),
False
)
self
.
assertFalse
(
step1
.
lonely_step
)
self
.
assertFalse
(
step2
.
lonely_step
)
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