'Assert that two tokens are equal.
Compare two tokens except for their ids. This also truncates
the time in the comparison.'

def assertEqualTokens(self, a, b, enforce_audit_ids=True):

    def normalize(token):
        token['access']['token']['id'] = 'dummy'
        del token['access']['token']['expires']
        del token['access']['token']['issued_at']
        del token['access']['token']['audit_ids']
        return token
    self.assertCloseEnoughForGovernmentWork(timeutils.parse_isotime(a['access']['token']['expires']), timeutils.parse_isotime(b['access']['token']['expires']))
    self.assertCloseEnoughForGovernmentWork(timeutils.parse_isotime(a['access']['token']['issued_at']), timeutils.parse_isotime(b['access']['token']['issued_at']))
    if enforce_audit_ids:
        self.assertIn(a['access']['token']['audit_ids'][0], b['access']['token']['audit_ids'])
        self.assertThat(len(a['access']['token']['audit_ids']), matchers.LessThan(3))
        self.assertThat(len(b['access']['token']['audit_ids']), matchers.LessThan(3))
    return self.assertDictEqual(normalize(a), normalize(b))
