예제 #1
0
def test_update_groupings(test):
    if test == '0':
    # Update a grouping manually
        print 'Required parameters: Grouping ID'
        show(t.update_groupings([{'id':raw_input(),
                                  'name':'Python Grouping updated',
                                  'description':'Test grouping updated with Python library'}]))
예제 #2
0
def test_get_strings(test):
    if test == '0':
        # Get a string manually
        print "Required parameter: stringid"
        show(t.get_strings([{'stringid':raw_input()}]))
    elif test == '1':
        # Get a string manually with optional parameters
        print "Required parameter: stringid, component, lang, stringparams name, stringparams value"
        show(t.get_strings([{'stringid':raw_input(),
                           'component':raw_input(),
                           'lang': raw_input(),
                           'stringparams':[{'name':raw_input(),'value':raw_input()}]
                          }]))
    elif test == '2':
        print "Required parameter: stringid, component, lang, stringparams name, stringparams value"
        show(t.get_strings([{'stringid':'groups',
                           'stringparams':[{'name':'stringname','value':'stringvalue'}]
                          }]))
    elif test == '3':
        show(t.get_strings([{'stringid':'groupid'}]))
    #Errors
    elif test == '4':
        #Produces a 500 internal server error
        print "Required parameter: stringid, component, lang, stringparams name, stringparams value"
        show(t.get_strings([{'stringid':'groups',
                           'stringparams':[{'name':'','value':'stringvalue'}]
                          }]))
예제 #3
0
def test_create_groups(test):
    if test == '0':
    # Create a group in a course manually
        print 'Required parameters: Course ID'
        show(t.create_groups([{'courseid':raw_input(),
                               'name':'Python Group',
                               'description':'Test group created with Python library'}]))
예제 #4
0
def test_unassign_roles(test):
    if test == '0':
        # Unassign a role to a user manually
        print "Required parameters: roleid, userid and contextid"
        show(t.unassign_roles([{'roleid': raw_input(),
                              'userid': raw_input(),
                              'contextid': raw_input()}]))
    elif test == '1':
        #Unassign a role to a user
        show(t.unassign_roles([{'roleid': '2',
                              'userid':'4' ,
                              'contextid': '1'}]))
예제 #5
0
def test_update_users():
    # Change a user name
    print 'Required parameters: id of the user to change its name'
    origUser = t.get_users_by_field('id',[raw_input()])[0]
    show(t.update_users([{'id':origUser['id'],
                       'username':'******',
                       'firstname':'Changed'}]))
    print "Press enter to restore its original user's name"
    raw_input()
    show(t.update_users([{'id':origUser['id'],
                       'username':origUser['username'],
                       'firstname':origUser['firstname']}]))
예제 #6
0
def test_get_forum_discussions(test):
    if test == '0':
    # Get discussions from 1 forum manually
        print 'Forum ID:'
        show(t.get_forum_discussions([raw_input()]))
    elif test == '1':
        show(t.get_forum_discussions([1,4]))
    # Errors
    elif test == '2':
        show(t.get_forum_discussions(1))
    elif test == '3':
        show(t.get_forum_discussions([-1]))
    elif test == '4':
        show(t.get_forum_discussions(['a']))
예제 #7
0
def test_get_submissions(test):
    if test == '0':
    # Manually show 1 assignment submissions 
        print 'Assignment ID to show submissions:'
        show(t.get_submissions([raw_input()]))
    elif test == '1':
        show(t.get_submissions([1]))
    elif test == '2':
        show(t.get_submissions([1],'submitted',1362385052, 1362385052))
    # Errors
    elif test == '3':
        show(t.get_submissions(['a']))
    elif test == '4':
        show(t.get_submissions([1],'submitted','a'))
예제 #8
0
def test_create_notes(test):
    if test == '0':
        # Create a note manually
        print "Required parameters: userid, publishstate('personal', 'course' or 'site'), courseid and text"
        show(t.create_notes([{'userid': raw_input(),
                              'publishstate': raw_input(),
                              'courseid': raw_input(),
                              'text': raw_input()}]))
    elif test == '1':
        # Create a personal note
        show(t.create_notes([{'userid': '3',
                              'publishstate':'personal' ,
                              'courseid': '2',
                              'text': 'Python library test note'}]))
    elif test == '2':
        # Create a site note
        show(t.create_notes([{'userid': '3',
                              'publishstate':'site',
                              'courseid': '2',
                              'text': 'Python library test note'}]))
    # Errors
    elif test == '3':
        # Create a site note without course id
        show(t.create_notes([{'userid': '3',
                              'publishstate':'site' ,
                              'text': 'Python library test note'}]))
