示例#1
0
def delete(id):
    user = User.get(id)
    user.delete()

    return redirect(
        url_for('user.users')
    )
示例#2
0
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()
示例#4
0
    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)
示例#5
0
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)
示例#6
0
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
    )
示例#7
0
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
    )
示例#8
0
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
示例#10
0
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)
示例#11
0
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
    )
示例#12
0
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
    )
示例#13
0
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
    )
示例#14
0
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
    )
示例#15
0
 def setUp(self):
     UserTest.setUp(self)
     self.user2 = User(username="******", password="******")
     self.user2.add()
示例#16
0
    def test_should_add_user(self):
        user = User(username="******", password="******")
        user.add()

        self.assertIn(user, self.db.session)
示例#17
0
    def test_should_return_list_of_all_users(self):
        users = User.get_all()

        self.assertEqual(users, [self.user, self.user2])
示例#18
0
    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)
示例#20
0
    def test_should_return_error_given_repeated_username(self):
        user = User(username="******", password="******")
        error = user.validation.validate_unique_values()

        self.assertNotEqual(error, None)
示例#21
0
    def test_should_return_none_given_invalid_id(self):
        user = User.get(2)

        self.assertEqual(user, None)
示例#22
0
    def test_should_return_permission_given_valid_username(self):
        user = User.search("Test User")

        self.assertEqual(user, self.user)
示例#23
0
 def setUp(self):
     Test.setUp(self)
     self.user = User(username="******", password="******")
     self.user.add()
     self.view = View(view_name="Test View")
     self.view.add()
示例#24
0
    def test_should_return_none_given_invalid_username(self):
        user = User.search("Non existent name")

        self.assertEqual(user, None)
示例#25
0
    def test_should_not_return_error_given_unique_username(self):
        user = User(username="******", password="******")
        error = user.validation.validate_unique_values()

        self.assertEqual(error, None)
示例#26
0
    def test_should_return_user_given_valid_id(self):
        user = User.get(1)

        self.assertEqual(user, self.user)
示例#27
0
class HomeTest(Test):
    def setUp(self):
        Test.setUp(self)
        self.user = User(username="******", password="******")
        self.user.add()
示例#28
0
    def test_should_return_error_given_invalid_user(self):
        user = User(username="******", password="")
        error = user.validation.validate()

        self.assertNotEqual(error, None)
示例#29
0
 def setUp(self):
     Test.setUp(self)
     self.user = User(username="******", password="******")
     self.user.add()
示例#30
0
    def test_should_return_error_given_empty_values(self):
        user = User(username="", password="")
        error = user.validation.validate_empty_values()

        self.assertNotEqual(error, None)