Ejemplo n.º 1
0
def with_celebrity_logged_in(celebrity_name):
    """Decorate a function so that it's run with a celebrity logged in."""
    return decorate_with(celebrity_logged_in, celebrity_name)
Ejemplo n.º 2
0
    return _with_login(login_as, ANONYMOUS)


@contextmanager
def celebrity_logged_in(celebrity_name):
    """Make a context manager for running logged in as a celebrity."""
    return _with_login(login_celebrity, celebrity_name)


@contextmanager
def admin_logged_in():
    # Use teamowner to avoid expensive and noisy team member additions.
    return _with_login(login_admin, None)


with_anonymous_login = decorate_with(person_logged_in, None)


def with_person_logged_in(person):
    return decorate_with(person_logged_in, person)


def with_celebrity_logged_in(celebrity_name):
    """Decorate a function so that it's run with a celebrity logged in."""
    return decorate_with(celebrity_logged_in, celebrity_name)


def run_with_login(person, function, *args, **kwargs):
    """Run 'function' with 'person' logged in."""
    with person_logged_in(person):
        return function(*args, **kwargs)
Ejemplo n.º 3
0
def with_person_logged_in(person):
    return decorate_with(person_logged_in, person)
Ejemplo n.º 4
0
 def test_decorate_with_returns(self):
     # decorate_with returns the original function's return value.
     decorator = decorate_with(self.trivialContextManager)
     arbitrary_value = self.getUniqueString()
     result = decorator(lambda: arbitrary_value)()
     self.assertEqual(arbitrary_value, result)
Ejemplo n.º 5
0
def with_celebrity_logged_in(celebrity_name):
    """Decorate a function so that it's run with a celebrity logged in."""
    return decorate_with(celebrity_logged_in, celebrity_name)
Ejemplo n.º 6
0
def with_person_logged_in(person):
    return decorate_with(person_logged_in, person)
Ejemplo n.º 7
0
    return _with_login(login_as, ANONYMOUS)


@contextmanager
def celebrity_logged_in(celebrity_name):
    """Make a context manager for running logged in as a celebrity."""
    return _with_login(login_celebrity, celebrity_name)


@contextmanager
def admin_logged_in():
    # Use teamowner to avoid expensive and noisy team member additions.
    return _with_login(login_admin, None)


with_anonymous_login = decorate_with(person_logged_in, None)


def with_person_logged_in(person):
    return decorate_with(person_logged_in, person)


def with_celebrity_logged_in(celebrity_name):
    """Decorate a function so that it's run with a celebrity logged in."""
    return decorate_with(celebrity_logged_in, celebrity_name)


def run_with_login(person, function, *args, **kwargs):
    """Run 'function' with 'person' logged in."""
    with person_logged_in(person):
        return function(*args, **kwargs)
Ejemplo n.º 8
0
 def test_decorate_with_returns(self):
     # decorate_with returns the original function's return value.
     decorator = decorate_with(self.trivialContextManager)
     arbitrary_value = self.getUniqueString()
     result = decorator(lambda: arbitrary_value)()
     self.assertEqual(arbitrary_value, result)