Example #1
0
    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)
Example #2
0
    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)
Example #3
0
 def test_adding_two_ints(self):
     combined = utils.add_prices(1, 1)
     assert combined == 2
Example #4
0
 def test_adding_two_decimals(self):
     combined = utils.add_prices(Decimal('1.0'), Decimal('1.0'))
     assert combined == Decimal('2.0')
Example #5
0
 def test_invalid_string_price(self):
     with pytest.raises(decimal.InvalidOperation):
         utils.add_prices('not a price', 5)
Example #6
0
 def test_zero_arguments(self):
     with pytest.raises(TypeError):
         utils.add_prices()
Example #7
0
 def test_adding_a_float_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(1.0, None)
Example #8
0
 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_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(1.0, None)
 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_three_floats(self):
     combined = utils.add_prices(1.0, 1.0, 1.0)
     assert combined == 3.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_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')
Example #16
0
 def test_adding_two_strs(self):
     combined = utils.add_prices('1.0', '1.0')
     assert combined == '2.0'
Example #17
0
 def test_adding_inexact_floats(self):
     combined = utils.add_prices(1.1, 2.2)
     assert combined == 3.3
 def test_adding_a_decimal_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(Decimal('1.0'), None)
Example #19
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_zero_arguments(self):
     with pytest.raises(TypeError):
         utils.add_prices()
Example #21
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)
Example #23
0
 def test_one_argument(self):
     with pytest.raises(TypeError):
         utils.add_prices(1)
 def test_invalid_string_price(self):
     with pytest.raises(decimal.InvalidOperation):
         utils.add_prices('not a price', 5)
Example #25
0
 def total_including_send_cost(self):
     return utils.add_prices(self.total_seatprice, self.total_surcharge,
                             self.send_method.cost)
Example #26
0
 def total_including_send_cost(self):
     return utils.add_prices(
         self.total_seatprice, self.total_surcharge, self.send_method.cost
     )