def serialize_content_file_for_bulk_deletion(content_file_obj):
    """
    Serialize a content file for bulk API request

    Args:
        content_file_obj (ContentFile): A content file for a course
    """
    return {"_id": gen_content_file_id(content_file_obj.key), "_op_type": "delete"}
Beispiel #2
0
def test_serialize_content_file_for_bulk_deletion():
    """
    Test that serialize_content_file_for_bulk_deletion yields a valid ESContentFileSerializer
    """
    content_file = ContentFileFactory.create()
    assert serialize_content_file_for_bulk_deletion(content_file) == {
        "_id": gen_content_file_id(content_file.key),
        "_op_type": "delete",
    }
Beispiel #3
0
def test_serialize_content_file_for_bulk():
    """
    Test that serialize_content_file_for_bulk yields a valid ESContentFileSerializer
    """
    content_file = ContentFileFactory.create()
    assert serialize_content_file_for_bulk(content_file) == {
        "_id": gen_content_file_id(content_file.key),
        **ESContentFileSerializer(content_file).data,
    }
def test_delete_content_file(mocker):
    """Tests that deleting a content_file triggers the correct ES delete task"""
    patched_delete_task = mocker.patch("search.task_helpers.delete_document")
    content_file = ContentFileFactory.create()
    delete_content_file(content_file)
    assert patched_delete_task.delay.called is True
    assert patched_delete_task.delay.call_args[0] == (
        gen_content_file_id(content_file.key),
        COURSE_TYPE,
    )
def serialize_content_file_for_bulk(content_file_obj):
    """
    Serialize a content file for bulk API request

    Args:
        content_file_obj (ContentFile): A content file for a course
    """
    return {
        "_id": gen_content_file_id(content_file_obj.key),
        **ESContentFileSerializer(content_file_obj).data,
    }
Beispiel #6
0
def delete_content_file(content_file_obj):
    """
    Runs a task to delete an ES CourseRunFile document

    Args:
        content_file_obj (course_catalog.models.ContentFile): A CourseRunFile object
    """
    course = content_file_obj.run.content_object
    delete_document.delay(
        gen_content_file_id(content_file_obj.key),
        COURSE_TYPE,
        routing=gen_course_id(course.platform, course.course_id),
    )
def test_delete_course(mocker):
    """
    Tests that delete_course calls the delete tasks for the course and its content files
    """
    patched_delete_task = mocker.patch("search.task_helpers.delete_document")
    course = CourseFactory.create()
    course_es_id = gen_course_id(course.platform, course.course_id)
    content_files = [ContentFileFactory.create(run=run) for run in course.runs.all()]

    delete_course(course)
    patched_delete_task.delay.assert_any_call(course_es_id, COURSE_TYPE)
    for content_file in content_files:
        patched_delete_task.delay.assert_any_call(
            gen_content_file_id(content_file.key), COURSE_TYPE, routing=course_es_id
        )
Beispiel #8
0
def upsert_content_file(file_id):
    """Upsert content file based on stored database information"""

    content_file_obj = ContentFile.objects.get(id=file_id)
    content_file_data = ESContentFileSerializer(content_file_obj).data
    api.upsert_document(
        gen_content_file_id(content_file_obj.key),
        content_file_data,
        COURSE_TYPE,
        retry_on_conflict=settings.INDEXING_ERROR_RETRIES,
        routing=gen_course_id(
            content_file_obj.run.content_object.platform,
            content_file_obj.run.content_object.course_id,
        ),
    )