Пример #1
0
def test_make_staff_sets_staff_to_True_if_True(get_by_username):
    """If .staff is True it should just do nothing."""
    fred = mock.Mock()
    fred.staff = True
    get_by_username.return_value = fred

    accounts.make_staff("fred")

    assert fred.staff is True
Пример #2
0
def test_make_staff_sets_staff_to_True_if_False(get_by_username):
    """It should set .staff to True if it was False."""
    fred = mock.Mock()
    fred.staff = False
    get_by_username.return_value = fred

    accounts.make_staff("fred")

    assert fred.staff is True
Пример #3
0
def staff_add(request):
    """Make a given user a staff member."""
    username = request.params['add']
    try:
        accounts.make_staff(username)
    except accounts.NoSuchUserError:
        request.session.flash(
            _("User {username} doesn't exist.".format(username=username)),
            "error")
    return staff_index(request)
Пример #4
0
def staff_add(request):
    """Make a given user a staff member."""
    username = request.params['add']
    try:
        accounts.make_staff(username)
    except accounts.NoSuchUserError:
        request.session.flash(
            _("User {username} doesn't exist.".format(username=username)),
            "error")
    return staff_index(request)
Пример #5
0
def test_make_staff_raises_if_user_does_not_exist(get_by_username):
    """It should raise NoSuchUserError if the user doesn't exist."""
    get_by_username.return_value = None

    with pytest.raises(accounts.NoSuchUserError):
        accounts.make_staff("fred")
Пример #6
0
def test_make_staff_gets_user_by_username(get_by_username):
    """It should pass the right value to get_by_username()."""
    accounts.make_staff("fred")

    get_by_username.assert_called_once_with("fred")