def delete(id): user = User.get(id) user.delete() return redirect( url_for('user.users') )
class OrderTest(Test): 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 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 test_should_not_register_user_given_invalid_username_and_LUHP(self): self.login_user(self.admin_user) user_credentials = dict(username="******", password="", password_confirm="", salary=1000) with self.client as client: client.post(url_for('user.register'), data=user_credentials) self.assertEqual(User.search('Test'), None)
def load_loged_in_user(): try: user_id = session["user_id"] except KeyError: user_id = None if user_id is None: g.user = None else: g.user = User.get(user_id)
def main_page(): users = User.get_all() views = View.get_all() if request.method == "POST": search_term = request.form['search_term'] user = User.search(search_term) if user: return redirect( url_for('user.update', id=user.id) ) view = View.search(search_term) if view: return redirect( url_for('view.update', id=view.id) ) return render_template( "admin/main-page.html", user_heads=username_head, users=users, views=views )
def users(): users = User.query.all() if request.method == "POST": user = User.search(request.form['search_term']) if user: return redirect( url_for('user.profile', id=user.id) ) return render_template( "user/users.html", user_heads=username_head, users=users )
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 get_autocomplete_data(group, attribute): groups = dict( users=User.get_all(), products=Product.get_all(), customers = Customer.get_all(), expenses=Expense.get_all(), warehouses=Warehouse.get_all() ) data = [] for obj in groups[group]: value = getattr(obj, attribute) if value not in set(data): data.append(value) return data
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 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 update(id): user = User.get(id) user_heads = dict( username_head, salary="Salario" ) if request.method == "POST": user.username = request.form["username"] user.salary = request.form['salary'] checked_permissions = get_checked_permissions() user.update_permissions(checked_permissions) error = user.request.update() if not error: return redirect( url_for('user.users') ) flash(error) return render_template( "user/update.html", user_heads=user_heads, user=user )
def update_password(id): user = User.get(id) if request.method == "POST": password = request.form["password"] password_confirm = request.form["password_confirm"] if password != password_confirm: error = "Las contraseñas no coinciden" else: user.password = password error = user.validation.validate() if not error: from werkzeug.security import generate_password_hash user.password = generate_password_hash(user.password) user.update() return redirect( url_for('user.update', id=id) ) flash(error) return render_template( 'user/auth/update-password.html', password_heads=password_heads, user=user )
def search_bar(): search_term = request.form['search_term'] try: customer = Customer.search_all(search_term)[0] except IndexError: customer = None if customer: return redirect( url_for("customer.update", id=customer.id) ) user = User.search(search_term) if user: return redirect( url_for("user.profile", id=user.id) ) product = Product.search(search_term) if product: return redirect( url_for("product.update", id=product.id) ) return redirect( request.referrer )
def setUp(self): UserTest.setUp(self) self.user2 = User(username="******", password="******") self.user2.add()
def test_should_add_user(self): user = User(username="******", password="******") user.add() self.assertIn(user, self.db.session)
def test_should_return_list_of_all_users(self): users = User.get_all() self.assertEqual(users, [self.user, self.user2])
def test_should_not_return_error_given_valid_user(self): user = User(username="******", password="******") error = user.validation.validate() self.assertEqual(error, None)
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_return_error_given_repeated_username(self): user = User(username="******", password="******") error = user.validation.validate_unique_values() self.assertNotEqual(error, None)
def test_should_return_none_given_invalid_id(self): user = User.get(2) self.assertEqual(user, None)
def test_should_return_permission_given_valid_username(self): user = User.search("Test User") self.assertEqual(user, self.user)
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_return_none_given_invalid_username(self): user = User.search("Non existent name") self.assertEqual(user, 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_user_given_valid_id(self): user = User.get(1) self.assertEqual(user, self.user)
class HomeTest(Test): def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add()
def test_should_return_error_given_invalid_user(self): user = User(username="******", password="") error = user.validation.validate() self.assertNotEqual(error, None)
def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add()
def test_should_return_error_given_empty_values(self): user = User(username="", password="") error = user.validation.validate_empty_values() self.assertNotEqual(error, None)