def test_do_submit(self):
        bt = BaseThrottler(delay=self.default_delay)
        bt.start()

        throttled_request = bt._submit(self.default_request)
        self.assertIsInstance(throttled_request, ThrottledRequest)

        bt.shutdown()

        with BaseThrottler(delay=self.default_delay) as bt:
            throttled_request = bt._submit(self.default_request)
            self.assertIsInstance(throttled_request, ThrottledRequest)
    def test_do_submit(self):
        bt = BaseThrottler(delay=self.default_delay)
        bt.start()

        throttled_request = bt._submit(self.default_request)
        self.assertIsInstance(throttled_request, ThrottledRequest)

        bt.shutdown()

        with BaseThrottler(delay=self.default_delay) as bt:
            throttled_request = bt._submit(self.default_request)
            self.assertIsInstance(throttled_request, ThrottledRequest)
    def test_shutdown(self):
        bt = BaseThrottler()
        for status in THROTTLER_STATUS:
            bt._status = status
            if status in ['stopped', 'ending', 'ended']:
                self.assertRaises(ThrottlerStatusError, bt.shutdown)
            else:
                bt.shutdown()
                self.assertTrue(bt._wait_enqueued)
                self.assertEqual('stopped', bt._status)

        for status in THROTTLER_STATUS:
            bt._status = status
            if status in ['stopped', 'ending', 'ended']:
                self.assertRaises(ThrottlerStatusError, bt.shutdown)
            else:
                bt.shutdown(wait_enqueued=False)
                self.assertFalse(bt._wait_enqueued)
                self.assertEqual('stopped', bt._status)
    def test_shutdown(self):
        bt = BaseThrottler()
        for status in THROTTLER_STATUS:
            bt._status = status
            if status in ['stopped', 'ending', 'ended']:
                self.assertRaises(ThrottlerStatusError, bt.shutdown)
            else:
                bt.shutdown()
                self.assertTrue(bt._wait_enqueued)
                self.assertEqual('stopped', bt._status)

        for status in THROTTLER_STATUS:
            bt._status = status
            if status in ['stopped', 'ending', 'ended']:
                self.assertRaises(ThrottlerStatusError, bt.shutdown)
            else:
                bt.shutdown(wait_enqueued=False)
                self.assertFalse(bt._wait_enqueued)
                self.assertEqual('stopped', bt._status)
    def test_submit(self):
        bt = BaseThrottler(delay=self.default_delay)
        bt.start()

        throttled_request = bt.submit(self.default_request)
        self.assertIsInstance(throttled_request, ThrottledRequest)
        reqs = [self.default_request for i in range(0, 10)]

        throttled_requests = bt.multi_submit(reqs)
        self.assertIsInstance(throttled_requests, list)
        self.assertEqual(10, len(throttled_requests))

        bt.shutdown()

        with BaseThrottler(delay=self.default_delay) as bt:
            throttled_request = bt.submit(self.default_request)
            self.assertIsInstance(throttled_request, ThrottledRequest)

            reqs = [self.default_request for i in range(0, 10)]
            throttled_requests = bt.multi_submit(reqs)
            self.assertIsInstance(throttled_requests, list)
            self.assertEqual(10, len(throttled_requests))
    def test_submit(self):
        bt = BaseThrottler(delay=self.default_delay)
        bt.start()

        throttled_request = bt.submit(self.default_request)
        self.assertIsInstance(throttled_request, ThrottledRequest)
        reqs = [self.default_request for i in range(0, 10)]

        throttled_requests = bt.multi_submit(reqs)
        self.assertIsInstance(throttled_requests, list)
        self.assertEqual(10, len(throttled_requests))

        bt.shutdown()

        with BaseThrottler(delay=self.default_delay) as bt:
            throttled_request = bt.submit(self.default_request)
            self.assertIsInstance(throttled_request, ThrottledRequest)

            reqs = [self.default_request for i in range(0, 10)]
            throttled_requests = bt.multi_submit(reqs)
            self.assertIsInstance(throttled_requests, list)
            self.assertEqual(10, len(throttled_requests))