def register(): form = get_form(user_heads) if request.method == "POST": error = None if form["password"] != request.form["password_confirm"]: error = "Las contraseñas no coinciden" if not error: user = User( username=form['username'], password=form['password'], salary=form['salary'] ) error = user.request.register() if not error: checked_permissions = get_checked_permissions() user.add_permissions(checked_permissions) return redirect( url_for('user.users') ) flash(error) return render_template( "user/auth/register.html", user_heads=user_heads, password_heads=password_heads, form=form )
def setUp(self): UserTest.setUp(self) self.admin_permission = Permission(permission_name="Admin") self.admin_permission.add() self.admin_view = View(view_name="Admin View") self.admin_view.add() self.admin_view.add_permission(self.admin_permission) self.admin_user = User(username="******", password="******") self.admin_user.add() self.admin_user.add_permission(self.admin_permission) self.quality_permission = Permission(permission_name="quality") self.quality_permission.add() self.quality_view = View(view_name="Quality View") self.quality_view.add() self.quality_view.add_permission(self.quality_permission) self.normal_user = User(username="******", password="******") self.normal_user.add()
def create_admin_user(): from EnGo.models.permission import Permission from EnGo.models.user import User admin_permission = Permission(permission_name="Admin") admin_permission.add() admin_user = User(username="******", password=generate_password_hash('0000')) admin_user.add() admin_user.add_permission(admin_permission)
def create_dev_user(): from EnGo.models.permission import Permission from EnGo.models.user import User dev_permission = Permission.search("Dev") if not dev_permission: dev_permission = Permission(permission_name="Dev") dev_permission.add() dev_user = User(username="******", password=generate_password_hash('0000')) dev_user.add() dev_user.add_permission(dev_permission)
def setUp(self): Test.setUp(self) self.user = User( username="******", password="******" ) self.user.add() self.order = Order( user_id=self.user.id, title="Test Title", description="Test Description", due_date=date.today() ) self.order.add()
def login(): if g.user: return redirect( url_for('home.main_page') ) if request.method == "POST": user = User( username=request.form["username"], password=request.form["password"] ) error = user.request.login() if not error: return redirect( url_for('home.main_page') ) flash(error) return render_template( "user/auth/login.html", user_heads=user_login_heads )
def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add()
def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add() self.view = View(view_name="Test View") self.view.add()
def test_should_register_user_given_valid_user(self): user = User(username="******", password="******") user.request.register() self.assertIn(user, self.db.session)
def test_shoul_add_permission_to_user(self): user = User(username="******", password="******") user.add() user.add_permission(self.quality_permission) self.assertIn(self.quality_permission, user.permissions)
def test_should_not_return_error_given_valid_user(self): user = User(username="******", password="******") error = user.validation.validate() self.assertEqual(error, None)
def test_should_return_error_given_repeated_username(self): user = User(username="******", password="******") error = user.validation.validate_unique_values() self.assertNotEqual(error, None)
def test_should_not_return_error_given_unique_username(self): user = User(username="******", password="******") error = user.validation.validate_unique_values() self.assertEqual(error, None)
def test_should_return_error_given_empty_values(self): user = User(username="", password="") error = user.validation.validate_empty_values() self.assertNotEqual(error, None)
def test_should_return_error_given_invalid_user(self): user = User(username="******", password="") error = user.validation.validate() self.assertNotEqual(error, None)
def test_should_add_user(self): user = User(username="******", password="******") user.add() self.assertIn(user, self.db.session)
def setUp(self): UserTest.setUp(self) self.user2 = User(username="******", password="******") self.user2.add()
def test_should_not_register_user_given_invalid_user(self): user = User(username="", password="") user.request.register() self.assertNotIn(user, self.db.session)
def test_should_login_user_given_valid_credentials(self): user = User(username=self.user.username, password="******") user.request.login() self.assertEqual(session["user_id"], self.user.id)
def test_should_not_login_user_given_invalid_credentials(self): user = User(username="******", password="******") user.request.login() with self.assertRaises(KeyError): session["user_id"]