Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-milestones
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-milestones
Commits
8313a283
Commit
8313a283
authored
Jul 13, 2016
by
Kevin Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new XBlock runtime service 'MilestonesService'
parent
d63216f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
1 deletions
+84
-1
milestones/services.py
+46
-0
milestones/tests/test_services.py
+37
-0
setup.py
+1
-1
No files found.
milestones/services.py
0 → 100644
View file @
8313a283
"""
A wrapper class around requested methods exposed in api.py
"""
import
types
from
milestones
import
api
as
milestones_api
class
MilestonesService
(
object
):
# pylint: disable=too-few-public-methods
"""
An xBlock service for xBlocks to talk to the Milestones subsystem.
NOTE: This is a Singleton class. We should only have one instance of it!
"""
_instance
=
None
REQUESTED_FUNCTIONS
=
[
'get_course_content_milestones'
,
]
def
__new__
(
cls
,
*
args
,
**
kwargs
):
"""
This is the class factory to make sure this is a Singleton
"""
if
not
cls
.
_instance
:
cls
.
_instance
=
super
(
MilestonesService
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
return
cls
.
_instance
def
__init__
(
self
):
"""
Class initializer, which just inspects the libraries and exposes the same functions
listed in REQUESTED_FUNCTIONS
"""
self
.
_bind_to_requested_functions
()
def
_bind_to_requested_functions
(
self
):
"""
bind module functions. Since we use underscores to mean private methods, let's exclude those.
"""
for
attr_name
in
self
.
REQUESTED_FUNCTIONS
:
attr
=
getattr
(
milestones_api
,
attr_name
,
None
)
if
isinstance
(
attr
,
types
.
FunctionType
)
and
not
attr_name
.
startswith
(
'_'
):
if
not
hasattr
(
self
,
attr_name
):
setattr
(
self
,
attr_name
,
attr
)
milestones/tests/test_services.py
0 → 100644
View file @
8313a283
"""
Test for the xBlock service
"""
import
unittest
import
types
from
milestones.services
import
MilestonesService
from
milestones
import
api
as
milestones_api
class
TestMilestonesService
(
unittest
.
TestCase
):
# pylint: disable=too-many-public-methods
"""
Tests for MilestonesService
"""
def
test_basic
(
self
):
"""
See if the MilestonesService exposes the expected methods
"""
service
=
MilestonesService
()
for
attr_name
in
dir
(
milestones_api
):
attr
=
getattr
(
milestones_api
,
attr_name
,
None
)
if
isinstance
(
attr
,
types
.
FunctionType
)
and
not
attr_name
.
startswith
(
'_'
):
if
attr_name
in
MilestonesService
.
REQUESTED_FUNCTIONS
:
self
.
assertTrue
(
hasattr
(
service
,
attr_name
))
else
:
self
.
assertFalse
(
hasattr
(
service
,
attr_name
))
def
test_singleton
(
self
):
"""
Test to make sure the MilestonesService is a singleton.
"""
service1
=
MilestonesService
()
service2
=
MilestonesService
()
self
.
assertIs
(
service1
,
service2
)
setup.py
View file @
8313a283
...
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
...
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup
(
setup
(
name
=
'edx-milestones'
,
name
=
'edx-milestones'
,
version
=
'0.1.
8
'
,
version
=
'0.1.
9
'
,
description
=
'Significant events module for Open edX'
,
description
=
'Significant events module for Open edX'
,
long_description
=
open
(
'README.md'
)
.
read
(),
long_description
=
open
(
'README.md'
)
.
read
(),
author
=
'edX'
,
author
=
'edX'
,
...
...
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