@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
    @patch('omaha.models.version_upload_to', lambda o, f: f)
    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}'
        install_date = datetime(year=2014, month=1, day=1, hour=15, minute=41, second=48)
        update_date = install_date + timedelta(days=31)

        request_events = DayEvents('request', install_date.year, install_date.month, install_date.day)
        app1_install_events = DayEvents('new_install:%s' % appid1, install_date.year, install_date.month, install_date.day)
        app2_install_events = DayEvents('new_install:%s' % appid2, install_date.year, install_date.month, install_date.day)
        app1_update_events = DayEvents('request:%s' % appid1, update_date.year, update_date.month, update_date.day)
        app2_update_events = DayEvents('request:%s' % appid2, update_date.year, update_date.month, update_date.day)

        self.assertEqual(len(request_events), 0)
        self.assertEqual(len(app1_install_events), 0)
        self.assertEqual(len(app2_install_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',
            )
        )

        with freeze_time(install_date):  # 56508 sec
            self.client.post(reverse('update'),
                             fixtures.request_update_check, content_type='text/xml')

        self.assertEqual(len(request_events), 1)
        self.assertEqual(len(app1_install_events), 1)
        self.assertEqual(len(app2_install_events), 1)
        self.assertTrue(user_id in request_events)
        self.assertTrue(user_id in app1_install_events)
        self.assertTrue(user_id in app2_install_events)

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

        self.assertEqual(len(app1_update_events), 1)
        self.assertEqual(len(app2_update_events), 1)
        self.assertTrue(user_id in app1_update_events)
        self.assertTrue(user_id in app2_update_events)
dataset/ETHPy150Open Crystalnix/omaha-server/omaha_server/omaha/tests/test_views.py/UpdateViewTest.test_userid_counting/original