Ejemplo n.º 1
0
 def test_run_calculate_cost_total(self):
     # Set up cafe with menu
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     price1 = Price(cafe.id, "S")
     price1.amount = 1.4
     price1.cafe = cafe
     price2 = Price(cafe.id, "M")
     price2.amount = 2.5
     price2.cafe = cafe
     db.session.add(price1)
     db.session.add(price2)
     db.session.commit()
     # Create run and add some coffees
     run = Run(datetime.utcnow())
     db.session.add(run)
     db.session.commit()
     coffee1 = Coffee("Latte")
     coffee1.price = price1
     coffee1.run = run
     coffee2 = Coffee("Cappuccino")
     coffee2.price = price2
     coffee2.run = run
     coffee3 = Coffee("Mocha")
     coffee3.price = price1
     coffee3.run = run
     coffee3.paid = True
     db.session.add(coffee1)
     db.session.add(coffee2)
     db.session.add(coffee3)
     db.session.commit()
     # Calculate total price of run
     total = run.calculateTotalRunCost()
     assert total == 3.9
Ejemplo n.º 2
0
 def test_user_owes_money_to_person(self):
     # Set up cafe with menu
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     price1 = Price(cafe.id, "S")
     price1.amount = 1.4
     price1.cafe = cafe
     price2 = Price(cafe.id, "M")
     price2.amount = 2.5
     price2.cafe = cafe
     db.session.add(price1)
     db.session.add(price2)
     db.session.commit()
     # Create run and add some coffees
     run = Run(datetime.utcnow())
     user1 = User()
     user2 = User()
     run.fetcher = user2
     db.session.add(user1)
     db.session.add(user2)
     db.session.add(run)
     db.session.commit()
     coffee1 = Coffee("Latte")
     coffee1.price = price1
     coffee1.run = run
     coffee2 = Coffee("Cappuccino")
     coffee2.price = price2
     coffee2.run = run
     coffee2.addict = user1
     coffee3 = Coffee("Mocha")
     coffee3.price = price1
     coffee3.run = run
     coffee3.paid = True
     coffee3.addict = user1
     db.session.add(coffee1)
     db.session.add(coffee2)
     db.session.add(coffee3)
     db.session.commit()
     amount = user1.moneyOwedPerson(user2)
     assert amount == 2.5