コード例 #1
0
ファイル: mixins.py プロジェクト: shubh234/pyticketswitch
    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)
コード例 #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)
コード例 #3
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_two_ints(self):
     combined = utils.add_prices(1, 1)
     assert combined == 2
コード例 #4
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_two_decimals(self):
     combined = utils.add_prices(Decimal('1.0'), Decimal('1.0'))
     assert combined == Decimal('2.0')
コード例 #5
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_invalid_string_price(self):
     with pytest.raises(decimal.InvalidOperation):
         utils.add_prices('not a price', 5)
コード例 #6
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_zero_arguments(self):
     with pytest.raises(TypeError):
         utils.add_prices()
コード例 #7
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_a_float_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(1.0, None)
コード例 #8
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_three_floats(self):
     combined = utils.add_prices(1.0, 1.0, 1.0)
     assert combined == 3.0
コード例 #9
0
 def test_adding_a_float_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(1.0, None)
コード例 #10
0
 def test_adding_a_float_and_a_decimal(self):
     combined = utils.add_prices(1.0, Decimal('1.0'))
     assert combined == Decimal('2.0')
コード例 #11
0
 def test_adding_three_floats(self):
     combined = utils.add_prices(1.0, 1.0, 1.0)
     assert combined == 3.0
コード例 #12
0
 def test_adding_inexact_floats(self):
     combined = utils.add_prices(1.1, 2.2)
     assert combined == 3.3
コード例 #13
0
 def test_adding_two_strs(self):
     combined = utils.add_prices('1.0', '1.0')
     assert combined == '2.0'
コード例 #14
0
 def test_adding_two_ints(self):
     combined = utils.add_prices(1, 1)
     assert combined == 2
コード例 #15
0
 def test_adding_two_decimals(self):
     combined = utils.add_prices(Decimal('1.0'), Decimal('1.0'))
     assert combined == Decimal('2.0')
コード例 #16
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_two_strs(self):
     combined = utils.add_prices('1.0', '1.0')
     assert combined == '2.0'
コード例 #17
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_inexact_floats(self):
     combined = utils.add_prices(1.1, 2.2)
     assert combined == 3.3
コード例 #18
0
 def test_adding_a_decimal_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(Decimal('1.0'), None)
コード例 #19
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_a_float_and_a_decimal(self):
     combined = utils.add_prices(1.0, Decimal('1.0'))
     assert combined == Decimal('2.0')
コード例 #20
0
 def test_zero_arguments(self):
     with pytest.raises(TypeError):
         utils.add_prices()
コード例 #21
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_adding_a_decimal_to_none(self):
     with pytest.raises(TypeError):
         utils.add_prices(Decimal('1.0'), None)
コード例 #22
0
 def test_one_argument(self):
     with pytest.raises(TypeError):
         utils.add_prices(1)
コード例 #23
0
ファイル: test_utils.py プロジェクト: shubh234/pyticketswitch
 def test_one_argument(self):
     with pytest.raises(TypeError):
         utils.add_prices(1)
コード例 #24
0
 def test_invalid_string_price(self):
     with pytest.raises(decimal.InvalidOperation):
         utils.add_prices('not a price', 5)
コード例 #25
0
ファイル: order.py プロジェクト: shubh234/pyticketswitch
 def total_including_send_cost(self):
     return utils.add_prices(self.total_seatprice, self.total_surcharge,
                             self.send_method.cost)
コード例 #26
0
 def total_including_send_cost(self):
     return utils.add_prices(
         self.total_seatprice, self.total_surcharge, self.send_method.cost
     )