def __init__(self, host, port, pretender_timeout=TIMEOUT_PRETENDER): self.host = host self.port = port self.pretender_timeout = pretender_timeout self.full_host = "{0}:{1}".format(self.host, self.port) self.connection = HTTPConnection(self.full_host) self.boss_access = APIHelper(self.connection, '') (self.pretend_access_point, self.pretend_access_point_id) = self._request_mock_access() if self.pretend_access_point: self.pretend_port = int(self.pretend_access_point.split(':')[1]) self.history = APIHelper( self.connection, '/history/{0}'.format(self.pretend_access_point_id)) self.preset = PresetHelper( self.connection, '/preset/{0}'.format(self.pretend_access_point_id))
def test_clear_down_only_happens_if_no_request_for_timeout_period(): # Test that stale mock servers are not cleared if they # recently made a request. # TODO: Once the timeout specification can be dictated by the client # the sleep in this test can be reduced. http_mock = HTTPMock('localhost', 8000, pretender_timeout=5) pretender = http_mock.get_pretender() timeout_server = pretender.timeout_in_secs assert_equal(pretender.last_call, pretender.start) for i in range(3): # Sleep for a while, check that the server is still running and then # make a call to the mock server. time.sleep(timeout_server / 2) # Check that we are still running pretender = http_mock.get_pretender() # Make a call to the mock server. pretender_client = APIHelper( HTTPConnection(http_mock.pretend_access_point), '') pretender_client.http(method="GET", url="/some_url")