Exemple #1
0
    def test_live_statistics_install(self):
        request = parse_request(fixtures.request_event_install_success)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version_1 = '0.0.0.1'
        version_2 = '0.0.0.2'

        events_appid_version = lambda version: HourEvents(
            'request:{}:{}'.format(appid, version), now.year, now.month, now.
            day, now.hour)
        events_appid_platform_version = lambda version: HourEvents(
            'request:{}:{}:{}'.format(appid, platform, version), now.year, now.
            month, now.day, now.hour)
        events_appid_platform_channel_version = lambda version: HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version),
            now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         0)
        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         1)

        request = parse_request(fixtures.request_event_update_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         0)
        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)),
                         1)

        request = parse_request(fixtures.request_event_uninstall_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)),
                         1)
Exemple #2
0
    def test_update_live_statistics_install(self):
        request = parse_request(fixtures.request_event_install_success)
        apps = request.findall('app')
        app = apps[0]

        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version_1 = '0.0.0.1'
        version_2 = '0.0.0.2'

        events_appid_version_1 = HourEvents('online:{}:{}'.format(appid, version_1), now.year, now.month, now.day, now.hour)
        events_appid_platform_version_1 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_1), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version_1), 0)
        self.assertEqual(len(events_appid_platform_version_1), 0)

        update_live_statistics(userid, apps, platform)

        self.assertEqual(len(events_appid_version_1), 1)
        self.assertEqual(len(events_appid_platform_version_1), 1)

        request = parse_request(fixtures.request_event_update_success)
        apps = request.findall('app')

        update_live_statistics(userid, apps, platform)

        events_appid_version_1 = HourEvents('online:{}:{}'.format(appid, version_1), now.year, now.month, now.day, now.hour)
        events_appid_platform_version_1 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_1), now.year, now.month, now.day, now.hour)
        events_appid_version_2 = HourEvents('online:{}:{}'.format(appid, version_2), now.year, now.month, now.day, now.hour)
        events_appid_platform_version_2 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_2), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version_1), 0)
        self.assertEqual(len(events_appid_platform_version_1), 0)
        self.assertEqual(len(events_appid_version_2), 1)
        self.assertEqual(len(events_appid_platform_version_2), 1)

        request = parse_request(fixtures.request_event_uninstall_success)
        apps = request.findall('app')

        update_live_statistics(userid, apps, platform)

        events_appid_version_2 = HourEvents('online:{}:{}'.format(appid, version_2),
                                            now.year, now.month, now.day, now.hour)
        events_appid_platform_version_2 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_2),
                                                     now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version_2), 1)
        self.assertEqual(len(events_appid_platform_version_2), 1)
    def test_live_statistics_updatecheck(self):
        request = parse_request(fixtures.request_update_check)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version = app.get('version')

        events_appid_version = HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = HourEvents('request:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_channel_version = HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)
        self.assertEqual(len(events_appid_platform_channel_version), 0)

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)
        self.assertEqual(len(events_appid_platform_channel_version), 1)
Exemple #4
0
    def test_live_statistics_updatecheck(self):
        request = parse_request(fixtures.request_update_check)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version = app.get('version')

        events_appid_version = HourEvents(
            'request:{}:{}'.format(appid, version), now.year, now.month,
            now.day, now.hour)
        events_appid_platform_version = HourEvents(
            'request:{}:{}:{}'.format(appid, platform, version), now.year,
            now.month, now.day, now.hour)
        events_appid_platform_channel_version = HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version),
            now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)
        self.assertEqual(len(events_appid_platform_channel_version), 0)

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)
        self.assertEqual(len(events_appid_platform_channel_version), 1)
