def test_request_timings(): send_headers = { 'token': '0000000000' } request_spec = RequestSpec(uri='mock://github/events', send_headers=send_headers) # get mock session and do a get session = mock_requests.create_mock_session() resp = session.get(request_spec.uri) # default timings timings = RequestTimings(request_spec) # assert defaults assert timings.interval == '1000' assert timings.rate_limit == '1' assert timings.rate_limit_remaining == '1' assert timings.time_to_reset == '60' assert timings.etag is None # update timings timings.update(resp) # asserts new timings assert timings.interval == mock_requests.GLOBAL_MOCK_REQUEST_INTERVAL assert timings.rate_limit == mock_requests.GLOBAL_MOCK_REQUEST_RATELIMIT assert timings.rate_limit_remaining == mock_requests.GLOBAL_MOCK_REQUEST_REMAINING assert timings.time_to_reset == mock_requests.GLOBAL_MOCK_REQUEST_RESET
def test_request_service(): timer_interval = 2 class Timer(BaseService): """ This test relies on this simple Timer to check things. """ def __init__(self, service): BaseService.__init__(self, "timer") self.service = service def event_loop(self): self.log.debug("tick") gevent.sleep(timer_interval) self.service.stop() # setup scheduler scheduler = Scheduler("scheduler") assert scheduler is not None # create test support Timer class timer = Timer(scheduler) # setup request_service request_spec = RequestSpec(uri='mock://github/events') request_service = RequestService("request-service-1", request_spec, mock_requests.create_mock_session()) assert request_service is not None # add services scheduler.add_service(request_service) # start services # scheduler.start() # gevent.joinall([scheduler.start()]) # blocks gevent.joinall([scheduler.start(), timer.start()]) # blocks