예제 #9
0
def test_create_cohorts(test):
    if test == '0':
    #  Create 1 cohort manually
        print 'Required parameters: type("id", "idnumber" or "system"), value, name, idnumber'
        show(t.create_cohorts([{'type':raw_input(),
                                'value':raw_input(),
                                'name':raw_input(),
                                'idnumber':raw_input()}]))
    elif test == '1':
    # Create 1 cohort
        show(t.create_cohorts([{'type':'id',
                                'value':'1',
                                'name':'Python Cohort',
                                'idnumber':'35',
                                'description':'This cohort has been created with the MoodLib python library.'}]))
예제 #10
0
def test_get_files(test):
    if test == '0':
    # Manually get 1 file
        print 'Parameters: contextid, component, filearea, itemid, filepath, filename'
        show(t.get_files(raw_input(), raw_input(), raw_input(), raw_input(), raw_input(), raw_input()))
    elif test == '1':
        show(t.get_files(45,
                         'assignsubmission_file',
                         'submission_files',
                         1,
                         '/',
                         ''))
    # Errors
    elif test == '2':
        show(t.get_files(45, 'assignsubmission_file', 'submission_files', 1, '/'))
    elif test == '3':
        show(t.get_files('', 'assignsubmission_file', 'submission_files', 1, '/', ''))
    elif test == '4':
        show(t.get_files(45, 'assignsubmission_file', 'submission_files', 'a', '/', ''))
예제 #11
0
def test_get_users(test):
    if test == '0':
        # Manually search users 
        print 'Required parameters: key ("id", "lastname", "firstname", "idnumber", "username", "email" or "auth"), value'
        show(t.get_users([{'key':raw_input(),
                           'value':raw_input()}]))
    elif test == '1':
        # Search the user with the userid = 3
        show(t.get_users([{'key':'id',
                           'value':'3'}]))
    elif test == '2':
        # Search without criteria: return all users and a warning (value field cannot be empty)
        show(t.get_users([{'key':'',
                           'value':'3'}]))
    elif test == '3':
        # Search using '%' character: search all users whose firstname contains an 'a'
        show(t.get_users([{'key':'firstname',
                           'value':'a%'}]))
    #Errors
    elif test == '4':
        show(t.get_users([]))
예제 #12
0
def test_get_string(test):
    if test == '0':
        # Get a string manually
        print "Required parameter: stringid"
        show(t.get_string(raw_input()))
    elif test == '1':
        # Get a string manually with optional parameters
        print "Required parameter: stringid, component, lang, stringparams name, stringparams value"
        show(t.get_string(raw_input(), raw_input(), raw_input(),
                          [{'name':raw_input(),'value':raw_input()}]))
    elif test == '2':
        show(t.get_string('groups',
                          stringparams=[{'name':'stringname','value':'id'}]))
    elif test == '3':
        show(t.get_string('groups'))
예제 #13
0
def test_update_cohorts(test):
    if test == '0':
    #  Create 1 cohort manually
        print 'Required parameters: "id", type("id", "idnumber" or "system"), value, name, idnumber'
        show(t.update_cohorts([{'type':raw_input(),
                                'value':raw_input(),
                                'name':raw_input(),
                                'idnumber':raw_input()}]))
    elif test == '1':
    # Update 1 cohort
        show(t.update_cohorts([{'id':4,
                                'type':'id',
                                'value':'1',
                                'name':'Python Cohort',
                                'idnumber':'35',
                                'description':'This cohort has been created with the MoodLib python library.'}]))
    elif test == '2':
    # Update 1 cohort
        show(t.update_cohorts([{'id':4,
                                'type':'id',
                                'value':'2',
                                'name':'Python Cohort Changed',
                                'idnumber':'36',
                                'description':'This cohort has been changed with the MoodLib python library.'}]))
    elif test == '3':
    # Update 1 cohort
        show(t.update_cohorts([{'id':1,
                                'type':'system',
                                'value':'1',
                                'name':'Cohort1',
                                'idnumber':''}]))
    # Error
    elif test == '4':
        show(t.update_cohorts([{'id':4,
                                'type':'id',
                                'value':'1',
                                'idnumber':'36'}]))
예제 #14
0
def test_get_definitions(test):
    if test == '0':
        # get grades definitions manually
        print "Required parameters: course module id and area name"
        show(t.get_definitions([raw_input()], raw_input()))
    elif test == '1':
        # get a grade definitions
        show(t.get_definitions(['5'], 'resource'))
    # Errors
    elif test == '2':
        # get a grade definitions
        show(t.get_definitions(['50000'], 'resource'))
