Example #1
0
def monkeys():
    form = forms.MonkeyForm(request.form)
    if request.method == 'POST' and form.validate():
        user = models.User(form.name.data, form.email.data, form.age.data)
        db_session.add(user)
        db_session.commit()
        flash("New monkey added")
        return redirect(url_for(".monkeys"))
    monkeys = models.query_users(order=request.args.get('ord'))
    return render_template(
        'monkeys.html', monkeys=monkeys.all(), form=form,
        order=request.args.get('ord'))
Example #2
0
def edit_monkey(ident):
    try:
        monkey = models.User.query.filter_by(id=ident).one()
    except:
        return redirect(404)
    form = forms.MonkeyForm(request.form, obj=monkey)
    if request.method == 'POST' and form.validate():
        form.populate_obj(monkey)
        db_session.commit()
        flash("Monkey updated")
        return redirect(url_for(".view_monkey", ident=ident))
    return render_template('edit_monkey.html', monkey=monkey, form=form)
Example #3
0
def remove_monkey(ident):
    try:
        monkey = models.User.query.filter_by(id=ident).one()
    except:
        return redirect(404)
    form = forms.RemoveForm(request.form)
    if request.method == 'POST' and form.validate():
        db_session.delete(monkey)
        db_session.commit()
        flash("Monkey removed")
        return redirect(url_for(".monkeys"))
    return render_template('remove_monkey.html', monkey=monkey, form=form)
Example #4
0
 def test_remove_friend(self):
     users = User.query.all()
     users[0].add_friend(users[1])
     users[0].add_friend(users[2])
     users[0].add_friend(users[3])
     db_session.commit()
     rw = self.client.get("/remove_friend/%i/%i" % (users[0].id, users[1].id))
     assert "Sure to remove friendship" in rw.data
     assert users[0].name in rw.data
     assert users[1].name in rw.data
     rw = self.client.post("/remove_friend/%i/%i" % (users[0].id, users[1].id), follow_redirects=True)
     assert "Friendship removed" in rw.data
     rw = self.client.post("/remove_friend/%i/%i" % (users[0].id, users[4].id), follow_redirects=True)
     assert "Couldnt remove friendship" in rw.data
Example #5
0
 def test_best_friend_circular_conflict(self):
     db_session.add(User("Test1", "*****@*****.**", 20))
     db_session.add(User("Test2", "*****@*****.**", 20))
     db_session.commit()
     # users = User.query.all()
     User.query.filter_by(name="Test1").one().add_friend(User.query.filter_by(name="Test2").one())
     db_session.commit()
     User.query.filter_by(name="Test1").one().make_best_friend(User.query.filter_by(name="Test2").one())
     db_session.commit()
     User.query.filter_by(name="Test2").one().make_best_friend(User.query.filter_by(name="Test1").one())
     db_session.commit()
     User.query.filter_by(name="Test1").one().remove_friend(User.query.filter_by(name="Test2").one())
     db_session.commit()
     user = User.query.filter_by(name="Test1").one()
     assert user.best_friend is None
Example #6
0
 def test_best_friend(self):
     db_session.add(User("Test1", "*****@*****.**", 20))
     db_session.add(User("Test2", "*****@*****.**", 20))
     db_session.commit()
     users = User.query.all()
     User.query.filter_by(name="Test1").one().add_friend(User.query.filter_by(name="Test2").one())
     db_session.commit()
     users = User.query.all()
     User.query.filter_by(name="Test1").one().make_best_friend(User.query.filter_by(name="Test2").one())
     db_session.commit()
     users = User.query.all()
     assert User.query.filter_by(name="Test2").one().best_friend is None
     assert User.query.filter_by(name="Test1").one().best_friend == User.query.filter_by(name="Test2").one()
     users[0].remove_friend(users[1])
     db_session.commit()
     users = User.query.all()
     assert users[0].best_friend is None
     users = User.query.all()
Example #7
0
 def test_friendship(self):
     db_session.add(User("Test1", "*****@*****.**", 20))
     db_session.add(User("Test2", "*****@*****.**", 20))
     db_session.commit()
     users = User.query.all()
     users[0].add_friend(users[1])
     db_session.commit()
     users = User.query.all()
     assert users[0].friends.count() == 1
     assert users[1].friends.count() == 1
     users[0].remove_friend(users[1])
     db_session.commit()
     assert users[0].friends.count() == 0
     assert users[1].friends.count() == 0
Example #8
0
def shutdown_session(exception=None):
    db_session.commit()
    db_session.remove()
Example #9
0
 def test_add_monkeys(self):
     db_session.add(User("Test1", "*****@*****.**", 20))
     db_session.add(User("Test2", "*****@*****.**", 20))
     db_session.commit()
     u = monkeyapp.models.User.query.all()
     assert len(u) == 2
Example #10
0
 def setup(self):
     super(TestOrder, self).setup()
     self.ways = ["name", "age", "email", "bf", "friends"]
     self.l = []
     db_session.add(User("a", "*****@*****.**", 20))
     db_session.commit()
     db_session.add(User("b", "*****@*****.**", 25))
     db_session.commit()
     db_session.add(User("c", "*****@*****.**", 23))
     db_session.commit()
     db_session.add(User("d", "*****@*****.**", 30))
     db_session.commit()
     db_session.add(User("e", "*****@*****.**", 10))
     db_session.commit()
     monkeys = User.query.all()
     monkeys[0].add_friend(monkeys[1])
     monkeys[0].add_friend(monkeys[4])
     db_session.commit()
     monkeys[0].make_best_friend(monkeys[4])
     db_session.commit()
     monkeys[4].make_best_friend(monkeys[0])
     db_session.commit()
     monkeys[2].add_friend(monkeys[1])
     monkeys[3].add_friend(monkeys[1])
     monkeys[4].add_friend(monkeys[1])
     db_session.commit()
Example #11
0
 def setup(self):
     super(TestRequestsOccupied, self).setup()
     for i in range(20):
         db_session.add(User("Test%i" % i, "*****@*****.**" % i, 20))
     db_session.commit()