def dateRange(self): if ProductType.is_thing(self.type) or not self.stocks: return DateTimes() start = min([stock.beginningDatetime for stock in self.stocks]) end = max([stock.endDatetime for stock in self.stocks]) return DateTimes(start, end)
def test_is_empty_if_event_has_no_event_occurrences(self): # given offer = create_offer_with_event_product() offer.stocks = [] # then assert offer.dateRange == DateTimes()
def test_is_empty_if_offer_is_on_a_thing(self): # given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_thing_product(venue) # then assert offer.dateRange == DateTimes()
def test_date_range_is_empty_if_event_has_no_stocks(): # given offer = Offer() offer.product = create_product_with_event_type() offer.stocks = [] # then assert offer.dateRange == DateTimes()
def test_date_range_is_empty_if_offer_is_on_a_thing(): # given offer = Offer() offer.product = create_product_with_thing_type() offer.stocks = [] # then assert offer.dateRange == DateTimes()
def test_matches_the_occurrence_if_only_one_occurrence(self): # given offer = create_offer_with_event_product() offer.stocks = [ create_stock(offer, beginning_datetime=two_days_ago, end_datetime=five_days_from_now) ] # then assert offer.dateRange == DateTimes(two_days_ago, five_days_from_now)
def test_starts_at_first_beginning_date_time_and_ends_at_last_end_date_time( self): # given offer = create_offer_with_event_product() offer.stocks = [ create_stock(offer, beginning_datetime=two_days_ago, end_datetime=five_days_from_now), create_stock(offer, beginning_datetime=four_days_ago, end_datetime=five_days_from_now), create_stock(offer, beginning_datetime=four_days_ago, end_datetime=ten_days_from_now), create_stock(offer, beginning_datetime=two_days_ago, end_datetime=ten_days_from_now) ] # then assert offer.dateRange == DateTimes(four_days_ago, ten_days_from_now) assert offer.dateRange.datetimes == [four_days_ago, ten_days_from_now]