def test_make_admin_sets_admin_to_True_if_True(get_by_username): """If .admin is True it should just do nothing.""" fred = mock.Mock() fred.admin = True get_by_username.return_value = fred accounts.make_admin("fred") assert fred.admin is True
def test_make_admin_sets_admin_to_True_if_False(get_by_username): """It should set .admin to True if it was False.""" fred = mock.Mock() fred.admin = False get_by_username.return_value = fred accounts.make_admin("fred") assert fred.admin is True
def admins_add(request): """Make a given user an admin.""" username = request.params['add'] try: accounts.make_admin(username) except accounts.NoSuchUserError: request.session.flash( _("User {username} doesn't exist.".format(username=username)), "error") return admins_index(request)
def create(self): """Make a given user an admin.""" try: username = self.request.params["add"] except KeyError: raise httpexceptions.HTTPNotFound try: accounts.make_admin(username) except accounts.NoSuchUserError: self.request.session.flash(_("User {username} doesn't exist.".format(username=username)), "error") return self.index()
def test_make_admin_gets_user_by_username(get_by_username): """It should pass the right value to get_by_username().""" accounts.make_admin("fred") get_by_username.assert_called_once_with("fred")
def test_make_admin_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_admin("fred")
def admin(args): """Make a user an admin.""" request = bootstrap(args) accounts.make_admin(unicode(args.username, sys.getfilesystemencoding())) request.tm.commit()
def admin(args): """Make a user an admin.""" request = bootstrap(args) accounts.make_admin(args.username) request.tm.commit()
def admin(args): """Make a user an admin.""" paster.bootstrap(args.config_uri, request=Request.blank('')) accounts.make_admin(unicode(args.username, sys.getfilesystemencoding())) transaction.commit()