Ejemplo n.º 1
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()
Ejemplo n.º 2
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'))
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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()
Ejemplo n.º 6
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
Ejemplo n.º 7
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()