예제 #1
0
    def test_get_id_new(self):
        id = get_id(self.uid)

        self.assertIsInstance(id, int)

        _id = self.redis.get('{}:{}'.format(KEY_PREFIX, self.uid))
        self.assertEqual(id, int(_id))
        self.assertEqual(id, int(self.redis.get(KEY_LAST_ID)))

        get_id('new_uid')
        self.assertEqual(id + 1, int(self.redis.get(KEY_LAST_ID)))
예제 #2
0
    def test_get_id_new(self):
        id = get_id(self.uid)

        self.assertIsInstance(id, int)

        _id = self.redis.get('{}:{}'.format(KEY_PREFIX, self.uid))
        self.assertEqual(id, int(_id))
        self.assertEqual(id, int(self.redis.get(KEY_LAST_ID)))

        get_id('new_uid')
        self.assertEqual(id + 1, int(self.redis.get(KEY_LAST_ID)))
예제 #3
0
    def test_userid_counting(self, mock_add_app_statistics):
        now = datetime.utcnow()

        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        app_list = [
            dict(appid='{F97917B1-19AB-48C1-9802-CEF305B10804}'),
            dict(appid='{555B8D18-076D-4576-9579-1FD7F0399EAE}')
        ]

        request_events = DayEvents('request', now.year, now.month, now.day)

        self.assertFalse(user1_id in request_events)
        self.assertEqual(len(request_events), 0)

        userid_counting(userid1, app_list, 'win')

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 1)
        self.assertTrue(user1_id in request_events)

        userid_counting(userid1, app_list, 'win')

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 1)

        self.assertFalse(user2_id in request_events)
        userid_counting(userid2, app_list[:1], 'win')
        self.assertTrue(user2_id in request_events)
        for app in app_list[:1]:
            mock_add_app_statistics.assert_any_call(user2_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 2)
예제 #4
0
    def test_update_live_statistics(self):
        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
        version = '0.0.0.1'
        channel = 'test'
        test_app = dict(appid=appid, version=version, tag=channel)
        platform = 'mac'

        request_version_events = HourEvents('request:{}:{}'.format(appid, version))
        request_platform_version_events = HourEvents('request:{}:{}:{}'.format(appid, 'mac', version))
        request_appid_platform_channel_version = HourEvents('request:{}:{}:{}:{}'.format(appid, 'mac', channel, version))

        self.assertFalse(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 0)
        self.assertFalse(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 0)
        self.assertFalse(user1_id in request_appid_platform_channel_version)
        self.assertEqual(len(request_appid_platform_channel_version), 0)

        userid_counting(userid1, test_app, platform)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)
        self.assertTrue(user1_id in request_appid_platform_channel_version)
        self.assertEqual(len(request_appid_platform_channel_version), 1)

        userid_counting(userid1, test_app, platform)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)
        self.assertTrue(user1_id in request_appid_platform_channel_version)
        self.assertEqual(len(request_appid_platform_channel_version), 1)

        userid_counting(userid2, test_app, platform)

        self.assertTrue(user2_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user2_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)
        self.assertTrue(user2_id in request_appid_platform_channel_version)
        self.assertEqual(len(request_appid_platform_channel_version), 2)
예제 #5
0
    def test_userid_counting(self, mock_add_app_statistics):
        now = datetime.utcnow()

        userid1 = "{F07B3878-CD6F-4B96-B52F-95C4D23077E0}"
        user1_id = get_id(userid1)

        userid2 = "{EC4C5647-F798-4BCA-83DA-926CD448A1D5}"
        user2_id = get_id(userid2)

        app_list = [
            dict(appid="{F97917B1-19AB-48C1-9802-CEF305B10804}"),
            dict(appid="{555B8D18-076D-4576-9579-1FD7F0399EAE}"),
        ]

        request_events = DayEvents("request", now.year, now.month, now.day)

        self.assertFalse(user1_id in request_events)
        self.assertEqual(len(request_events), 0)

        userid_counting(userid1, app_list, "win")

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id, "win", app, now=None)

        self.assertEqual(len(request_events), 1)
        self.assertTrue(user1_id in request_events)

        userid_counting(userid1, app_list, "win")

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id, "win", app, now=None)

        self.assertEqual(len(request_events), 1)

        self.assertFalse(user2_id in request_events)
        userid_counting(userid2, app_list[:1], "win")
        self.assertTrue(user2_id in request_events)
        for app in app_list[:1]:
            mock_add_app_statistics.assert_any_call(user2_id, "win", app, now=None)

        self.assertEqual(len(request_events), 2)
