コード例 #1
0
ファイル: tests.py プロジェクト: slok/dwarf
    def test_users_login(self):

        users_ids = [random.randrange(0, 100000) for i in range(100)]
        date = datetime_now_utc().strftime(self.DATE_FORMAT)
        key = self.LOGIN_METRICS_FORMAT.format(date)

        for i in users_ids:
            self.assertEquals(LoginMetrics.FLAG_DOWN, self.r.getbit(key, i))

        ls = LoginMetrics(datetime_now_utc())
        ls.save_users_login(users_ids)

        for i in users_ids:
            self.assertEquals(LoginMetrics.FLAG_UP, self.r.getbit(key, i))
コード例 #2
0
    def handle(self, *args, **options):
        max_users = 5000 if len(args) < 1 else int(args[0])
        min_users = 0 if len(args) < 2 else int(args[1])
        day = None if len(args) < 3 else int(args[2])

        # Populate the DB for one day
        for hour in range(24):
            # Create the datetime for the key
            now = datetime_now_utc()
            if not day:
                day = now.day
            date = datetime(year=now.year,
                            month=now.month,
                            day=day,
                            hour=hour)

            # Get random login users
            logins = range(random.randrange(min_users, max_users))
            users = [random.randrange(min_users, max_users) for i in logins]

            # Save the users
            ls = LoginMetrics(date)
            ls.save_users_login(users)