def test_chunked_dates_offset_1(self): """Assert that dates are correctly chunked when start date is DEFAULT_CHUNK_SIZE + 1 days prior. """ chunk_size = DEFAULT_CHUNK_SIZE + 1 start_date = self.todays_date - datetime.timedelta(days=chunk_size) date_chunks = chunked_dates(start_date) chunk_1, chunk_2 = date_chunks # Assert that there are two chunks self.assertEquals(len(date_chunks), 2) # Assert that the first chunk has two dates separated by # DEFAULT_CHUNK_SIZE number of days num_days = (chunk_1[1] - chunk_1[0]).days self.assertEquals(num_days, DEFAULT_CHUNK_SIZE) # Assert that the second chunk is a tuple of a single date self.assertEquals(len(chunk_2), 1) # Assert that the second chunk end date is now self.assertEquals(chunk_2[0], self.todays_date)
def test_chunked_dates_not_offset_1(self): """Assert that dates are correctly chunked when start date is not DEFAULT_CHUNK_SIZE + 1 days prior. """ chunk_size = DEFAULT_CHUNK_SIZE + 2 start_date = self.todays_date - datetime.timedelta(days=chunk_size) date_chunks = chunked_dates(start_date) # Assert that the second chunk is a tuple of two dates self.assertEquals(len(date_chunks[1]), 2)
def test_chunked_dates_with_valid_end_date(self): """Assert that dates are correctly chunked when end_date is passed.""" start_date = self.todays_date - datetime.timedelta(days=60) end_date = self.todays_date - datetime.timedelta(days=20) date_chunks = chunked_dates(start_date, end_date) # Assert that the start date of the first chunk is start_date self.assertEquals(date_chunks[0][0], start_date) # Assert that the end date of the last chunk is end_date last_chunk = reversed(date_chunks).next() end_date = reversed(last_chunk).next() self.assertEquals(end_date, end_date)
def test_chunked_dates_with_chunk_override(self): """Assert that dates are correctly chunked when chunk is overridden.""" chunk_size = 15 num_chunks = 3 start_date = (self.todays_date - datetime.timedelta(days=chunk_size * num_chunks)) date_chunks = chunked_dates(start_date, chunk=chunk_size) # Assert that there are num_chunk number of chunked dates self.assertEquals(len(date_chunks), num_chunks) # Assert that start date is chunk_size days prior to end date start_date, end_date = date_chunks[0] self.assertEquals((end_date - start_date).days, chunk_size)