Exemple #5
0
def generate_events(app_id, **options):
    versions = Version.objects.filter_by_enabled(app__id=app_id)

    userid_list = list([get_random_uuid() for x in range(1, 25)])
    sessionid_list = list([get_random_uuid() for x in range(1, 50)])

    for i in range(1, options['count'] + 1):
        if i % 10 == 0:
            print('=> ', i)

        version = random.choice(versions)
        request = request_tml.format(
            sessionid=random.choice(sessionid_list),
            requestid=get_random_uuid(),
            userid=random.choice(userid_list),
            os_version=random.choice(os_version_list),
            os_sp=random.choice(os_sp_list),
            os_arch=random.choice(os_arch_list),
            app_id=app_id,
            version='',
            nextversion=str(version.version),
            events=random.choice(event_list)
        )

        request = bytes(request, 'utf8')

        request_obj = parse_request(request)

        with freeze_time(get_random_date()):
            collect_statistics(request_obj, ip='8.8.8.8')
    def test_add_app_live_statistics(self):
        request = parse_request(fixtures.request_update_check)
        app = request.findall("app")[0]

        now = datetime.utcnow()
        userid = 1
        platform = "win"

        appid = app.get("appid")
        version = app.get("version")

        events_appid_version = HourEvents("online:{}:{}".format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = HourEvents(
            "online:{}:{}:{}".format(appid, platform, version), now.year, now.month, now.day, now.hour
        )

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)

        add_app_live_statistics(userid, platform, app)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)

        self.assertIn(userid, events_appid_version)
        self.assertIn(userid, events_appid_platform_version)
def generate_events(app_id, **options):
    versions = Version.objects.filter_by_enabled(app__id=app_id)

    userid_list = list(map(lambda x: get_random_uuid(), range(1, 25)))
    sessionid_list = list(map(lambda x: get_random_uuid(), range(1, 50)))

    for i in range(1, options['count'] + 1):
        if i % 10 == 0:
            print('=> ', i)

        version = random.choice(versions)
        request = request_tml.format(
            sessionid=random.choice(sessionid_list),
            requestid=get_random_uuid(),
            userid=random.choice(userid_list),
            os_version=random.choice(os_version_list),
            os_sp=random.choice(os_sp_list),
            os_arch=random.choice(os_arch_list),
            app_id=app_id,
            version=str(version.version),
            nextversion='',
            events=random.choice(event_list)
        )

        request = bytes(request, 'utf8')

        request_obj = parse_request(request)

        with freeze_time(get_random_date()):
            collect_statistics(request_obj, ip='8.8.8.8')
 def test_parse_os(self):
     request = parse_request(fixtures.request_event)
     os = parse_os(request.os)
     self.assertIsInstance(os, Os)
     self.assertEqual(os.platform, 'win')
     self.assertEqual(os.version, '6.1')
     self.assertEqual(os.sp, '')
     self.assertEqual(os.arch, 'x64')
 def generate_fake_hour():
     for version in versions:
         for i in range(random.randint(0, 20)):
             id = uuid.UUID(int=i)
             request = event_install % (id, app_id, version)
             request = bytes(request, 'utf8')
             request = parse_request(request)
             collect_statistics(request)
 def test_parse_os(self):
     request = parse_request(fixtures.request_event)
     os = parse_os(request.os)
     self.assertIsInstance(os, Os)
     self.assertEqual(os.platform, "win")
     self.assertEqual(os.version, "6.1")
     self.assertEqual(os.sp, "")
     self.assertEqual(os.arch, "x64")
Exemple #11
0
 def test_parse_os(self):
     request = parse_request(fixtures.request_event)
     os = parse_os(request.os)
     self.assertIsInstance(os, Os)
     self.assertEqual(os.platform, 'win')
     self.assertEqual(os.version, '6.1')
     self.assertEqual(os.sp, '')
     self.assertEqual(os.arch, 'x64')
 def generate_fake_hour():
     for version in versions:
         for i in range(random.randint(0, 20)):
             id = uuid.UUID(int=i)
             request = event_updatecheck % (id, app_id, version)
             request = bytes(request, 'utf8')
             request = parse_request(request)
             collect_statistics(request)
    def test_live_statistics_install(self):
        request = parse_request(fixtures.request_event_install_success)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version_1 = '0.0.0.1'
        version_2 = '0.0.0.2'
        events_appid_version = lambda version: HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = lambda version: HourEvents('request:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_channel_version = lambda version: HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 0)
        userid_counting(userid, apps, platform)
        self.assertEqual(len(events_appid_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 1)

        request = parse_request(fixtures.request_event_update_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 0)
        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)), 1)

        request = parse_request(fixtures.request_event_uninstall_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)), 1)
