'Test backwards compatibility of previous app builds
iOS version 1.0.02: Incorrectly emits the skip back 30 seconds as +30
instead of -30.
Android version 1.0.02: Skip and slide were both being returned as a
skip. Skip or slide is determined by checking if the skip time is == -30
Additionally, for both of the above mentioned versions, edx.video.seeked
was sent instead of edx.video.position.changed'

@data((1, 1, 'seek_type', 'slide', 'onSlideSeek', 'edx.video.seeked', 'edx.video.position.changed', 'edx.mobileapp.iOS', '1.0.02'), ((-2), (-2), 'seek_type', 'slide', 'onSlideSeek', 'edx.video.seeked', 'edx.video.position.changed', 'edx.mobileapp.iOS', '1.0.02'), (30, (-30), 'seek_type', 'skip', 'onSkipSeek', 'edx.video.position.changed', 'edx.video.position.changed', 'edx.mobileapp.iOS', '1.0.02'), ((-30), (-30), 'seek_type', 'skip', 'onSkipSeek', 'edx.video.position.changed', 'edx.video.position.changed', 'edx.mobileapp.iOS', '1.0.02'), (1, 1, 'type', 'onSkipSeek', 'onSlideSeek', 'edx.video.seeked', 'edx.video.position.changed', 'edx.mobileapp.android', '1.0.02'), ((-2), (-2), 'type', 'onSkipSeek', 'onSlideSeek', 'edx.video.seeked', 'edx.video.position.changed', 'edx.mobileapp.android', '1.0.02'), (30, 30, 'type', 'onSkipSeek', 'onSkipSeek', 'edx.video.position.changed', 'edx.video.position.changed', 'edx.mobileapp.android', '1.0.02'), ((-30), (-30), 'type', 'onSkipSeek', 'onSkipSeek', 'edx.video.position.changed', 'edx.video.position.changed', 'edx.mobileapp.android', '1.0.02'))
@unpack
def test_previous_builds(self, requested_skip_interval, expected_skip_interval, seek_type_key, seek_type, expected_seek_type, name, expected_name, platform, version):

    course_id = 'foo/bar/baz'
    middleware = TrackMiddleware()
    input_payload = {'code': 'mobile', 'new_time': 89.699177437, 'old_time': 119.699177437, seek_type_key: seek_type, 'requested_skip_interval': requested_skip_interval, 'module_id': 'i4x://foo/bar/baz/some_module'}
    request = self.create_request(data=self.create_segmentio_event_json(name=name, data=input_payload, context={'open_in_browser_url': 'https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2', 'course_id': course_id, 'application': {'name': platform, 'version': version, 'component': 'videoplayer'}}), content_type='application/json')
    User.objects.create(pk=SEGMENTIO_TEST_USER_ID, username=str(sentinel.username))
    middleware.process_request(request)
    try:
        response = segmentio.segmentio_event(request)
        self.assertEquals(response.status_code, 200)
        expected_event = {'accept_language': '', 'referer': '', 'username': str(sentinel.username), 'ip': '', 'session': '', 'event_source': 'mobile', 'event_type': 'seek_video', 'name': expected_name, 'agent': str(sentinel.user_agent), 'page': 'https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity', 'time': datetime.strptime('2014-08-27T16:33:39.215Z', '%Y-%m-%dT%H:%M:%S.%fZ'), 'host': 'testserver', 'context': {'user_id': SEGMENTIO_TEST_USER_ID, 'course_id': course_id, 'org_id': 'foo', 'path': SEGMENTIO_TEST_ENDPOINT, 'client': {'library': {'name': 'test-app', 'version': 'unknown'}, 'app': {'version': '1.0.1'}}, 'application': {'name': platform, 'version': version, 'component': 'videoplayer'}, 'received_at': datetime.strptime('2014-08-27T16:33:39.100Z', '%Y-%m-%dT%H:%M:%S.%fZ')}, 'event': {'code': 'mobile', 'new_time': 89.699177437, 'old_time': 119.699177437, 'type': expected_seek_type, 'requested_skip_interval': expected_skip_interval, 'id': 'i4x-foo-bar-baz-some_module'}}
    finally:
        middleware.process_response(request, None)
    actual_event = self.get_event()
    assert_event_matches(expected_event, actual_event)
