Skip to content

Commit

Permalink
feat: return no result if skill validation is disable for a course
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-ammar committed Mar 22, 2024
1 parent dfba55d commit 3142756
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Change Log
Unreleased

[1.50.0] - 2024-03-21
---------------------
* feat: For taxonomy/api/v1/xblocks/ api, send no result if skill validation is disabled for the course.

[1.46.2] - 2024-02-14
---------------------
* feat: Optimized finalize_xblockskill_tags command for memory via chunking
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# 2. MINOR version when you add functionality in a backwards compatible manner, and
# 3. PATCH version when you make backwards compatible bug fixes.
# More details can be found at https://semver.org/
__version__ = '1.46.2'
__version__ = '1.50.0'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
8 changes: 8 additions & 0 deletions taxonomy/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
XBlockSkillData,
XBlockSkills,
)
from taxonomy.providers.utils import get_course_metadata_provider


class TaxonomyAPIViewSetMixin:
Expand Down Expand Up @@ -301,7 +302,14 @@ class XBlockSkillsViewSet(TaxonomyAPIViewSetMixin, RetrieveModelMixin, ListModel
def get_queryset(self):
"""
Get all the xblocks skills with prefetch_related objects.
If skill validation is disabled for a course, then return an empty queryset.
"""
course_run_key = self.request.query_params.get('course_key')
skill_validation_disabled = get_course_metadata_provider().skill_validation_disabled(course_run_key)
if skill_validation_disabled:
return XBlockSkills.objects.none()

return XBlockSkills.objects.prefetch_related(
Prefetch(
'skills',
Expand Down
12 changes: 12 additions & 0 deletions taxonomy/providers/course_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ def get_all_courses(self):
4. short_description: Course's short description
5. full_description: Course's full description
"""

@abstractmethod
def skill_validation_disabled(self, course_run_key) -> bool:
"""
Get whether skill validation is disabled for a course.
Arguments:
course_run_key(str): A course run key.
Returns:
bool: `True` if skill validation is disabled for the course run, `False` otherwise.
"""
11 changes: 11 additions & 0 deletions taxonomy/validators/course_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
All host platform must run this validator to make sure providers are working as expected.
"""
import inspect

from taxonomy.providers.utils import get_course_metadata_provider


Expand Down Expand Up @@ -32,6 +34,7 @@ def validate(self):
"""
self.validate_get_courses()
self.validate_get_all_courses()
self.validate_skill_validation_disabled()

def validate_get_courses(self):
"""
Expand Down Expand Up @@ -60,3 +63,11 @@ def validate_get_all_courses(self):
assert 'title' in course
assert 'short_description' in course
assert 'full_description' in course

def validate_skill_validation_disabled(self):
"""
Validate `skill_validation_disabled` methods has the correct interface implemented.
"""
skill_validation_disabled_func = getattr(self.course_metadata_provider, 'skill_validation_disabled') # pylint: disable=literal-used-as-attribute
assert callable(skill_validation_disabled_func)
assert str(inspect.signature(skill_validation_disabled_func)) == '(course_run_key) -> bool'
6 changes: 6 additions & 0 deletions test_utils/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def get_all_courses(self):
'full_description': course.full_description,
}

def skill_validation_disabled(self, course_run_key) -> bool:
"""
Whether skill validation is disabled for the course.
"""
return bool(course_run_key)


class DiscoveryProgramMetadataProvider(ProgramMetadataProvider):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,14 @@ def test_xblocks_api_filtering(self):
})
self._verify_xblocks_data(api_response, self.xblock_skills[:1], verified=False)

def test_xblocks_api_with_skill_validation_disabled(self):
"""
Verify that xblocks API return no result if skill validation is disabled for a course.
"""
api_response = self.client.get(self.view_url, {"course_key": 'course-v1:edX+M12+1T2024'})
assert api_response.status_code == 200
assert api_response.json() == []


@mark.django_db
class TestJobPathAPIView(TestCase):
Expand Down

0 comments on commit 3142756

Please sign in to comment.