def adduser(dbsession): user = User(login='******', lastname='lastname__éé', firstname='firstname__éé') user.set_password(u"Tést$!Pass") dbsession.add(user) dbsession.flush() return user
def user(dbsession): user = User(login='******', lastname='lastname__éé', firstname='firstname__éé', email="*****@*****.**") user.set_password(u"Tést$!Pass") dbsession.add(user) dbsession.flush() return user
def test_account(dbsession): a = User(**TEST1) a.set_password('pwd') assert a.auth("pwd") strange = "#;\'\\\" $25; é ö ô è à ù" a.set_password(strange) assert not a.auth("pwd") assert a.auth(strange)
def user(dbsession): from autonomie.models.user import User user = User( login=u"login", lastname=u"Lastname", firstname=u"Firstname", email="*****@*****.**", ) user.set_password('password') dbsession.add(user) dbsession.flush() return user
def test_role(dbsession): a = User(**TEST1) assert a.is_admin() assert not a.is_manager() a = User(**TEST2) assert a.is_manager() assert not a.is_admin() a = User(**TEST3) assert a.is_contractor() assert not a.is_admin()
def test_role(self): a = User(**TEST1) self.assertTrue(a.is_admin()) self.assertFalse(a.is_manager()) a = User(**TEST2) self.assertTrue(a.is_manager()) self.assertFalse(a.is_admin()) a = User(**TEST3) self.assertTrue(a.is_contractor()) self.assertFalse(a.is_admin())
def populate_db(session): from autonomie.models.user import User user = User( login='******', firstname='user1_firstname', lastname="user1_lastname", email="*****@*****.**" ) user.set_password('o') session.add(user) from autonomie.models.project import Project project = Project( name='Projet 1', code='P001', definition="Projet 1" ) session.add(project) from autonomie.models.customer import Customer cust = Customer( code='C001', name='Client1', contactLastName=u'Client Lastname', address=u'15 rue Victore Hugo', zipCode='69003', city='Lyon', ) cust.projects.append(project) session.add(cust) from autonomie.models.project import Phase phase = Phase(name='Phase de test') phase.project = project session.add(phase) from autonomie.models.company import Company c = Company( name="company1", goal="Company of user1", phone='0457858585', ) c.employees.append(user) c.customers.append(cust) c.projects.append(project) session.add(c) from autonomie.scripts import fake_database fake_database.set_configuration()
def add_user(login, password, group, firstname="", lastname=""): user = User(login=login, firstname=firstname, lastname=lastname) user.set_password(password) user.primary_group = group session = DBSESSION() session.add(user) session.flush() group_name = GROUPS[group] print "Added %s: %s/%s" % (group_name, login, password) return user
def test_account(self): a = User(**TEST1) a.set_password('pwd') self.assertTrue(a.auth("pwd")) strange = "#;\'\\\" $25; é ö ô è à ù" a.set_password(strange) self.assertFalse(a.auth("pwd")) self.assertTrue(a.auth(strange))
def objects(): user = User(login=u"test_user1", firstname=u"firstname", lastname=u"lastname") project = Project(name=u"Projet", code=u"PROJ") phase = Phase(name="test", project=project) return (user, phase, project)
def test_get_company(dbsession): user1 = User.query().first() cid = 1 company = user1.get_company(cid) assert company.name == u'company1' with pytest.raises(KeyError): user1.get_company(3000)
def add_user(login, password, group, firstname="", lastname="", email=""): user = User(login=login, firstname=firstname, lastname=lastname, email=email) user.set_password(password) user.groups.append(group) session = DBSESSION() session.add(user) session.flush() print "Added %s: %s/%s" % (group, login, password) return user
def user_add(arguments, env): """ Add a user in the database """ logger = logging.getLogger(__name__) login = get_value(arguments, 'user', 'admin.majerti') login = login.decode('utf-8') logger.debug(u"Adding a user {0}".format(login)) password = get_value(arguments, 'pwd', get_pwd()) password = password.decode('utf-8') firstname = get_value(arguments, 'firstname', 'Admin') lastname = get_value(arguments, 'lastname', 'Majerti') email = get_value(arguments, 'email', '*****@*****.**') group = get_value(arguments, 'group', None) user = User(login=login, firstname=firstname, lastname=lastname, email=email) if group: user.groups.append(group) user.set_password(password) db = DBSESSION() db.add(user) db.flush() print(u""" Account created : ID : {0.id} Login : {0.login} Firstname : {0.firstname} Lastname : {0.lastname} Email : {0.email} Groups : {0.groups} """.format(user)) if 'pwd' not in arguments: print(u""" Password : {0}""".format(password)) logger.debug(u"-> Done") return user
def unique_login(node, value): """ Test login unicity against database """ result = User.query(only_active=False).filter_by(login=value).first() if result: message = u"Le login '{0}' n'est pas disponible.".format( value) raise colander.Invalid(node, message)
def get_user_choices(): """ Return the a list of values for the contractor autocomplete widget """ choices = [(0, u'Tous les entrepreneurs')] choices.extend([(unicode(user.id), u"{0} {1}".format(user.lastname, user.firstname),) for user in User.query().all()]) return choices
def add_user(login, password, group, firstname="", lastname="", email=""): user = User(login=login, firstname=firstname, lastname=lastname, email=email) user.set_password(password) user.primary_group = group session = DBSESSION() session.add(user) session.flush() group_name = GROUPS[group] print "Added %s: %s/%s" % (group_name, login, password) return user
def add_user(login, password, group, firstname="", lastname="", email=""): user = User(login=login, firstname=firstname, lastname=lastname, email=email) user.set_password(password) user.groups.append(GROUPS[group]) session = DBSESSION() session.add(user) session.flush() group_name = GROUPS[group] print "Added %s: %s/%s" % (group_name, login, password) return user
def test_gen_cancelinvoice_payment(dbsession, invoice): user = User.query().first() project = Project.query().first() invoice.project = project invoice.owner = user invoice.statusPersonAccount = user invoice.record_payment(mode="c", amount=1500) cinv = invoice.gen_cancelinvoice(user) assert len(cinv.lines) == len(invoice.lines) + len(invoice.discounts) + 1 assert cinv.lines[-1].cost == 1500
def test_company_index(self): avatar = User.get(3) self.config.add_route('company', '/company/{cid}') self.config.add_static_view('static', 'autonomie:static') request = self.get_csrf_request() request._user = avatar request.user = avatar request.context = avatar.companies[0] response = company_index(request) self.assertEqual(avatar.companies[0].name, response['company'].name )
def user_add(arguments, env): """ Add a user in the database """ login = get_value(arguments, 'user', 'admin.majerti') login = login.decode('utf-8') password = get_value(arguments, 'pwd', get_pwd()) password = password.decode('utf-8') firstname = get_value(arguments, 'firstname', 'Admin') lastname = get_value(arguments, 'lastname', 'Majerti') email = get_value(arguments, 'email', '*****@*****.**') group = get_value(arguments, 'group', None) user = User( login=login, firstname=firstname, lastname=lastname, email=email ) if group: user.groups.append(group) user.set_password(password) db = DBSESSION() db.add(user) db.flush() print(u""" Account created : ID : {0.id} Login : {0.login} Firstname : {0.firstname} Lastname : {0.lastname} Email : {0.email} Groups : {0.groups} """.format(user)) if 'pwd' not in arguments: print(u""" Password : {0}""".format(password)) return user
def test_company_index(config, content, get_csrf_request_with_db): from autonomie.views.company import company_index avatar = User.query().first() config.add_route('company', '/company/{cid}') config.add_static_view('static', 'autonomie:static') request = get_csrf_request_with_db() request._user = avatar request.user = avatar request.context = avatar.companies[0] response = company_index(request) assert avatar.companies[0].name == response['company'].name
def test_gen_cancelinvoice_payment(self): user = User.query().first() project = Project.query().first() inv = self.getOne() inv.project = project inv.owner = user inv.statusPersonAccount = user inv.record_payment(mode="c", amount=1500) cinv = inv.gen_cancelinvoice(user) self.assertEqual(len(cinv.lines), len(inv.lines) + len(inv.discounts) + 1) self.assertEqual(cinv.lines[-1].cost, 1500)
def add_admin(arguments, env): """ Add an admin user to the database """ login = get_value(arguments, 'user', 'admin.majerti') password = get_value(arguments, 'pwd', get_pwd()) firstname = get_value(arguments, 'firstname', 'Admin') lastname = get_value(arguments, 'lastname', 'Majerti') email = get_value(arguments, 'email', '*****@*****.**') user = User( login=login, firstname=firstname, primary_group=1, #is an admin lastname=lastname, email=email) user.set_password(password) db = DBSESSION() db.add(user) db.flush() print u"Creating account %s with password %s" % (login, unicode(password)) return user
def add_admin(arguments, env): """ Add an admin user to the database """ login = get_value(arguments, 'user', 'admin.majerti') password = get_value(arguments, 'pwd', get_pwd()) firstname = get_value(arguments, 'firstname', 'Admin') lastname = get_value(arguments, 'lastname', 'Majerti') email = get_value(arguments, 'email', '*****@*****.**') user = User(login=login, firstname=firstname, primary_group=1, #is an admin lastname=lastname, email=email ) user.set_password(password) db = DBSESSION() db.add(user) db.flush() print u"Creating account %s with password %s" % (login, unicode(password)) return user
def auth(form, value): """ Check the login/password content """ log.debug(u" * Authenticating") login = value.get('login') log.debug(u" + Login {0}".format(login)) password = value.get('password') result = User.query().filter_by(login=login).first() if not result or not result.auth(password): log.debug(u" - Authentication Error") message = u"Erreur d'authentification" exc = colander.Invalid(form, message) exc['password'] = message raise exc
def upgrade(): logger = logging.getLogger("alembic.migrate_code_compta") op.add_column("company", sa.Column("code_compta", sa.String(30), default=0)) dbsession = DBSESSION() for user in User.query(): code_compta = user.code_compta companies = user.companies if code_compta not in [u"0", None, u""]: if len(companies) == 1: company = companies[0] company.code_compta = code_compta dbsession.merge(company) else: logger.warn(u"User {0} has a code_compta and multiple \ companies".format(user.id))
def test_gen_cancelinvoice(dbsession, invoice): user = User.query().first() project = Project.query().first() invoice.project = project invoice.owner = user invoice.statusPersonAccount = user dbsession.add(invoice) dbsession.flush() cinv = invoice.gen_cancelinvoice(user) dbsession.add(cinv) dbsession.flush() assert cinv.name == "Avoir 1" assert cinv.total_ht() == -1 * invoice.total_ht() today = datetime.date.today() assert cinv.taskDate == today
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ user_id = appstruct.get('user_id') company = Company() company = merge_session_with_post(company, appstruct) if user_id is not None: user_account = User.get(user_id) if user_account is not None: company.employees.append(user_account) self.dbsession.add(company) self.dbsession.flush() message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name) self.session.flash(message) return HTTPFound(self.request.route_path("company", id=company.id))
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ user_id = appstruct.get('user_id') company = Company() company.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(company, appstruct) if user_id is not None: user_account = User.get(user_id) if user_account is not None: company.employees.append(user_account) self.dbsession.add(company) self.dbsession.flush() message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name) self.session.flash(message) return HTTPFound(self.request.route_path("company", id=company.id))
def test_gen_cancelinvoice(self): user = User.query().first() project = Project.query().first() inv = self.getOne() inv.project = project inv.owner = user inv.statusPersonAccount = user self.session.add(inv) self.session.flush() cinv = inv.gen_cancelinvoice(user) self.session.add(cinv) self.session.flush() self.assertEqual(cinv.name, "Avoir 1") self.assertEqual(cinv.total_ht(), -1 * inv.total_ht()) today = datetime.date.today() self.assertEqual(cinv.taskDate, today)
def company_remove_employee_view(context, request): """ Enlève un employé de l'entreprise courante """ uid = request.params.get("uid") if not uid: request.session.flash("Missing uid parameter", "error") user = User.get(uid) if not user: request.session.flash("User not found", "error") if user in context.employees: context.employees = [employee for employee in context.employees if employee != user] request.session.flash( u"L'utilisateur {0} ne fait plus partie de l'entreprise {1}".format(format_account(user), context.name) ) url = request.referer if url is None: url = request.route_path("company", id=context.id) return HTTPFound(url)
def company_remove_employee_view(context, request): """ Enlève un employé de l'entreprise courante """ uid = request.params.get('uid') if not uid: request.session.flash('Missing uid parameter', 'error') user = User.get(uid) if not user: request.session.flash('User not found', 'error') if user in context.employees: context.employees = [ employee for employee in context.employees if employee != user ] request.session.flash( u"L'utilisateur {0} ne fait plus partie de l'entreprise {1}". format(format_account(user), context.name)) url = request.referer if url is None: url = request.route_path('company', id=context.id) return HTTPFound(url)
def test_unique_login(user): assert User.unique_login("test_forms_user") == False assert User.unique_login("Test_forms_user") == True
def user(content): return User.query().first()
def test_get_company(self): user1 = User.get(3) cid = 1 company = user1.get_company(cid) self.assertEqual(company.name, u'Laveur de K-ro') self.assertRaises(KeyError, user1.get_company, 3000)
def test_unique_login(user): assert User.unique_login("test_forms_user") == False User.unique_login("nutt", "other unused login")
def getone(): return User.query().filter(User.login == APPSTRUCT['login']).first()
def query(self): """ Return the main query for our list view """ return User.query(ordered=False, only_active=False)\ .outerjoin(User.companies)
def user(self): return User.query().first()
def get_user(datas=USER): user = User(**datas) return user
def getone(): return User.query().filter(User.login==APPSTRUCT['login']).first()
def getone(self): return User.query().filter(User.login==USER['login']).first()