def __init__( self, base_url: str = None, universal_parameters: dict = None, universal_headers: dict = None, log_requests: bool = False, ): """ Create a reusable request handler Set universal parameters and headers used for all requests Reuses session for all requests :param base_url: Base URL of all requests :type base_url: str, optional :param universal_parameters: Dictionary of parameters to include in all requests (i.e. API token, language) :type universal_parameters: dict, optional :param universal_headers: Dictionary of header to include in all requests (i.e. API token, user agent) :type universal_parameters: dict, optional :param log_requests: whether to log the request (default False) :type log_requests: bool, optional """ self.base_url = base_url self.params = universal_parameters self.headers = universal_headers self._log = log_requests self._session = objectrest.Session()
def test_options_with_session(): session = objectrest.Session() res = objectrest.options(url=URL, session=session, log=True) assert res.request.method == "OPTIONS" assert res.status_code == 200
def test_head_with_session(): session = objectrest.Session() res = objectrest.head(url=URL, session=session, log=True) assert res.request.method == "HEAD" assert res.status_code == 200
def test_patch_with_session(): session = objectrest.Session() res = objectrest.patch(url=URL, session=session, log=True) assert res.request.method == "PATCH" assert res.status_code == 200
def test_delete_with_session(): session = objectrest.Session() res = objectrest.delete(url=URL, session=session, log=True) assert res.request.method == "DELETE" assert res.status_code == 200
def test_post_with_session(): session = objectrest.Session() res = objectrest.post(url=URL, session=session, log=True) assert res.request.method == "POST" assert res.status_code == 200