def test_datetime_one_shard(self):
        """Make sure one shard gets returned with the right start and stop."""
        from extractor.sharder import _generate_shard_ranges

        today = datetime.datetime.today()

        shard_range = (today - datetime.timedelta(days=1), today)
        shards = _generate_shard_ranges(1, 'datetime', shard_range)

        self.assertEqual([shard_range], shards)
    def test_datetime_two_shards(self):
        """Make sure two shards get returned with the right start and stop."""
        from extractor.sharder import _generate_shard_ranges

        today = datetime.datetime.today()

        shard_range = (today - datetime.timedelta(days=2), today)

        shards = _generate_shard_ranges(2, 'datetime', shard_range)

        expected_shards = [
            (today - datetime.timedelta(days=2),
             today - datetime.timedelta(days=1)),
            (today - datetime.timedelta(days=1), today)
        ]

        self.assertEqual(expected_shards, shards)
    def test_many_shards(self):
        """Make sure lots of shards get returned with the right start and stop
        values.
        """
        from extractor.sharder import _generate_shard_ranges

        today = datetime.datetime.today()

        shard_range = (today - datetime.timedelta(days=1), today)

        shards = _generate_shard_ranges(24, 'datetime', shard_range)

        expected_shards = [
            (today - datetime.timedelta(hours=24 - i),
             today - datetime.timedelta(hours=23 - i))
            for i in xrange(24)]

        self.assertEqual(expected_shards, shards)