Skip to content

Commit

Permalink
fix: update waffle switch in edx-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielC1409 committed Feb 24, 2025
1 parent e6a85b5 commit 6cf11f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions xmodule/capa/tests/test_xqueue_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest


@pytest.mark.django_db
@skip_unless_lms
class XQueueServiceTest(TestCase):
"""Test the XQueue service methods."""
Expand Down
2 changes: 2 additions & 0 deletions xmodule/capa/tests/test_xqueue_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
from xmodule.capa.xqueue_submission import XQueueInterfaceSubmission
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
from opaque_keys.edx.keys import UsageKey, CourseKey
from xblock.fields import ScopeIds


Expand Down Expand Up @@ -40,6 +41,7 @@ def test_extract_item_data():
assert score == 0.85


@pytest.mark.django_db
@patch('submissions.api.create_submission')
def test_send_to_submission(mock_create_submission, xqueue_service):
header = json.dumps({
Expand Down
11 changes: 9 additions & 2 deletions xmodule/capa/xqueue_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def _send_to_queue(self, header, body, files_to_upload): # lint-amnesty, pylint
# Use the new edx-submissions workflow
submission = XQueueInterfaceSubmission().send_to_submission(header, body, files)
log.error(submission)
return None, ''

return self._http_post(self.url + '/xqueue/submit/', payload, files=files)
else:
return self._http_post(self.url + '/xqueue/submit/', payload, files=files)

def _http_post(self, url, data, files=None): # lint-amnesty, pylint: disable=missing-function-docstring
try:
Expand Down Expand Up @@ -191,8 +193,13 @@ def construct_callback(self, dispatch: str = 'score_update') -> str:
"""
Return a fully qualified callback URL for external queueing system.
"""
if switch_is_active('callback_submission.enabled'):
dispatch_callback = "callback_submission"
else:
dispatch_callback = 'xqueue_callback'

relative_xqueue_callback_url = reverse(
'xqueue_callback',
dispatch_callback,
kwargs=dict(
course_id=str(self._block.scope_ids.usage_id.context_key),
userid=str(self._block.scope_ids.user_id),
Expand Down
16 changes: 5 additions & 11 deletions xmodule/capa/xqueue_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ def extract_item_data(self, header, payload):
if not callback_url:
raise ValueError("El header is not content 'lms_callback_url'.")

match_item_id = re.search(r'(block-v1:[^/]+)', callback_url)
match_course_id = re.search(r'(course-v1:[^\/]+)', callback_url)
match_item_type = re.search(r'type@([^+]+)', callback_url)

if not (match_item_id and match_item_type and match_course_id):
raise ValueError(f"The callback_url is not valid: {callback_url}")

item_id = match_item_id.group(1)
item_type = match_item_type.group(1)
course_id = match_course_id.group(1)
item_id = re.search(r'block@([^\/]+)', callback_url).group(1)
item_type = re.search(r'type@([^+]+)', callback_url).group(1)
course_id = re.search(r'(course-v1:[^\/]+)', callback_url).group(1)

try:
student_info = json.loads(payload["student_info"])
Expand All @@ -70,6 +63,7 @@ def extract_item_data(self, header, payload):
usage_key = BlockUsageLocator.from_string(item_id)
course_key = CourseKey.from_string(course_id)

full_block_id = f"block-v1:{course_id.replace('course-v1:', '')}+type@{item_type}+block@{item_id}"
try:
grader_payload = payload["grader_payload"]
if isinstance(grader_payload, str):
Expand All @@ -85,7 +79,7 @@ def extract_item_data(self, header, payload):
raise ValueError("The field 'anonymous_student_id' is not student_info.")

student_dict = {
'item_id': item_id,
'item_id': full_block_id,
'item_type': item_type,
'course_id': course_id,
'student_id': student_id
Expand Down

0 comments on commit 6cf11f1

Please sign in to comment.