Exemple #14
0
def build_response(request, pretty_print=True):
    obj = parse_request(request)
    tasks.collect_statistics.apply_async(args=(request,), queue='transient')
    userid = obj.get('userid')
    apps = obj.findall('app')
    apps_list = reduce(partial(on_app, os=obj.os, userid=userid), apps, [])
    response = Response(apps_list, date=now())
    return etree.tostring(response, pretty_print=pretty_print,
                          xml_declaration=True, encoding='UTF-8')
Exemple #15
0
 def test_parse_request(self):
     request = parse_request(fixtures.request_event)
     req = parse_req(request)
     self.assertIsInstance(req, Request)
     self.assertEqual(req.version, Request._meta.get_field_by_name('version')[0].to_python('1.3.23.0'))
     self.assertEqual(req.ismachine, 1)
     self.assertEqual(req.sessionid, '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
     self.assertEqual(req.userid, '{F25EC606-5FC2-449b-91FF-FA21CADB46E4}')
     self.assertEqual(req.originurl, None)
     self.assertEqual(req.testsource, 'ossdev')
     self.assertEqual(req.updaterchannel, None)
 def test_parse_request(self):
     request = parse_request(fixtures.request_event)
     req = parse_req(request)
     self.assertIsInstance(req, Request)
     self.assertEqual(req.version, Request._meta.get_field_by_name("version")[0].to_python("1.3.23.0"))
     self.assertEqual(req.ismachine, 1)
     self.assertEqual(req.sessionid, "{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}")
     self.assertEqual(req.userid, "{D0BBD725-742D-44ae-8D46-0231E881D58E}")
     self.assertEqual(req.originurl, None)
     self.assertEqual(req.testsource, "ossdev")
     self.assertEqual(req.updaterchannel, None)
 def test_parse_request(self):
     request = parse_request(fixtures.request_event)
     req = parse_req(request)
     self.assertIsInstance(req, Request)
     self.assertEqual(req.version, Request._meta.get_field_by_name('version')[0].to_python('1.3.23.0'))
     self.assertEqual(req.ismachine, 1)
     self.assertEqual(req.sessionid, '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
     self.assertEqual(req.userid, '{D0BBD725-742D-44ae-8D46-0231E881D58E}')
     self.assertEqual(req.originurl, None)
     self.assertEqual(req.testsource, 'ossdev')
     self.assertEqual(req.updaterchannel, None)
 def test_parse_request(self):
     request = parse_request(fixtures.request_event)
     req = parse_req(request)
     self.assertIsInstance(req, Request)
     self.assertEqual(req.version, Request._meta.get_field_by_name('version')[0].to_python('1.3.23.0'))
     self.assertEqual(req.ismachine, 1)
     self.assertEqual(req.sessionid, '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
     self.assertEqual(req.userid, '{F25EC606-5FC2-449b-91FF-FA21CADB46E4}')
     self.assertEqual(req.originurl, None)
     self.assertEqual(req.testsource, 'ossdev')
     self.assertEqual(req.updaterchannel, None)
Exemple #19
0
def build_response(request, pretty_print=True, ip=None):
    obj = parse_request(request)
    tasks.collect_statistics.apply_async(args=(request, ip), queue='transient')
    userid = obj.get('userid')
    apps = obj.findall('app')
    apps_list = reduce(partial(on_app, os=obj.os, userid=userid), apps, [])
    response = Response(apps_list, date=now())
    return etree.tostring(response,
                          pretty_print=pretty_print,
                          xml_declaration=True,
                          encoding='UTF-8')
Exemple #20
0
    def test_parse_apps(self):
        request = parse_request(fixtures.request_event)
        req = parse_req(request)
        req.os = parse_os(request.os)
        req.hw = parse_hw(request.hw) if request.get('hw') else None
        req.save()

        apps = parse_apps(request.findall('app'), req)
        self.assertEqual(len(apps), 1)
        app = apps[0]
        self.assertIsInstance(app, AppRequest)
        self.assertEqual(app.version, None)
        self.assertEqual(app.nextversion, Request._meta.get_field_by_name('version')[0].to_python('13.0.782.112'))
        self.assertEqual(app.lang, 'en')
        self.assertEqual(app.tag, None)
        self.assertEqual(app.installage, 6)
        self.assertEqual(app.appid, '{8A69D345-D564-463C-AFF1-A69D9E530F96}')
    def test_parse_apps(self):
        request = parse_request(fixtures.request_event)
        req = parse_req(request)
        req.os = parse_os(request.os)
        req.hw = parse_hw(request.hw) if request.get('hw') else None
        req.save()

        apps = parse_apps(request.findall('app'), req)
        self.assertEqual(len(apps), 1)
        app = apps[0]
        self.assertIsInstance(app, AppRequest)
        self.assertEqual(app.version, None)
        self.assertEqual(app.nextversion, Request._meta.get_field_by_name('version')[0].to_python('13.0.782.112'))
        self.assertEqual(app.lang, 'en')
        self.assertEqual(app.tag, 'stable')
        self.assertEqual(app.installage, 6)
        self.assertEqual(app.appid, '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}')
    def test_parse_apps(self):
        request = parse_request(fixtures.request_event)
        req = parse_req(request)
        req.os = parse_os(request.os)
        req.hw = parse_hw(request.hw) if request.get('hw') else None
        req.save()

        apps = parse_apps(request.findall('app'), req)
        self.assertEqual(len(apps), 1)
        app = apps[0]
        self.assertIsInstance(app, AppRequest)
        self.assertEqual(app.version, None)
        self.assertEqual(app.nextversion, Request._meta.get_field_by_name('version')[0].to_python('13.0.782.112'))
        self.assertEqual(app.lang, 'en')
        self.assertEqual(app.tag, None)
        self.assertEqual(app.installage, 6)
        self.assertEqual(app.appid, '{8A69D345-D564-463C-AFF1-A69D9E530F96}')
    def test_parse_apps(self):
        request = parse_request(fixtures.request_event)
        req = parse_req(request)
        req.os = parse_os(request.os)
        req.hw = parse_hw(request.hw) if request.get("hw") else None
        req.save()

        apps = parse_apps(request.findall("app"), req)
        self.assertEqual(len(apps), 1)
        app = apps[0]
        self.assertIsInstance(app, AppRequest)
        self.assertEqual(app.version, None)
        self.assertEqual(app.nextversion, Request._meta.get_field_by_name("version")[0].to_python("13.0.782.112"))
        self.assertEqual(app.lang, "en")
        self.assertEqual(app.tag, None)
        self.assertEqual(app.installage, 6)
        self.assertEqual(app.appid, "{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}")
 def test_parse_events(self):
     request = parse_request(fixtures.request_event)
     events = request.findall("app")[0].findall("event")
     events = parse_events(events)
     self.assertEqual(len(events), 3)
     event = events[0]
     self.assertIsInstance(event, Event)
     self.assertEqual(event.eventtype, 9)
     self.assertEqual(event.eventresult, 1)
     self.assertEqual(event.errorcode, 0)
     self.assertEqual(event.extracode1, 0)
     self.assertEqual(event.download_time_ms, None)
     self.assertEqual(event.downloaded, None)
     self.assertEqual(event.total, None)
     self.assertEqual(event.update_check_time_ms, None)
     self.assertEqual(event.install_time_ms, None)
     self.assertEqual(event.source_url_index, None)
     self.assertEqual(event.state_cancelled, None)
     self.assertEqual(event.time_since_update_available_ms, None)
     self.assertEqual(event.time_since_download_start_ms, None)
     self.assertEqual(event.nextversion, None)
     self.assertEqual(event.previousversion, None)
Exemple #25
0
 def test_parse_events(self):
     request = parse_request(fixtures.request_event)
     events = request.findall('app')[0].findall('event')
     events = parse_events(events)
     self.assertEqual(len(events), 3)
     event = events[0]
     self.assertIsInstance(event, Event)
     self.assertEqual(event.eventtype, 9)
     self.assertEqual(event.eventresult, 1)
     self.assertEqual(event.errorcode, 0)
     self.assertEqual(event.extracode1, 0)
     self.assertEqual(event.download_time_ms, None)
     self.assertEqual(event.downloaded, None)
     self.assertEqual(event.total, None)
     self.assertEqual(event.update_check_time_ms, None)
     self.assertEqual(event.install_time_ms, None)
     self.assertEqual(event.source_url_index, None)
     self.assertEqual(event.state_cancelled, None)
     self.assertEqual(event.time_since_update_available_ms, None)
     self.assertEqual(event.time_since_download_start_ms, None)
     self.assertEqual(event.nextversion, None)
     self.assertEqual(event.previousversion, None)
 def generate_version(self, is_enabled):
     app = Application.objects.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='app')
     platform = Platform.objects.create(name='win')
     channel = Channel.objects.create(name='stable')
     userid = 1
     Version.objects.create(
         is_enabled=is_enabled,
         app=app,
         platform=platform,
         channel=channel,
         version='0.0.0.2',
         file=SimpleUploadedFile('./chrome_installer.exe', False))
     start = timezone.now() - timedelta(3)
     end = timezone.now()
     request = parse_request(fixtures.request_event_uninstall_success)
     apps = request.findall('app')
     userid_counting(userid, apps, platform)
     return get_users_live_versions(
         app_id=app.pk,
         channel=channel,
         start=start,
         end=end,
     )
Exemple #27
0
    def test_add_app_live_statistics(self):
        request = parse_request(fixtures.request_update_check)
        app = request.findall('app')[0]

        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version = app.get('version')

        events_appid_version = HourEvents('online:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = HourEvents('online:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)

        add_app_live_statistics(userid, platform, app)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)

        self.assertIn(userid, events_appid_version)
        self.assertIn(userid, events_appid_platform_version)
Exemple #28
0
def collect_statistics(request, ip=None):
    statistics.collect_statistics(parse_request(request), ip=ip)
    def test_collect_statistics(self):
        request = parse_request(fixtures.request_event)

        self.assertEqual(Os.objects.all().count(), 0)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 0)
        self.assertEqual(AppRequest.objects.all().count(), 0)
        self.assertEqual(Event.objects.all().count(), 0)

        collect_statistics(request)

        self.assertEqual(Os.objects.all().count(), 1)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 1)
        self.assertEqual(AppRequest.objects.all().count(), 1)
        self.assertEqual(Event.objects.all().count(), 3)

        os = Os.objects.get()
        req = Request.objects.get()
        app_req = AppRequest.objects.get()
        events = Event.objects.all()

        self.assertEqual(os.platform, "win")
        self.assertEqual(os.version, "6.1")
        self.assertEqual(os.sp, "")
        self.assertEqual(os.arch, "x64")

        self.assertEqual(req.version, Request._meta.get_field_by_name("version")[0].to_python("1.3.23.0"))
        self.assertEqual(req.ismachine, 1)
        self.assertEqual(req.sessionid, "{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}")
        self.assertEqual(req.userid, "{D0BBD725-742D-44ae-8D46-0231E881D58E}")
        self.assertEqual(req.originurl, None)
        self.assertEqual(req.testsource, "ossdev")
        self.assertEqual(req.updaterchannel, None)
        self.assertEqual(req.os, os)
        self.assertEqual(req.hw, None)

        self.assertEqual(app_req.version, None)
        self.assertEqual(app_req.nextversion, Request._meta.get_field_by_name("version")[0].to_python("13.0.782.112"))
        self.assertEqual(app_req.lang, "en")
        self.assertEqual(app_req.tag, None)
        self.assertEqual(app_req.installage, 6)
        self.assertEqual(app_req.appid, "{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}")
        self.assertEqual(app_req.request, req)

        event = events[0]

        self.assertEqual(event.eventtype, 9)
        self.assertEqual(event.eventresult, 1)
        self.assertEqual(event.errorcode, 0)
        self.assertEqual(event.extracode1, 0)
        self.assertEqual(event.download_time_ms, None)
        self.assertEqual(event.downloaded, None)
        self.assertEqual(event.total, None)
        self.assertEqual(event.update_check_time_ms, None)
        self.assertEqual(event.install_time_ms, None)
        self.assertEqual(event.source_url_index, None)
        self.assertEqual(event.state_cancelled, None)
        self.assertEqual(event.time_since_update_available_ms, None)
        self.assertEqual(event.time_since_download_start_ms, None)
        self.assertEqual(event.nextversion, None)
        self.assertEqual(event.previousversion, None)

        for e in events:
            self.assertIn(e, app_req.events.all())
