Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions openedx/core/djangoapps/catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,35 @@ def get_course_data(course_key_str, fields):
)
if data:
return data


def get_course_run_data(course_run_id, fields):
"""
Retrieve information about the course run with the given course run id.

Arguments:
course_run_id: key for the course run about which we are retrieving information.
fields (List, string): The given fields that you want to retrieve from API response.

Returns:
dict with details about specified course run.
"""
user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Course Run ID')
if user:
api_client = get_catalog_api_client(user)
base_api_url = get_catalog_api_base_url()
if course_run_id:
course_run_cache_key = f'{catalog_integration.CACHE_KEY}.course_run.{course_run_id}'
data = get_api_data(
catalog_integration,
'course_runs',
resource_id=course_run_id,
api_client=api_client,
base_api_url=base_api_url,
cache_key=course_run_cache_key if catalog_integration.is_cache_enabled else None,
long_term_cache=True,
many=False,
fields=fields
)
if data:
return data
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ def setUp(self):
self.catalog_integration = self.create_catalog_integration()

@mock.patch('openedx.core.djangoapps.user_api.learner_skill_levels.utils.get_course_run_ids')
@mock.patch('openedx.core.djangoapps.user_api.learner_skill_levels.utils.get_course_run_data')
@mock.patch('openedx.core.djangoapps.user_api.learner_skill_levels.utils.get_course_data')
def test_generate_skill_score_mapping(
self,
mock_get_course_data,
mock_get_course_run_data,
mock_get_course_run_ids,
):
"""
Test that skill-score mapping is returned in correct format.
"""
user = UserFactory(username='edX')
mock_get_course_run_ids.return_value = ['AWS+OTP-AWSD12']
mock_get_course_run_ids.return_value = ['course-v1:AWS+OTP-AWSD12']
mock_get_course_run_data.return_value = {'course': 'AWS+OTP'}
mock_get_course_data.return_value = DUMMY_COURSE_DATA_RESPONSE
result = generate_skill_score_mapping(user)
expected_response = {"python": 3, "MongoDB": 3, "Data Science": 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
}

DUMMY_COURSE_DATA_RESPONSE = {
"key": "AWS+OTP-AWSD12",
"key": "AWS+OTP",
"uuid": "fe1a9ad4-a452-45cd-80e5-9babd3d43f96",
"title": "Demonstration Course",
"level_type": 'Advanced',
Expand Down
12 changes: 8 additions & 4 deletions openedx/core/djangoapps/user_api/learner_skill_levels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get_catalog_api_base_url,

)
from openedx.core.djangoapps.catalog.utils import get_course_data
from openedx.core.djangoapps.catalog.utils import get_course_data, get_course_run_data
from openedx.core.lib.edx_api_utils import get_api_data

from .constants import LEVEL_TYPE_SCORE_MAPPING
Expand All @@ -37,13 +37,17 @@ def generate_skill_score_mapping(user):

skill_score_mapping = {}
for course_run_id in course_run_ids:
course_data = get_course_data(course_run_id, ['skill_names', 'level_type'])
# fetch course details from course run id to get course key
course_run_data = get_course_run_data(course_run_id, ['course'])
Comment thread
sameenfatima78 marked this conversation as resolved.

# fetch course details to get level type and skills
course_data = get_course_data(course_run_data['course'], ['skill_names', 'level_type'])
Comment thread
sameenfatima78 marked this conversation as resolved.
skill_names = course_data['skill_names']
level_type = course_data['level_type'].capitalize()
level_type = course_data['level_type']

# if a level_type is None for a course, we should skip that course.
if level_type:
score = LEVEL_TYPE_SCORE_MAPPING[level_type]
score = LEVEL_TYPE_SCORE_MAPPING[level_type.capitalize()]
for skill in skill_names:
if skill in skill_score_mapping:
# assign scores b/w 1-3 based on level type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from copy import deepcopy

from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from rest_framework import permissions
from rest_framework import permissions, status
from rest_framework.response import Response
from rest_framework.views import APIView

Expand Down Expand Up @@ -93,6 +93,11 @@ def get(self, request, job_id):
"""
# get top categories for the given job
job_skill_categories = get_top_skill_categories_for_job(job_id)
if not job_skill_categories:
return Response(
Comment thread
sameenfatima78 marked this conversation as resolved.
status=status.HTTP_404_NOT_FOUND,
data={'message': "The job id doesn't exist, enter a valid job id."}
Comment thread
sameenfatima78 marked this conversation as resolved.
)

# assign scores for every skill request user has learned
top_categories = deepcopy(job_skill_categories['skill_categories'])
Expand Down