from opaque_keys.edx.keys import CourseKey
from opaque_keys import InvalidKeyError
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.django import modulestore
from courseware.courses import get_course_by_id, get_course_about_section
from courseware.tests.helpers import get_request_for_user
from courseware.module_render import get_module
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview


def get_course_key(course_id):
    course_key = ""
    try:
        course_key = CourseKey.from_string(course_id)
    except InvalidKeyError:
        course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    return course_key


def get_course(course_id):
    course_key = get_course_key(course_id)
    course = get_course_by_id(course_key)
    return course


def get_course_title(course_id):
    course_key = get_course_key(course_id)
    title = CourseOverview.get_from_id(course_key).display_name
    return title


def get_course_description(course_id, user_id):
    course = get_course(course_id)
    user = User.objects.get(user_id)
    request = get_request_for_user(user)
    module = get_module(user, request, course.location.replace(category='about', name="short_description"), [])
    return module.data

    get_course_about_section(course, "short_description")


def get_usage_key(course_id, module_id):
    """
    Get the usage key of sequential block
    Can be :
        i4x://test/TEST101/sequential/45b889d710424143aa7f13e7c4bc0446
        or
        block-v1:ORG+TEST101+RUNCODE+type@sequential+block@45b889d710424143aa7f13e7c4bc0446
    depending on modulestore
    """
    course_key = CourseKey.from_string(course_id)
    items = modulestore().get_items(course_key, qualifiers={'name': module_id})
    return items[0].location.to_deprecated_string()

@@ -267,66 +267,8 @@
 ion%0A
-from courseware.tests.helpers import get_request_for_user%0A
 from
@@ -394,16 +394,365 @@
 verview%0A
+from django.test.client import RequestFactory%0A%0A%0Adef get_request_for_user(user):%0A    %22%22%22Create a request object for user.%22%22%22%0A    request = RequestFactory()%0A    request.user = user%0A    request.COOKIES = %7B%7D%0A    request.META = %7B%7D%0A    request.is_secure = lambda: True%0A    request.get_host = lambda: %22edx.org%22%0A    request.method = 'GET'%0A    return request
 %0A%0Adef ge

Remove dependencies from courseware.test as create problem with import