Exemple #30
0
    def test_collect_statistics(self):
        request = parse_request(fixtures.request_event)

        self.assertEqual(Os.objects.all().count(), 0)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 0)
        self.assertEqual(AppRequest.objects.all().count(), 0)
        self.assertEqual(Event.objects.all().count(), 0)

        collect_statistics(request)

        self.assertEqual(Os.objects.all().count(), 1)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 1)
        self.assertEqual(AppRequest.objects.all().count(), 1)
        self.assertEqual(Event.objects.all().count(), 3)

        os = Os.objects.get()
        req = Request.objects.get()
        app_req = AppRequest.objects.get()
        events = Event.objects.all()

        self.assertEqual(os.platform, 'win')
        self.assertEqual(os.version, '6.1')
        self.assertEqual(os.sp, '')
        self.assertEqual(os.arch, 'x64')

        self.assertEqual(req.version, Request._meta.get_field_by_name('version')[0].to_python('1.3.23.0'))
        self.assertEqual(req.ismachine, 1)
        self.assertEqual(req.sessionid, '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
        self.assertEqual(req.userid, '{F25EC606-5FC2-449b-91FF-FA21CADB46E4}')
        self.assertEqual(req.originurl, None)
        self.assertEqual(req.testsource, 'ossdev')
        self.assertEqual(req.updaterchannel, None)
        self.assertEqual(req.os, os)
        self.assertEqual(req.hw, None)

        self.assertEqual(app_req.version, None)
        self.assertEqual(app_req.nextversion, Request._meta.get_field_by_name('version')[0].to_python('13.0.782.112'))
        self.assertEqual(app_req.lang, 'en')
        self.assertEqual(app_req.tag, None)
        self.assertEqual(app_req.installage, 6)
        self.assertEqual(app_req.appid, '{8A69D345-D564-463C-AFF1-A69D9E530F96}')
        self.assertEqual(app_req.request, req)

        event = events[0]

        self.assertEqual(event.eventtype, 9)
        self.assertEqual(event.eventresult, 1)
        self.assertEqual(event.errorcode, 0)
        self.assertEqual(event.extracode1, 0)
        self.assertEqual(event.download_time_ms, None)
        self.assertEqual(event.downloaded, None)
        self.assertEqual(event.total, None)
        self.assertEqual(event.update_check_time_ms, None)
        self.assertEqual(event.install_time_ms, None)
        self.assertEqual(event.source_url_index, None)
        self.assertEqual(event.state_cancelled, None)
        self.assertEqual(event.time_since_update_available_ms, None)
        self.assertEqual(event.time_since_download_start_ms, None)
        self.assertEqual(event.nextversion, None)
        self.assertEqual(event.previousversion, None)

        for e in events:
            self.assertIn(e, app_req.events.all())
Exemple #31
0
def collect_statistics(request):
    statistics.collect_statistics(parse_request(request))
Exemple #32
0
def collect_statistics(request, ip=None):
    statistics.collect_statistics(parse_request(request), ip=ip)
Exemple #33
0
    def test_collect_statistics(self):
        request = parse_request(fixtures.request_event)

        self.assertEqual(Os.objects.all().count(), 0)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 0)
        self.assertEqual(AppRequest.objects.all().count(), 0)
        self.assertEqual(Event.objects.all().count(), 0)

        collect_statistics(request)

        self.assertEqual(Os.objects.all().count(), 1)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 1)
        self.assertEqual(AppRequest.objects.all().count(), 1)
        self.assertEqual(Event.objects.all().count(), 3)

        os = Os.objects.get()
        req = Request.objects.get()
        app_req = AppRequest.objects.get()
        events = Event.objects.all()

        self.assertEqual(os.platform, 'win')
        self.assertEqual(os.version, '6.1')
        self.assertEqual(os.sp, '')
        self.assertEqual(os.arch, 'x64')

        self.assertEqual(
            req.version,
            Request._meta.get_field('version').to_python('1.3.23.0'))
        self.assertEqual(req.ismachine, 1)
        self.assertEqual(req.sessionid,
                         '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
        self.assertEqual(req.userid, '{D0BBD725-742D-44ae-8D46-0231E881D58E}')
        self.assertEqual(req.originurl, None)
        self.assertEqual(req.testsource, 'ossdev')
        self.assertEqual(req.updaterchannel, None)
        self.assertEqual(req.os, os)
        self.assertEqual(req.hw, None)

        self.assertEqual(app_req.version, None)
        self.assertEqual(
            app_req.nextversion,
            Request._meta.get_field('version').to_python('13.0.782.112'))
        self.assertEqual(app_req.lang, 'en')
        self.assertEqual(app_req.tag, 'stable')
        self.assertEqual(app_req.installage, 6)
        self.assertEqual(app_req.appid,
                         '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}')
        self.assertEqual(app_req.request, req)

        event = events[0]

        self.assertEqual(event.eventtype, 9)
        self.assertEqual(event.eventresult, 1)
        self.assertEqual(event.errorcode, 0)
        self.assertEqual(event.extracode1, 0)
        self.assertEqual(event.download_time_ms, None)
        self.assertEqual(event.downloaded, None)
        self.assertEqual(event.total, None)
        self.assertEqual(event.update_check_time_ms, None)
        self.assertEqual(event.install_time_ms, None)
        self.assertEqual(event.source_url_index, None)
        self.assertEqual(event.state_cancelled, None)
        self.assertEqual(event.time_since_update_available_ms, None)
        self.assertEqual(event.time_since_download_start_ms, None)
        self.assertEqual(event.nextversion, None)
        self.assertEqual(event.previousversion, None)

        for e in events:
            self.assertIn(e, app_req.events.all())
    def test_collect_statistics(self):
        request = parse_request(fixtures.request_event)

        self.assertEqual(Os.objects.all().count(), 0)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 0)
        self.assertEqual(AppRequest.objects.all().count(), 0)
        self.assertEqual(Event.objects.all().count(), 0)

        collect_statistics(request)

        self.assertEqual(Os.objects.all().count(), 1)
        self.assertEqual(Hw.objects.all().count(), 0)
        self.assertEqual(Request.objects.all().count(), 1)
        self.assertEqual(AppRequest.objects.all().count(), 1)
        self.assertEqual(Event.objects.all().count(), 3)

        os = Os.objects.get()
        req = Request.objects.get()
        app_req = AppRequest.objects.get()
        events = Event.objects.all()

        self.assertEqual(os.platform, 'win')
        self.assertEqual(os.version, '6.1')
        self.assertEqual(os.sp, '')
        self.assertEqual(os.arch, 'x64')

        self.assertEqual(req.version, Request._meta.get_field_by_name('version')[0].to_python('1.3.23.0'))
        self.assertEqual(req.ismachine, 1)
        self.assertEqual(req.sessionid, '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}')
        self.assertEqual(req.userid, '{F25EC606-5FC2-449b-91FF-FA21CADB46E4}')
        self.assertEqual(req.originurl, None)
        self.assertEqual(req.testsource, 'ossdev')
        self.assertEqual(req.updaterchannel, None)
        self.assertEqual(req.os, os)
        self.assertEqual(req.hw, None)

        self.assertEqual(app_req.version, None)
        self.assertEqual(app_req.nextversion, Request._meta.get_field_by_name('version')[0].to_python('13.0.782.112'))
        self.assertEqual(app_req.lang, 'en')
        self.assertEqual(app_req.tag, None)
        self.assertEqual(app_req.installage, 6)
        self.assertEqual(app_req.appid, '{8A69D345-D564-463C-AFF1-A69D9E530F96}')
        self.assertEqual(app_req.request, req)

        event = events[0]

        self.assertEqual(event.eventtype, 9)
        self.assertEqual(event.eventresult, 1)
        self.assertEqual(event.errorcode, 0)
        self.assertEqual(event.extracode1, 0)
        self.assertEqual(event.download_time_ms, None)
        self.assertEqual(event.downloaded, None)
        self.assertEqual(event.total, None)
        self.assertEqual(event.update_check_time_ms, None)
        self.assertEqual(event.install_time_ms, None)
        self.assertEqual(event.source_url_index, None)
        self.assertEqual(event.state_cancelled, None)
        self.assertEqual(event.time_since_update_available_ms, None)
        self.assertEqual(event.time_since_download_start_ms, None)
        self.assertEqual(event.nextversion, None)
        self.assertEqual(event.previousversion, None)

        for e in events:
            self.assertIn(e, app_req.events.all())
Exemple #35
0
def collect_statistics(request):
    statistics.collect_statistics(parse_request(request))