def test_add_get_delete(self): us = UserService() user1 = User("Test User", Americano()) user2 = User("Tess User", Americano()) us.add(user1) us.add(user2) self.assertEqual(user1, us.get_with_uid(user1.uid)) self.assertEqual(user2, us.get_with_uid(user2.uid)) us.delete(user2) self.assertEqual(None, us.get_with_uid(user2.uid))
class UserManager(): def __init__(self, DAO): self.user = User(DAO.db.user) self.book = DAO.db.book self.dao = self.user.dao def list(self): user_list = self.dao.list() return user_list def signin(self, email, password): user = self.dao.getByEmail(email) if user is None: return False user_pass = user[2] # user pass at if user_pass != password: return False return user def signout(self): self.user.signout() def get(self, id): user = self.dao.getById(id) return user def signup(self, name, email, password): user = self.dao.getByEmail(email) if user is not None: return "already_exists" user_info = {"name": name, "email": email, "password": password} new_user = self.dao.add(user_info) return new_user def get(self, id): user = self.dao.getById(id) return user def getBooksList(self, id): return self.book.getBooksByUser(id)
def from_db(db_response: iter): rounds = dict() for row in db_response: user = User(row.person_first_name, row.person_last_name, uid=row.person_id) order = RoundOrder() order.add_item(row.drink_id) if row.round_id not in rounds.keys(): initiator = User(row.initiator_first_name, row.initiator_last_name, uid=row.initiator_id) rounds[row.round_id] = Round(initiator, id=row.round_id, active=(row.round_active == 1)) if user.first_name is not None: rounds[row.round_id].add(user, order) return list(rounds.values())
def people(): print(request.endpoint) if request.method == "GET": return render_template("app/people.html", people=UserService().get_all(), drinks=DrinkService().get_all()) elif request.method == "POST": first_name = request.json["personFirstName"] last_name = request.json["personLastName"] new_user = User(first_name, last_name) UserService().add(new_user) return jsonify({"status": "ok"})
def test_change_name(self): us = UserService() initial_name = "Old Name" user = User(initial_name, Americano()) uid = user.uid us.add(user) new_name = "New Name" us.change_name(user.uid, new_name) self.assertEqual(us.get_with_uid(uid).name, new_name)
def test_change_drink(self): us = UserService() initial_drink = Americano() user = User("Test User", initial_drink) uid = user.uid us.add(user) new_drink = Espresso() us.change_drink(uid, new_drink) self.assertEqual(new_drink, us.get_with_uid(uid).fav_drink)
def __init__(self, DAO): self.user = User(DAO.db.user) self.book = DAO.db.book self.dao = self.user.dao
def from_db(db_row): drink = Drink(db_row.drink_name, 0) if db_row.drink_name is not None else None return User(db_row.first_name, db_row.last_name, drink, db_row.id)
def test_init(self): name = "Test Name" test_user = User(name, TestUser.drink) self.assertEqual(test_user.name, name) self.assertEqual(test_user.fav_drink, TestUser.drink)