def test_inherit_seqnum(self):
     '''Test the inherit_seqnum function with an event
     that should inherit a sequence number.
     '''
     event = {
         'current_location': (CourseURL(
             'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/3/'
         ), '2013-11-10 06:43:41'),
         'page':
         CourseURL(
             'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/'
         )
     }
     expected_event = {
         'current_location': (CourseURL(
             'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/3/'
         ), '2013-11-10 06:43:41'),
         'page':
         CourseURL(
             'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/'
         ),
         'inherited':
         'seqnum'
     }
     expected_event['page'].set_seq(3)
     inherit_seqnum(event)
     self.assertEqual(expected_event, event)
    def test_close_previous_page(self):
        '''Simple coverage test for the close_previous_page function.
        '''

        event_page_equal_current_location = {
            'page':
            CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/87510/'
            ),
            'event_type':
            'page_close',
            'current_location': (CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/87510/'
            ), '')
        }
        self.assertEqual(
            None, close_previous_page(event_page_equal_current_location))

        event_page_notequal_current_location = {
            'page':
            CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/87510/3/2/'
            ),
            'event_type':
            'page_close',
            'current_location': (CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/87510/'
            ), '')
        }
        self.assertEqual(
            CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/87510/'
            ), close_previous_page(event_page_notequal_current_location))
    def test_no_url_yes_inheritance(self):
        '''Test the no_url function with an event that
        should inherit a url.
        '''
        event = {
            'current_location': (CourseURL(
                'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/3/'
            ), '2013-11-10 06:43:41'),
            'time':
            '2013-12-10 06:44:00',
            'page':
            ''
        }
        expected_event = {
            'current_location': (CourseURL(
                'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/3/'
            ), '2013-11-10 06:43:41'),
            'time':
            '2013-12-10 06:44:00',
            'page':
            CourseURL(
                'https://edx.edu/courses/Medicine/SciWrite/run/courseware/c340d5/ff5b3/3/'
            ),
            'inherited':
            'url'
        }

        no_url(event)
        self.assertEqual(expected_event, event)
    def test_simple_update(self):
        '''Simple coverage test for the simple_update function.
        '''
        event = {
            'page':
            CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/00000/87510/'
            )
        }

        self.assertEqual(
            CourseURL(
                'https://edx.org/courses/Medicine/SciWrite/run/courseware/00000/87510/'
            ), simple_update(event))
 def test_update_seq(self):
     '''Simple coverage test for the update_seqnum function.
     '''
     event = {
         'page':
         CourseURL(
             'https://edx.org/courses/Medicine/SciWrite/run/courseware/00000/87510/'
         ),
         'event_type':
         'seq_goto',
         'goto_dest':
         '3',
     }
     self.assertEqual(
         CourseURL(
             'https://edx.org/courses/Medicine/SciWrite/run/courseware/00000/87510/3/'
         ), update_seq(event))
 def test_get_page(self):
     '''Simple coverage test to check the get_page method works
     when the page (CourseURL) field and goto_dest field are set'''
     event = events.PdfInteraction({
         'page':
         CourseURL('https://edx.org/book/2/3'),
         'goto_dest':
         2
     })
     self.assertEqual('2', event.get_page())
    def test_no_url_no_inheritance(self):
        '''Test the no_url function with an event that
        should not inherit a url.
        '''
        event = {
            'current_location':
            (CourseURL('http://a/b/'), '2013-11-10 06:43:41'),
            'time': '2013-12-10 06:44:00',
            'page': ''
        }
        expected_event = {
            'current_location':
            (CourseURL('http://a/b/'), '2013-11-10 06:43:41'),
            'time': '2013-12-10 06:44:00',
            'page': '',
            'inherited': ''
        }

        no_url(event)
        self.assertEqual(expected_event, event)
 def test_get_uri(self):
     '''Simple coverage test for the get_uri method.
     Relative pathing should not be appended for these events.
     '''
     raw_event = {
         'sequence_id': 'a',
         'goto_dest': 2,
         'goto_from': 3,
         'page': CourseURL('https://edx.org/')
     }
     event = events.Navigational(raw_event)
     self.assertEqual('https://edx.org/', event.get_uri())
 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_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_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_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_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 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')
Ejemplo n.º 18
0
def test_urls(urls):
    for s in urls:
        print '** Input : %s' % s
        test(CourseURL(s))
Ejemplo n.º 19
0
def test_bad_urls(BadURLs):
    print '* Testing bad URLs'
    for s in BadURLs:
        print '\n'
        print s
        print CourseURL(s)
Ejemplo n.º 20
0
import sys
import os

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
    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))