예제 #6
0
    def test_userid_counting(self):
        now = datetime.utcnow()
        userid = '{D0BBD725-742D-44ae-8D46-0231E881D58E}'
        user_id = get_id(userid)
        appid1 = '{430FD4D0-B729-4F61-AA34-91526481799D}'
        appid2 = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}'

        request_events = DayEvents('request', now.year, now.month, now.day)
        app1_events = DayEvents('request:%s' % appid1, now.year, now.month, now.day)
        app2_events = DayEvents('request:%s' % appid2, now.year, now.month, now.day)

        self.assertEqual(len(request_events), 0)
        self.assertEqual(len(app1_events), 0)
        self.assertEqual(len(app2_events), 0)


        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        platform = PlatformFactory.create(name='win')
        channel = ChannelFactory.create(name='stable')
        obj = VersionFactory.create(
            app=app,
            platform=platform,
            channel=channel,
            version='13.0.782.112',
            file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192))
        obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo='
        obj.save()

        Action.objects.create(
            version=obj,
            arguments='--do-not-launch-chrome',
            event=EVENT_DICT_CHOICES['install'],
            run='chrome_installer.exe'
        )

        Action.objects.create(
            version=obj,
            event=EVENT_DICT_CHOICES['postinstall'],
            other=dict(
                version='13.0.782.112',
                onsuccess='exitsilentlyonlaunchcmd',
            )
        )

        self.client.post(reverse('update'),
                         fixtures.request_update_check, content_type='text/xml')

        self.assertEqual(len(request_events), 1)
        self.assertEqual(len(app1_events), 1)
        self.assertEqual(len(app2_events), 1)
        self.assertTrue(user_id in request_events)
        self.assertTrue(user_id in app1_events)
        self.assertTrue(user_id in app2_events)
예제 #7
0
    def test_userid_counting(self):
        now = datetime.utcnow()
        userid = '{D0BBD725-742D-44ae-8D46-0231E881D58E}'
        user_id = get_id(userid)
        appid1 = '{430FD4D0-B729-4F61-AA34-91526481799D}'
        appid2 = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}'

        request_events = DayEvents('request', now.year, now.month, now.day)
        app1_events = DayEvents('request:%s' % appid1, now.year, now.month,
                                now.day)
        app2_events = DayEvents('request:%s' % appid2, now.year, now.month,
                                now.day)

        self.assertEqual(len(request_events), 0)
        self.assertEqual(len(app1_events), 0)
        self.assertEqual(len(app2_events), 0)

        app = ApplicationFactory.create(
            id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        platform = PlatformFactory.create(name='win')
        channel = ChannelFactory.create(name='stable')
        obj = VersionFactory.create(app=app,
                                    platform=platform,
                                    channel=channel,
                                    version='13.0.782.112',
                                    file=SimpleUploadedFile(
                                        './chrome_installer.exe',
                                        b'_' * 23963192))
        obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo='
        obj.save()

        Action.objects.create(version=obj,
                              arguments='--do-not-launch-chrome',
                              event=EVENT_DICT_CHOICES['install'],
                              run='chrome_installer.exe')

        Action.objects.create(version=obj,
                              event=EVENT_DICT_CHOICES['postinstall'],
                              other=dict(
                                  version='13.0.782.112',
                                  onsuccess='exitsilentlyonlaunchcmd',
                              ))

        self.client.post(reverse('update'),
                         fixtures.request_update_check,
                         content_type='text/xml')

        self.assertEqual(len(request_events), 1)
        self.assertEqual(len(app1_events), 1)
        self.assertEqual(len(app2_events), 1)
        self.assertTrue(user_id in request_events)
        self.assertTrue(user_id in app1_events)
        self.assertTrue(user_id in app2_events)
예제 #8
0
    def test_update_live_statistics(self):
        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
        version = '0.0.0.1'

        request_version_events = HourEvents('online:{}:{}'.format(
            appid, version))
        request_platform_version_events = HourEvents('online:{}:{}:{}'.format(
            appid, 'mac', version))

        self.assertFalse(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 0)
        self.assertFalse(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 0)

        update_live_statistics(userid1, appid, version)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)

        update_live_statistics(userid1, appid, version)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)

        update_live_statistics(userid2, appid, version)

        self.assertTrue(user2_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user2_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)
    def test_is_user_active(self):
        userid = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        id = get_id(userid)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['all'], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES['week'], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES['month'], userid))

        mark_event('request', id)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['all'], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['week'], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['month'], userid))
