~twom/canonical-identity-provider/django-1.11.x

« back to all changes in this revision

Viewing changes to src/identityprovider/tests/test_command_clean_old_authtokens.py

  • Committer: Ubuntu One Auto Copilot
  • Author(s): Colin Watson
  • Date: 2018-01-29 16:32:48 UTC
  • mfrom: (1593.2.1 no-xrange)
  • Revision ID: otto-copilot@canonical.com-20180129163248-zbbccdz42i9u3pwb
Handle range/xrange changes in Python 3.

Merged from https://code.launchpad.net/~cjwatson/canonical-identity-provider/no-xrange/+merge/336733

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
    def test_multiple_accounts_tokens_ages(self):
96
96
        auth_tokens = defaultdict(list)
97
97
        accounts = []
98
 
        for i in xrange(10):
 
98
        for i in range(10):
99
99
            account_mail = "{}-me@example.com".format(i)
100
100
            account = self.factory.make_account(email=account_mail)
101
101
            accounts.append(account)
104
104
            # (so account 0 will have no tokens, account9 will have 9 tokens)
105
105
            # Ages range from 0 days (starting in account1) to 8 days (one for
106
106
            # account9)
107
 
            for age in xrange(i):
 
107
            for age in range(i):
108
108
                days_ago = now() - timedelta(days=age)
109
109
                auth_tokens[age].append(self.factory.make_authtoken(
110
110
                    email=account_mail, requester=account,
122
122
            # 2 tokens with age 7
123
123
            # 1  token with age 8
124
124
            # 0 tokens with age 9
125
 
        for cutoff in xrange(9, 0, -1):
 
125
        for cutoff in range(9, 0, -1):
126
126
            expected_tokens = 9 - cutoff
127
127
            output = self.call_the_command(max_age=cutoff)
128
128
            self.assertIn(
129
129
                "Deleting {} tokens older than {} days".format(
130
130
                    expected_tokens, cutoff), output)
131
131
            existing_tokens = AuthToken.objects.all()
132
 
            for age in xrange(9):
 
132
            for age in range(9):
133
133
                for token in auth_tokens[age]:
134
134
                    if age >= cutoff:
135
135
                        self.assertNotIn(token, existing_tokens)