예제 #1
0
파일: test_moodle.py 프로젝트: uu-mofa/mofa
    def test_get_course_by_id_field(self, a):
        moodle_api.get_course_by_id_field(2)

        a.assert_called_with(
            'DUMMY_MOODLE_URL/core_course_get_courses_by_field',
            headers={
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'Authorization': 'DUMMY_MOODLE_TOKEN'
            },
            json={
                'field': 'id',
                'value': 2
            })
예제 #2
0
def create_job(course_id, time_not_active, main_scheduler):
    """
    Call all the methods that are needed to check the inactivity.

    :param course_id: Id of the course the inactivity needs to be checked for.
    :type course_id: int
    :param time_not_active: Time interval the inactivity needs to be checked for.
    :type time_not_active: int
    """
    if (check_if_ended(course_id)):
        main_scheduler.remove_inactivity_notification(course_id)
        return

    time = calculate_date(dt.date.today(), time_not_active)
    if (check_if_older_than(time_not_active, course_id)):
        viewed_courses = ll_api.get_viewed_courses(time, course_id)
        list_viewed = lib.ll_event_parsers.parse_viewed_courses(viewed_courses)
        enrolled_students = parse_enrolled_students(
            moodle_api.get_enrolled_users(course_id))
        course_name = parse_course_info(
            moodle_api.get_course_by_id_field(course_id))
        students = students_not_viewed(enrolled_students, list_viewed,
                                       course_id)
        message = get_message(course_name, time_not_active)
        if len(students) > 0:
            send_message(students, message)
예제 #3
0
def check_if_ended(id):
    """
    Check if the course has already ended.

    :param id: Id of the course that needs to be checked.
    :type id: int
    :return: If a course has ended
    :rtype: bool
    """

    course = moodle_api.get_course_by_id_field(id)
    end_date = course['courses'][0]['enddate']
    if (dt.datetime.fromtimestamp(end_date) < dt.datetime.today()):
        return True
    else:
        return False
예제 #4
0
def check_if_older_than(time_not_active, id):
    """
    Check if the course was created before the time for which inactivity is checked

    :param id: Id of the course that needs to be checked.
    :type id: int
    :param time_not_active: Number of days of inactivity.
    :type time_not_active: int
    :return: If a course was created before
    :rtype: bool
    """
    course = moodle_api.get_course_by_id_field(id)
    time_created = course['courses'][0]['timecreated']
    date_created = dt.date.fromtimestamp(time_created)
    difference = (dt.date.today() - date_created).days
    if (difference < time_not_active):
        return False
    else:
        return True
예제 #5
0
def create_job(course_id, time_not_active):
    """
    Call all the methods that are needs to check the inactivity.

    :param course_id: Id of the course the inactivity needs to be checked for.
    :type course_id: int
    :param time_not_active: Time interval the inactivity needs to be checked for.
    :type time_not_active: int
    """
    time = calculate_date(dt.date.today(), time_not_active)
    viewed_courses = ll_api.get_viewed_courses(time, course_id)
    list_viewed = lib.ll_event_parsers.parse_viewed_courses(viewed_courses)
    enrolled_students = parse_enrolled_students(
        moodle_api.get_enrolled_users(course_id))
    course_name = parse_course_info(
        moodle_api.get_course_by_id_field(course_id))
    students = students_not_viewed(enrolled_students, list_viewed)
    message = get_message(course_name, time_not_active)
    send_message(students, message)