예제 #10
0
    def test_collect_statistics(self, mock_update_live_statistics):
        app_id = '00000000-0000-0000-0000-000000000001'
        app_name = "Sparrow"
        channel = "test"
        version = "0.0.0.1"
        deviceID = "A37152BF-A3CB-5FEC-8230-FACF43BDCDDD"
        request = RequestFactory().get('/sparkle/%s/%s/appcast.xml?appVersionShort=%s&deviceID=%s' %
                                       (app_name, channel, version, deviceID))

        collect_statistics(request, app_id, channel)

        user_id = get_id(deviceID)
        mock_update_live_statistics.assert_called_with(user_id, app_id, version)
예제 #11
0
    def test_is_user_active(self):
        userid = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        id = get_id(userid)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['all'], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES['week'], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES['month'], userid))

        mark_event('request', id)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['all'], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['week'], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES['month'], userid))
예제 #12
0
    def test_is_user_active(self):
        userid = "{F07B3878-CD6F-4B96-B52F-95C4D23077E0}"
        id = get_id(userid)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES["all"], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES["week"], userid))
        self.assertFalse(is_user_active(ACTIVE_USERS_DICT_CHOICES["month"], userid))

        mark_event("request", id)

        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES["all"], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES["week"], userid))
        self.assertTrue(is_user_active(ACTIVE_USERS_DICT_CHOICES["month"], userid))
예제 #13
0
    def test_update_live_statistics(self):
        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
        version = '0.0.0.1'

        request_version_events = HourEvents('online:{}:{}'.format(appid, version))
        request_platform_version_events = HourEvents('online:{}:{}:{}'.format(appid, 'mac', version))

        self.assertFalse(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 0)
        self.assertFalse(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 0)

        update_live_statistics(user1_id, appid, version)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)

        update_live_statistics(user1_id, appid, version)

        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)

        update_live_statistics(user2_id, appid, version)

        self.assertTrue(user2_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user2_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)
예제 #14
0
    def test_get_app_version_active_users(self):
        userid = "{%s}" % UUID(int=1)
        userid_beta = "{%s}" % UUID(int=40)
        userid_beta_not_active = "{%s}" % UUID(int=60)
        version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', b''))
        version_beta = Version.objects.create(
            file=SimpleUploadedFile('./chrome_installer.exe', b''),
            app=version.app,
            platform=version.platform,
            channel=version.channel,
            version='39.0.0.0',
        )


        id = get_id(userid_beta)
        mark_event('request', id)

        PartialUpdate.objects.create(version=version_beta,
                                     percent=5,
                                     start_date=datetime.now(),
                                     end_date=datetime.now())

        self.assertEqual(version, get_version(version.app.pk,
                                              version.platform.name,
                                              version.channel.name,
                                              '36.0.2062.124',
                                              userid))

        self.assertEqual(version_beta, get_version(version.app.pk,
                                                   version.platform.name,
                                                   version.channel.name,
                                                   '36.0.2062.124',
                                                   userid_beta))

        self.assertEqual(version, get_version(version.app.pk,
                                              version.platform.name,
                                              version.channel.name,
                                              '36.0.2062.124',
                                              userid_beta_not_active))
예제 #15
0
    def test_add_app_statistics(self):
        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
        version = '0.0.0.1'
        channel = 'test'
        test_app = dict(appid=appid, version=version, tag=channel)

        install_app_events = DayEvents('new_install:%s' % appid)
        request_app_events = DayEvents('request:%s' % appid)
        request_version_events = DayEvents('request:{}:{}'.format(appid, version))
        install_platform_events = DayEvents('new_install:{}:{}'.format(appid, 'mac'))
        request_platform_events = DayEvents('request:{}:{}'.format(appid, 'mac'))
        request_channel_events = DayEvents('request:{}:{}'.format(appid, channel))
        request_platform_version_events = DayEvents('request:{}:{}:{}'.format(appid, 'mac', version))

        self.assertFalse(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 0)
        self.assertFalse(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 0)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertFalse(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 0)
        self.assertFalse(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 0)
        self.assertFalse(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 0)

        add_app_statistics(user1_id, 'mac', test_app)
        self.assertTrue(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 1)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 1)
        self.assertTrue(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)


        add_app_statistics(user2_id, 'mac', test_app)

        self.assertTrue(user2_id in install_app_events)
        self.assertEqual(len(install_app_events), 2)
        self.assertFalse(user2_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user2_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user2_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user2_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 2)
        self.assertTrue(user2_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 2)
        self.assertTrue(user2_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)

        add_app_statistics(user1_id, 'mac', test_app)

        self.assertTrue(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 2)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 2)
        self.assertTrue(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 2)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)
