Exemple #1
0
    def test_base_edx_client_calls(self, mock_edx_get_course_blocks,
                                   mock_edx_get_provider_courses,
                                   mock_get_oauth_access_token):
        """
        Check that get_course_blocks and get_provider_courses called from the edx api client.

        We use the id of the content source equal to 5 because in fixture this source has type `edx`
        """
        get_available_blocks(4)
        mock_edx_get_course_blocks.assert_called_once()

        get_available_courses(4)
        mock_edx_get_provider_courses.assert_called_once()
Exemple #2
0
    def test_base_api_client_calls(self, mock_base_get_course_blocks,
                                   mock_edx_get_course_blocks,
                                   mock_base_get_provider_courses,
                                   mock_edx_get_provider_courses):
        """
        Check that get_course_blocks and get_provider_courses called from the correct place.

        We use the id of the content source equal to 5 because in fixture this source has type `base`
        """
        get_available_blocks(5)
        mock_base_get_course_blocks.assert_called_once()
        mock_edx_get_course_blocks.assert_not_called()

        get_available_courses(5)
        mock_base_get_provider_courses.assert_called_once()
        mock_edx_get_provider_courses.assert_not_called()
Exemple #3
0
def sources(request):
    """
    Content Source backend endpoint.

    Uses OpenEdx Course API v.1.0
    :param request:
    :return: (JSON) blocks
    """
    source_id, course_id, error = check_source_course(request)

    if error:
        return error
    try:
        sources_list = get_available_blocks(source_id=source_id,
                                            course_id=course_id)
    except ObjectDoesNotExist as exc:
        return HttpResponseBadRequest(reason={"error": exc.message})
    except HttpClientError as exc:
        return HttpResponseNotFound(reason={"error": exc.message})

    return JsonResponse(data=sources_list, safe=False)