예제 #1
0
def test(s):
    print '** Input : %s'%s
    module = ModuleURI(s)
    print '- Full URI :: %s'% str(module)
    print '- Relative URI :: %s'% module.get_relative_uri()
    print '- Top level URI :: %s'% module.get_top_level_uri()
    print '- Module ID :: %s' % module.module_id
    print '- Name :: %s' % module.get_name()
    print '- Category :: %s' % module.category
    print '- Rescued answer :: %s '% module.rescued_answer
    print '- Action :: %s' % module.action
 def test_get_resource_display_name(self):
     '''Simple coverage test to check the get_resource_name method works under
     the following scenarios:
     - No resource_display_name field set but module (ModuleURI) is set
     - resource_display_name field set and module (ModuleURI) is set
     '''
     event = events.Event({})
     event.set_data_attr(
         'module',
         ModuleURI(
             '/courses/MITx/2.111x/2010_Spring/modx/i4x://MITx/2.111x/problem/a/problem_get'
         ))
     self.assertEqual('a', event.get_resource_display_name())
     event.set_data_attr('resource_display_name', 'display_name')
     self.assertEqual('display_name', event.get_resource_display_name())
 def test_get_uri(self):
     '''Simple coverage test to check that the overridden get_uri method
     works when the page, module (ModuleURI), and video_code fields
     are set approprirately.
     '''
     event = events.VideoInteraction({
         'page':
         'https://edx.org/',
         'module':
         ModuleURI(
             '/courses/MITx/3.111x/2009_Spring/modx/i4x://MITx/3.111x/video/What_is_MATLAB/'
         ),
         'video_code':
         'OEoXabPEzfa'
     })
     self.assertEqual('https://edx.org/video/What_is_MATLAB/_OEoXabPEzfa',
                      event.get_uri())
    def test_get_uri(self):
        '''Simple coverage test to check the get_uri method works under the
        following scenarios:
        - No page field set and no module (ModuleURI) field set.
        - page field set but no module (ModuleURI) field set.
        - No page field set but module (ModuleURI) field set.
        - page field set and module (ModuleURI) field set.
        '''
        event = events.Event({})
        self.assertEqual('https://unknown/', event.get_uri())
        event.set_data_attr('page', 'https://edx.org/')
        self.assertEqual('https://edx.org/', event.get_uri())

        event = events.Event({})
        event.set_data_attr(
            'module',
            ModuleURI(
                '/courses/MITx/1.111x/2010_Spring/modx/i4x://MITx/1.111x/problem/a/problem_get'
            ))
        self.assertEqual('https://unknown/problem/a/', event.get_uri())
        event.set_data_attr('page', 'https://edx.org/')
        self.assertEqual('https://edx.org/problem/a/', event.get_uri())
 def test_show_transcript_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the show_transcript event.
     '''
     event = VideoInteraction({
         '_id':
             'f',
         'anon_screen_name':
             'show_anonymous',
         'course_display_name':
             'course-v1:HKUSTx+EBA101x+3T2016',
         'module':
             ModuleURI(''),
         'time':
             '2013-11-06 18:45:25',
         'event_type':
             'show_transcript',
         'page':
             CourseURL('https://www.edx.org/courses/0/show/transcript'),
         'video_code':
             'fghi6789',
         'video_current_time':
             '',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'b3f8a32d52374496afc421e07e0aaf89',
         'transcript_id':
             'b3f8a32d52374496afc421e07e0aaf89'
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_pause_video_MITx_csv_output(self):
     '''Tests click_events.csv output for the pause_video event.
     '''
     event = VideoInteraction({
         '_id':
             'c',
         'anon_screen_name':
             'pause_anonymous',
         'course_display_name':
             'org/course/run',
         'module':
             ModuleURI('i4x://play/video/uri'),
         'time':
             '2013-08-11 11:03:47',
         'event_type':
             'pause_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/pause/video'),
         'video_code':
             'cdef3456',
         'video_current_time':
             '21.055',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             '',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'MITx')
 def test_video_show_cc_menu_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the video_show_cc_menu event.
     '''
     event = VideoInteraction({
         '_id':
             'f',
         'anon_screen_name':
             'show_anonymous',
         'course_display_name':
             'course-v1:HKUSTx+EBA101x+3T2016',
         'module':
             ModuleURI(''),
         'time':
             '2013-11-06 18:45:25',
         'event_type':
             'video_show_cc_menu',
         'page':
             CourseURL('https://www.edx.org/courses/0/show/transcript'),
         'video_code':
             'fghi6789',
         'video_current_time':
             '',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'c636c61da1bd4951a1e76c9fb2ae4e96',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_speed_change_video_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the speed_change_video event.
     '''
     event = VideoInteraction({
         '_id':
             'g',
         'anon_screen_name':
             'speed_anonymous',
         'course_display_name':
             'course-v1:HKUSTx+EBA101x+3T2016',
         'module':
             ModuleURI(''),
         'time':
             '2013-11-06 18:45:25',
         'event_type':
             'speed_change_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/speed/change/video'),
         'video_code':
             'ghij7890',
         'video_current_time':
             '',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '2',
         'video_old_speed':
             '1',
         'video_id':
             '09e004c72f114843a7d50d32b723a741',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_hide_transcript_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the hide_transcript event.
     '''
     event = VideoInteraction({
         '_id':
             'e',
         'anon_screen_name':
             'hide_anonymous',
         'course_display_name':
             'course-v1:HKUSTx+EBA101x+3T2016',
         'module':
             ModuleURI(''),
         'time':
             '2014-06-09 01:16:48',
         'event_type':
             'hide_transcript',
         'page':
             CourseURL('https://www.edx.org/courses/0/hide/transcript'),
         'video_code':
             'efgh5678',
         'video_current_time':
             '',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'ff00eb135e2d44fbb3d545fe12cd157e',
         'transcript_id':
             'ff00eb135e2d44fbb3d545fe12cd157e'
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_seek_video_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the seek_video event.
     '''
     event = VideoInteraction({
         '_id':
             'h',
         'anon_screen_name':
             'seek_anonymous',
         'course_display_name':
             'course-v1:HKUSTx+EBA101x+3T2016',
         'module':
             ModuleURI(''),
         'time':
             '2013-12-02 18:44:40',
         'event_type':
             'seek_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/seek/video'),
         'video_code':
             'hijk8901',
         'video_current_time':
             '',
         'video_new_time':
             '330',
         'video_old_time':
             '293.24',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'i4x-HKUSTx-COMP102x-video-b3f8a32d52374496afc421e07e0aaf89',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_stop_video_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the stop_video event.
     '''
     event = VideoInteraction({
         '_id':
             'd',
         'anon_screen_name':
             'stop_anonymous',
         'course_display_name':
             'org/course/run',
         'module':
             ModuleURI(''),
         'time':
             '2013-06-13 07:03:04',
         'event_type':
             'stop_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/stop/video'),
         'video_code':
             'defg4567',
         'video_current_time':
             '133.812',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'i4x-HKUSTx-COMP102x-video-d86629a449b04f60bc822939efc0e832',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_load_video_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the load_video event.
     '''
     event = VideoInteraction({
         '_id':
             'b',
         'anon_screen_name':
             'load_anonymous',
         'course_display_name':
             'org/course/run',
         'module':
             ModuleURI(''),
         'time':
             '2013-08-13 19:03:04',
         'event_type':
             'load_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/load/video'),
         'video_code':
             'bcde2345',
         'video_current_time':
             '',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'i4x-HKUSTx-COMP102x-video-2680e14cba5e43f488d9c9fc73e25cb9',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
 def test_play_video_HKUSTx_csv_output(self):
     '''Tests click_events.csv output for the play_video event.
     '''
     event = VideoInteraction({
         '_id':
             'a',
         'anon_screen_name':
             'play_anonymous',
         'course_display_name':
             'org/course/run',
         'module':
             ModuleURI(''),
         'time':
             '2013-08-13 19:47:47.451372',
         'event_type':
             'play_video',
         'page':
             CourseURL('https://www.edx.org/courses/0/play/video'),
         'video_code':
             'abcd1234',
         'video_current_time':
             '0',
         'video_new_time':
             '',
         'video_old_time':
             '',
         'video_new_speed':
             '',
         'video_old_speed':
             '',
         'video_id':
             'i4x-HKUSTx-COMP102x-video-a6a52021a087402fafa1bb717406b326',
         'transcript_id':
             ''
     })
     self.check_equal_click_event(event, 'HKUSTx')
    def check_equal_click_event(self, event, specification):
        '''This is only used as a helper function within actual tests
        to assert event equivalence with a click event from a click_events.csv file.
        '''
        moocdb = MOOCdb(tempfile.gettempdir())
        click_events_manager = ClickEventsManager(moocdb)
        click_events_manager.record(event, {'video_id_spec': specification})
        moocdb.close()

        with open(os.path.join(tempfile.gettempdir(), 'click_events.csv'),
                  'r') as click_events_file:
            lines = click_events_file.read().splitlines()
            self.assertEqual(1, len(lines))
            for line in lines:
                self.assertEqual(
                    line.count(','), 12,
                    "Mismatched number of fields in line: %s" % line)
                (observed_event_id, course_id, user_id, video_id,
                 observed_event_timestamp, observed_event_type, url, code,
                 video_current_time, video_new_time, video_old_time,
                 video_new_speed, video_old_speed) = line.split(',')
                event_from_file = VideoInteraction({
                    '_id':
                        observed_event_id,
                    'anon_screen_name':
                        user_id,
                    'course_display_name':
                        course_id,
                    'module':
                        ModuleURI(video_id) if specification == 'MITx' else ModuleURI(''),
                    'time':
                        observed_event_timestamp,
                    'event_type':
                        observed_event_type,
                    'page':
                        CourseURL(url),
                    'video_code':
                        code,
                    'video_current_time':
                        video_current_time,
                    'video_new_time':
                        video_new_time,
                    'video_old_time':
                        video_old_time,
                    'video_new_speed':
                        video_new_speed,
                    'video_old_speed':
                        video_old_speed,
                    'video_id':
                        video_id if specification == 'HKUSTx'
                        else '',
                    'transcript_id':
                        video_id if specification == 'HKUSTx'
                                    and (observed_event_type == 'hide_transcript'
                                         or observed_event_type == 'show_transcript')
                        else ''
                })
                self.assertEqual(event, event_from_file)

        for name in moocdb.TABLES:
            os.remove(os.path.join(tempfile.gettempdir(), '%s.csv' % name))
예제 #15
0
sys.path.insert(0, os.path.join(os.getcwd(), os.path.pardir))
from events import Event
from helperclasses import CurationHelper, ModuleURI, CourseURL

url1 = CourseURL(
    'https://courses.edx.org/courses/MITx/6.002x/2013_Spring/courseware/Week_10/Homework_10/1'
)
url2 = CourseURL(
    'https://courses.edx.org/courses/MITx/6.002x/2013_Spring/courseware/Week_10/Homework_10/2'
)
url3 = CourseURL(
    'https://courses.edx.org/courses/MITx/6.002x/2013_Spring/courseware/Week_13/Op_Amps_Positive_Feedback/10'
)

module1 = ModuleURI(
    'input_i4x-MITx-6_002x-problem-H12P3_Opamps_and_Filter_Design_10_1')
module2 = ModuleURI(
    'input_i4x-MITx-6_002x-problem-H12P3_Opamps_and_Filter_Design')
module3 = ModuleURI('i4x://MITx/6.002x/problem/Q2Final2012')

inputs = [(module1, Event({
    'url_id': 1,
    'page': url1,
    'resource_id': 1
})), (module2, Event({
    'url_id': 2,
    'page': url2,
    'resource_id': 2
})), (module2, Event({
    'url_id': 1,
    'page': url1,