Skip to content

Commit

Permalink
[BB-2132] [YONK-1560] Support JWT creation on openedx ironwood (#27)
Browse files Browse the repository at this point in the history
* Support JWT creation on openedx ironwood

Problem root cause: JwtBuilder class was removed in commit dc56a63e of edx-platform
git repository and the eoc-journal xblock was not updated accordingly.

This patch drops support of all openedx versions before ironwood.

* Set pdfminer version in Python requirements for test environment

pdfminer 20140328 is the last version to support Python 2, used by
EDX platform. Due to this, pdfminer newer versions (20091010 and later)
were breaking the tests.

* Fix tests broken by openedx import

An import of Python package openedx was added in commit 4507e0d, but
the test environment does not have that Python package. To avoid
breaking the tests, this patch:

- ignores the import error in Pylint check.
- move the import to inside the function, which is not called in tests
  because the methods which call it are already mocked

* Create a Python module which contains edx-platform dependent code

* Version bump
  • Loading branch information
alanoe authored Mar 4, 2020
1 parent 32dfc05 commit 68722aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
14 changes: 14 additions & 0 deletions eoc_journal/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
edx-platform dependent code
"""
# pylint: disable=import-error


def create_jwt_for_user(user):
"""
Wraps openedx.core.djangoapps.oauth_dispatch.jwt.create_jwt_for_user() call
"""
# test env does not have edx-platform installed. because of this, all edx-platform imports must be
# kept inside this function so that the test code does not break when importing the module
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user as openedx_create_jwt_for_user
return openedx_create_jwt_for_user(user)
10 changes: 3 additions & 7 deletions eoc_journal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

from edx_rest_api_client.client import EdxRestApiClient

try:
from openedx.core.lib.token_utils import JwtBuilder # pylint: disable=F0401
except ImportError:
JwtBuilder = None # pylint: disable=C0103
from .compat import create_jwt_for_user


def normalize_id(key):
Expand All @@ -31,9 +28,8 @@ def build_jwt_edx_client(url, scopes, user, expires_in, append_slash=True):
"""
Returns an edx API client authorized using JWT.
"""
if JwtBuilder is None:
raise NotConnectedToOpenEdX("This package must be installed in an OpenEdX environment.")
jwt = JwtBuilder(user).build_token(scopes, expires_in)

jwt = create_jwt_for_user(user)
return EdxRestApiClient(url, append_slash=append_slash, jwt=jwt)


Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fs
lxml
mako
markupsafe
pdfminer
pdfminer==20140328
pycodestyle
pylint
python-dateutil
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def package_data(pkg, roots):

setup(
name='xblock-eoc-journal',
version='0.4',
version='0.5',
description='End of Course Journal XBlock',
packages=[
'eoc_journal',
Expand Down

0 comments on commit 68722aa

Please sign in to comment.