예제 #15
0
def test_add_cohort_members(test):
    if test == '0':
    #  Adds a user to a cohort manually
        print 'Required parameters: cohorttype("id" or "idnumber"), cohortvalue, usertype("id" or "username"), uservalue'
        show(t.add_cohort_members([{'cohorttype':
                                        {'type':raw_input(),
                                         'value':raw_input()},
                                    'usertype':
                                        {'type':raw_input(),
                                         'value':raw_input()}}
                                   ]))
    elif test == '1':
    # Add a member using user and cohort IDs
        show(t.add_cohort_members([{'cohorttype':
                                        {'type':'id',
                                         'value':'1'},
                                    'usertype':
                                        {'type':'id',
                                         'value':'3'}
                                    }]))
    elif test == '2':
    # Add a member using username and cohort idnumber
        show(t.add_cohort_members([{'cohorttype':
                                        {'type':'idnumber',
                                         'value':'35'},
                                    'usertype':
                                        {'type':'username',
                                         'value':'student1'}
                                    }]))
    elif test == '3':
    # Get a warning because cohort specified do not exist
        show(t.add_cohort_members([{'cohorttype':
                                        {'type':'id',
                                         'value':'1100'},
                                    'usertype':
                                        {'type':'id',
                                         'value':'3'}
                                    }]))
예제 #16
0
def test_update_notes(test):
    if test == '0':
        # Update a note manually
        print "Required parameters: note id, publishstate('personal', 'course' or 'site') and text"
        show(t.update_notes([{'id': raw_input(),
                              'publishstate': raw_input(),
                              'text': raw_input()}]))
    elif test == '1':
        # Update a personal note
        show(t.update_notes([{'id': 1,
                              'publishstate': 'personal',
                              'text': 'Python note changed'}]))
    elif test == '2':
        # Update a personal note to a course
        show(t.update_notes([{'id': 1,
                              'publishstate': 'course',
                              'text': 'Python note changed to a course note'}]))
예제 #17
0
def test_assign_roles(test):
    if test == '0':
        # Assign a role to a user manually
        print "Required parameters: roleid, userid and contextid"
        show(t.assign_roles([{'roleid': raw_input(),
                              'userid': raw_input(),
                              'contextid': raw_input()}]))
    elif test == '1':
        # Assign a role to a user
        show(t.assign_roles([{'roleid': '2',
                              'userid':'4' ,
                              'contextid': '2'}]))
    # Errors
    elif test == '2':
        # Assign a role to a user in a invalid context
        show(t.assign_roles([{'roleid': '6',    # guest role id
                              'userid':'4' ,    # Any user id
                              'contextid': '1'}]))  # System context
예제 #18
0
def test_create_users(test):
    if test == '1':
        # Create a test user
        show(t.create_users([{'username':'******',
                           'password':'******',
                           'firstname':'Python',
                           'lastname':'Test Student',
                           'email':'*****@*****.**'}]))
    #Errors
    elif test =='2':
        # Try to create a user with an invalid pasword
        show(t.create_users([{'username':'******',
                           'password':'******',
                           'firstname':'Python',
                           'lastname':'Test Student',
                           'email':'*****@*****.**'}]))
    elif test =='3':
        # Try to create a user with an invalid email
        show(t.create_users([{'username':'******',
                           'password':'******',
                           'firstname':'Python',
                           'lastname':'Test Student',
                           'email':'pythontest@t'}]))
예제 #19
0
def test_delete_calendar_events(test):
    if test == '0':
    # Manually delete 1 event
        print 'Event ID to delete:'
        show(t.delete_calendar_events([{'eventid':raw_input(),
                                        'repeat':0}]))
    elif test == '1':
    # Manually delete 1 event series
        print 'Event ID to delete with series(repeated event):'
        show(t.delete_calendar_events([{'eventid':raw_input(),
                                        'repeat':1}]))
    # Errors:
    #  try to delete a global event with student user
    elif test == '2':
        show(t.delete_calendar_events([1]))
    elif test == '3':
        show(t.delete_calendar_events([{'eventid':1}]))
    elif test == '4':
        show(t.delete_calendar_events([{'eventid':1,
                                        'repeat':2}]))
    elif test == '5':
        show(t.delete_calendar_events([{'eventid':-1,
                                        'repeat':0}]))
예제 #20
0
def test_get_notes():
    # Get a note manually
    print "Required parameters: note id"
    show(t.get_notes([raw_input()]))
예제 #21
0
def test_delete_notes():
    # Delete a note manually
    print "Required parameters: note id"
    show(t.delete_notes([raw_input()]))
