def non_offer_combined_price(self): """Returns the combined non offer seatprice and surcharge. This method assumes that we have both a seatprice and surcharge. In the situation where are missing either a seatprice or a surcharge then we don't have all the information to be able provide this information. Returns: float: the combined seatprice and surcharge Raises: AssertionError: It might seem like the obvious thing to do would be to assume the missing data was in fact zero and simply allow the addition to continue. However that would be somewhat dangerous when we are talking about prices, and it's better to actually raise an exception to indicate that there was a problem with the objects data, than to inform a customer that the tickets are free or have no booking fees """ assert self.non_offer_seatprice is not None, 'non_offer_seatprice data missing' assert self.non_offer_surcharge is not None, 'non_offer_surcharge data missing' return utils.add_prices(self.non_offer_seatprice, self.non_offer_surcharge)
def combined_price(self): """Returns the combined seatprice and surcharge. This method assumes that we have both a seatprice and surcharge. In the situation where are missing either a seatprice or a surcharge then we don't have all the information to be able provide this information. Returns: float: the combined seatprice and surcharge Raises: AssertionError: It might seem like the obvious thing to do would be to assume the missing data was in fact zero and simply allow the addition to continue. However that would be somewhat dangerous when we are talking about prices, and it's better to actually raise an exception to indicate that there was a problem with the objects data, than to inform a customer that the tickets are free or have no booking fees """ assert self.seatprice is not None, 'seatprice data missing' assert self.surcharge is not None, 'surcharge data missing' return utils.add_prices(self.seatprice, self.surcharge)
def test_adding_two_ints(self): combined = utils.add_prices(1, 1) assert combined == 2
def test_adding_two_decimals(self): combined = utils.add_prices(Decimal('1.0'), Decimal('1.0')) assert combined == Decimal('2.0')
def test_invalid_string_price(self): with pytest.raises(decimal.InvalidOperation): utils.add_prices('not a price', 5)
def test_zero_arguments(self): with pytest.raises(TypeError): utils.add_prices()
def test_adding_a_float_to_none(self): with pytest.raises(TypeError): utils.add_prices(1.0, None)
def test_adding_three_floats(self): combined = utils.add_prices(1.0, 1.0, 1.0) assert combined == 3.0
def test_adding_a_float_and_a_decimal(self): combined = utils.add_prices(1.0, Decimal('1.0')) assert combined == Decimal('2.0')
def test_adding_inexact_floats(self): combined = utils.add_prices(1.1, 2.2) assert combined == 3.3
def test_adding_two_strs(self): combined = utils.add_prices('1.0', '1.0') assert combined == '2.0'
def test_adding_a_decimal_to_none(self): with pytest.raises(TypeError): utils.add_prices(Decimal('1.0'), None)
def test_one_argument(self): with pytest.raises(TypeError): utils.add_prices(1)
def total_including_send_cost(self): return utils.add_prices(self.total_seatprice, self.total_surcharge, self.send_method.cost)
def total_including_send_cost(self): return utils.add_prices( self.total_seatprice, self.total_surcharge, self.send_method.cost )