def test_different_dates(self, first, second):
        """
        current: --1-1-2-2--
        given:   ----3-3-3--
        """
        # Given
        new_price = dataclasses.replace(first,
                                        id=None,
                                        start=first.start + timedelta(days=1),
                                        end=second.end,
                                        price=333)
        current_prices = [first, second]

        # When
        operations = PriceRangeOperations.execute(new_price, current_prices)

        # Then
        to_create = [
            new_price,
            dataclasses.replace(first, id=None, end=new_price.start)
        ]

        assert sorted(operations.to_create) == sorted(to_create)
        assert operations.to_modify is None
        assert operations.to_delete == current_prices
    def test_process_different_price_and_dates_three_ranges(
            self, first, second, third):  # noqa
        """
        current: --1-1-2-2-3-3
        given:   ----4-4-4-4--
        """
        # Given
        new_price = dataclasses.replace(first,
                                        id=None,
                                        price=999,
                                        start=first.start + timedelta(days=1),
                                        end=third.end - timedelta(days=1))
        current_prices = [first, second, third]

        # When
        operations = PriceRangeOperations.execute(new_price, current_prices)

        # Then
        to_create = sorted([
            new_price,
            dataclasses.replace(first, id=None, end=new_price.start),
            dataclasses.replace(third, id=None, start=new_price.end),
        ])

        assert sorted(operations.to_create) == to_create
        assert operations.to_modify is None
        assert operations.to_delete == current_prices
Example #3
0
    def test_process_different_price_and_dates(self, price):
        """
        current: --1-1-1-1--
        given:   ----2-2----
        """
        # Given
        new_price = dataclasses.replace(price,
                                        id=None,
                                        price=999,
                                        start=price.start + timedelta(days=1),
                                        end=price.end - timedelta(days=1))
        current_prices = [price]

        # When
        operations = PriceRangeOperations.execute(new_price, current_prices)

        # Then
        to_create = sorted([
            new_price,
            dataclasses.replace(price, id=None, end=new_price.start),
            dataclasses.replace(price, id=None, start=new_price.end),
        ])

        assert sorted(operations.to_create) == to_create
        assert operations.to_modify is None
        assert operations.to_delete == [price]
Example #4
0
    def test_no_intersected_ranges(self, price):
        current_prices = []
        operations = PriceRangeOperations.execute(price, current_prices)
        to_create = [price]

        assert operations.to_create == to_create
        assert operations.to_modify is None
        assert operations.to_delete is None
Example #5
0
    def test_process_same_price_and_dates(self, price):
        """
        current: --1-1-1-1--
        given:   --1-1-1-1--
        """
        # Given
        existed_price = dataclasses.replace(price, id=123)
        current_prices = [existed_price]

        # When
        operations = PriceRangeOperations.execute(price, current_prices)

        # Then
        assert operations.to_create is None
        assert operations.to_modify is None
        assert operations.to_delete is None
Example #6
0
    def test_process_same_dates_but_different_price(self, price):
        """
        current: --1-1-1-1--
        given:   --2-2-2-2--
        """
        # Given
        existed_price = dataclasses.replace(price, price=999)
        current_prices = [existed_price]

        # When
        operations = PriceRangeOperations.execute(price, current_prices)
        to_modify = [price]

        # Then
        assert operations.to_create is None
        assert operations.to_modify == to_modify
        assert operations.to_delete is None
Example #7
0
    def test_process_same_price_but_different_dates(self, price):
        """
        current: --1-1-1-1--
        given:   ----1-1----
        """
        # Given
        new_price = dataclasses.replace(price,
                                        id=None,
                                        start=price.start + timedelta(days=1),
                                        end=price.end - timedelta(days=1))
        current_prices = [price]

        # When
        operations = PriceRangeOperations.execute(new_price, current_prices)

        # Then
        assert operations.to_create is None
        assert operations.to_modify is None
        assert operations.to_delete is None
    def test_same_dates(self, first, second):
        u"""
        current: --1-1-2-2--
        given:   --3-3-3-3--
        """
        # Given
        new_price = dataclasses.replace(first,
                                        id=None,
                                        start=first.start,
                                        end=second.end,
                                        price=333)
        current_prices = [first, second]

        # When
        operations = PriceRangeOperations.execute(new_price, current_prices)

        # Then
        to_create = [new_price]

        assert operations.to_create == to_create
        assert operations.to_modify is None
        assert operations.to_delete == current_prices