예제 #16
0
def update_live_statistics(userid, apps_list, platform, now=None):
    id = get_id(userid)
    list(map(partial(add_app_live_statistics, id, platform, now=now), apps_list or []))
예제 #17
0
def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(map(partial(add_app_statistics, id, platform, now=now), apps_list or []))
예제 #18
0
def _(period, userid):
    return get_id(userid) in MonthEvents.from_date('request', timezone.now())
예제 #19
0
    def test_add_app_statistics(self):
        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
        version = '0.0.0.1'
        channel = 'test'
        test_app = dict(appid=appid, version=version, tag=channel)

        install_app_events = DayEvents('new_install:%s' % appid)
        request_app_events = DayEvents('request:%s' % appid)
        request_version_events = DayEvents('request:{}:{}'.format(
            appid, version))
        install_platform_events = DayEvents('new_install:{}:{}'.format(
            appid, 'mac'))
        request_platform_events = DayEvents('request:{}:{}'.format(
            appid, 'mac'))
        request_channel_events = DayEvents('request:{}:{}'.format(
            appid, channel))
        request_platform_version_events = DayEvents('request:{}:{}:{}'.format(
            appid, 'mac', version))

        self.assertFalse(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 0)
        self.assertFalse(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 0)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertFalse(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 0)
        self.assertFalse(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 0)
        self.assertFalse(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 0)

        add_app_statistics(user1_id, 'mac', test_app)
        self.assertTrue(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 1)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 1)
        self.assertTrue(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 1)
        self.assertTrue(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 1)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 1)

        add_app_statistics(user2_id, 'mac', test_app)

        self.assertTrue(user2_id in install_app_events)
        self.assertEqual(len(install_app_events), 2)
        self.assertFalse(user2_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user2_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user2_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user2_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 2)
        self.assertTrue(user2_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 2)
        self.assertTrue(user2_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)

        add_app_statistics(user1_id, 'mac', test_app)

        self.assertTrue(user1_id in install_app_events)
        self.assertEqual(len(install_app_events), 2)
        self.assertFalse(user1_id in request_app_events)
        self.assertEqual(len(request_app_events), 0)
        self.assertFalse(user1_id in request_platform_events)
        self.assertEqual(len(request_platform_events), 0)
        self.assertTrue(user1_id in request_version_events)
        self.assertEqual(len(request_version_events), 2)
        self.assertTrue(user1_id in install_platform_events)
        self.assertEqual(len(install_platform_events), 2)
        self.assertTrue(user1_id in request_channel_events)
        self.assertEqual(len(request_channel_events), 2)
        self.assertTrue(user1_id in request_platform_version_events)
        self.assertEqual(len(request_platform_version_events), 2)
예제 #20
0
 def test_get_id_exist(self):
     id = 123
     self.redis.set('{}:{}'.format(KEY_PREFIX, self.uid), 123)
     self.assertEqual(id, get_id(self.uid))
예제 #21
0
def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(
        map(partial(add_app_statistics, id, platform, now=now), apps_list
            or []))
예제 #22
0
def _(period, userid):
    return get_id(userid) in MonthEvents.from_date('request', timezone.now())
예제 #23
0
 def test_get_id_exist(self):
     id = 123
     self.redis.set('{}:{}'.format(KEY_PREFIX, self.uid), 123)
     self.assertEqual(id, get_id(self.uid))
예제 #24
0
def update_live_statistics(userid, apps_list, platform, now=None):
    id = get_id(userid)
    list(
        map(partial(add_app_live_statistics, id, platform, now=now), apps_list
            or []))
예제 #25
0
def _(period, userid):
    return get_id(userid) in WeekEvents.from_date("request", timezone.now())