def other_user(dbsession): user = User( lastname=u"Lastname2", firstname=u"Firstname2", email="*****@*****.**", ) dbsession.add(user) dbsession.flush() return user
def migrate_datas(): from autonomie_base.models.base import DBSESSION session = DBSESSION() from alembic.context import get_bind connection = get_bind() from autonomie.models.user.login import Login op.execute("update groups set editable=0;") op.execute("update groups set `primary`=0;") op.execute( "update groups set `primary`=1 where name IN ('admin', 'contractor', 'manager')" ) op.execute('update accounts set civilite="Monsieur"') for user in connection.execute(user_helper.select()): login = Login( user_id=user.id, login=user.login, ) login.pwd_hash = user.password, login.active = user.active == 'Y' session.add(login) session.flush() op.execute( 'UPDATE user_groups set login_id="%s" where user_id=%s' % ( login.id, user.id ) ) op.drop_column("accounts", "login") op.drop_column("accounts", "password") op.drop_column("accounts", "active") from autonomie.models.user.user import User for userdatas in connection.execute(userdatas_helper.select()): if userdatas.user_id is None: user = User( lastname=userdatas.coordonnees_lastname, firstname=userdatas.coordonnees_firstname, email=userdatas.coordonnees_email1, civilite=userdatas.coordonnees_civilite or 'Monsieur', ) session.add(user) session.flush() connection.execute( userdatas_helper.update().where( userdatas_helper.c.id == userdatas.id ).values(user_id=user.id) ) else: user = User.get(userdatas.user_id) user.civilite = userdatas.coordonnees_civilite or 'Monsieur' session.merge(user) session.flush() op.execute('update accounts set civilite="Monsieur" where civilite is NULL')
def user(dbsession): from autonomie.models.user.user import User user = User( lastname=u"Lastname", firstname=u"Firstname", email="*****@*****.**", ) dbsession.add(user) dbsession.flush() return user
def test_edit_schema_login_context(dbsession, pyramid_request, login, user, groups): import colander from autonomie.forms.user.login import get_add_edit_schema from autonomie.models.user.login import Login from autonomie.models.user.user import User user2 = User(email='*****@*****.**', lastname='lastname2', firstname='firstname2') dbsession.add(user2) dbsession.flush() item = Login(user_id=user2.id, login="******") item.set_password('pwd2') dbsession.add(item) dbsession.flush() pyramid_request.context = item schema = get_add_edit_schema(edit=True) schema = schema.bind(request=pyramid_request) result = schema.deserialize({ 'login': '******', 'pwd_hash': '', 'primary_group': "manager", 'groups': ['trainer'], 'user_id': user2.id, }) assert 'pwd_hash' not in result result = schema.deserialize({ 'login': '******', 'pwd_hash': 'notpwd2', 'primary_group': "manager", 'groups': ['trainer'], 'user_id': user2.id, }) assert 'pwd_hash' in result # Login already used with pytest.raises(colander.Invalid): schema.deserialize({ 'login': '******', 'pwd_hash': '', 'primary_group': "manager", 'groups': ['trainer'], 'user_id': user2.id, }) # User already linked to Login class with pytest.raises(colander.Invalid): schema.deserialize({ 'login': '******', 'pwd_hash': 'ooo', 'primary_group': "manager", 'groups': ['trainer'], 'user_id': user.id }) # wrong primary group with pytest.raises(colander.Invalid): schema.deserialize({ 'login': '******', 'pwd_hash': 'ooo', "primary_group": "falseone", 'groups': ['trainer'], 'user_id': user2.id, }) # wrong group with pytest.raises(colander.Invalid): schema.deserialize({ 'login': '******', 'pwd_hash': 'ooo', "primary_group": "contractor", 'user_id': user2.id, "groups": ["falseone"], })