'Test s3_impersonate'

def testImpersonate(self):

    auth = current.auth
    session = current.session
    sr = auth.get_system_roles()
    ADMIN = sr.ADMIN
    ANONYMOUS = sr.ANONYMOUS
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    assertRaises = self.assertRaises
    auth.s3_impersonate('admin@example.com')
    assertTrue(auth.s3_logged_in())
    assertTrue((auth.user is not None))
    assertTrue((ADMIN in session.s3.roles))
    assertTrue((ANONYMOUS in session.s3.roles))
    assertTrue((ADMIN in auth.user.realms))
    with assertRaises(ValueError):
        auth.s3_impersonate('NonExistentUser')
    assertTrue(auth.s3_logged_in())
    assertTrue((ADMIN in session.s3.roles))
    auth.s3_impersonate(None)
    assertFalse(auth.s3_logged_in())
    assertTrue(((session.s3.roles == []) or (ANONYMOUS in session.s3.roles)))
    auth.s3_impersonate(None)