예제 #22
0
def test_upload_file():
    # Manually upload the specified file to the main private area folder
    print 'Parameter: file path to upload'
    show(t.upload_file(raw_input(),'1/Testfiles/'))
예제 #23
0
def test_search_contacts(test):
    if test == '0':
    # Search contacts manually
        print 'Required parameters: Search string'
        show(t.search_contacts(raw_input()))
예제 #24
0
def test_get_contacts():
    show(t.get_contacts())
예제 #25
0
def test_delete_contacts(test):
    if test == '0':
    # Delete a contact from your contacts list manually
        print 'Required parameters: User ID'
        show(t.delete_contacts([raw_input()]))
예제 #26
0
def test_get_calendar_events(test):
    if test == '0':
    # Manually show 1 event
        print 'Event ID to search:'
        show(t.get_calendar_events([raw_input()],userevents=0,siteevents=0))
    elif test == '1':
    # Manually show events from 1 course
        print 'Course ID to search events:'
        show(t.get_calendar_events(courseids=[raw_input()],userevents=0,siteevents=0))
    elif test == '2':
    # Manually show events from 1 group
        print 'Group ID to search events:'
        show(t.get_calendar_events(groupids=[raw_input()],userevents=0,siteevents=0))
    elif test == '3':
    # Get user events (only those created with MoodLib)
        show(t.get_calendar_events(siteevents=0))
    elif test == '4':
    # Get global site events (only those created with MoodLib)
        show(t.get_calendar_events(userevents=0))
    elif test == '5':
    # Get user and global events in a time range even if are hidden
        timestr = t.get_calendar_events()['events'][0]['timestart']
        timend = int(t.get_calendar_events()['events'][0]['timestart'])+10000
        show(t.get_calendar_events(timestart=timestr,timeend=timend, ignorehidden=0))
    # Errors
    elif test == '6':
        show(t.get_calendar_events(['a']))
    elif test == '7':
        show(t.get_calendar_events(courseids=['a']))
    elif test == '8':
        show(t.get_calendar_events(groupids=['a']))
    elif test == '9':
        show(t.get_calendar_events(timestart='a'))
    elif test == '10':
        show(t.get_calendar_events(timeend='a'))
예제 #27
0
def test_create_calendar_events(test):
    if test == '0':
    #  Create 1 event manually for the user
        print 'Event name to create:'
        show(t.create_calendar_events([{'name':raw_input()}]))
    elif test == '1':
    # Create 1 event with all parameters for a course
        show(t.create_calendar_events([{'name':'Python advanced event',
                                        'description':'Event created with Moodle python library',
                                        'format':'0',
                                        'courseid':'2',
                                        'groupid':'0',
                                        'repeats':'3',
                                        'eventtype':'course',
                                        'timestart':int(time.time()),
                                        'timeduration':'240',
                                        'visible':'1',
                                        'sequence':'1'}]))
    elif test == '2':
    # Create 1 event with all parameters for the entire site (courseid=1)
        show(t.create_calendar_events([{'name':'Python event: closing site',
                                        'description':'This moodle site will be close for maintenance operations',
                                        'courseid':'1',
                                        'repeats':'2',
                                        'eventtype':'site',
                                        'timeduration':60*60*24,
                                        'visible':'1'}]))
    # Warnings: execute test 2 or 3 with student user
    # Errors
    elif test == '3':
        show(t.create_calendar_events({'name':'Python advanced'}))
    elif test == '4':
        show(t.create_calendar_events([{'name':'Python event: error',
                                        'repeats':'a'}]))
    elif test == '5':
        show(t.create_calendar_events([{'name':'Python event: error',
                                        'timestart':'a'}]))
    elif test == '6':
        show(t.create_calendar_events([{'name':'Python event: error',
                                        'timeduration':'a'}]))
    elif test == '7':
        show(t.create_calendar_events([{'name':'Python event: error',
                                        'visible':'a'}]))
예제 #28
0
def test_send_instant_messages(test):
    if test == '0':
    # Send a message to a user manually
        print 'Required parameters: User ID, text message'
        show(t.send_instant_messages([{'touserid':raw_input(),
                                       'text':raw_input()}]))
예제 #29
0
def test_create_contacts(test):
    if test == '0':
    # Add a contact to your contacts list manually
        print 'Required parameters: User ID'
        show(t.create_contacts([raw_input()]))
예제 #30
0
def test_block_contacts(test):
    if test == '0':
    # Block a contact manually
        print 'Required parameters: User ID'
        show(t.block_contacts([raw_input()]))