def generate_cookies(auth_token_username):
     if not auth_token_username:
         return {}
     return dict(
         request.cookies.items() +
         make_auth_cookie(auth_token_username).items()
     )
Пример #2
0
    def get(self, url, query_string=None, auth_token_username=None, catch_errors=True):
        if query_string:
            url = url + "?" + query_string
        auth_token_cookie = make_auth_cookie(auth_token_username)

        response = requests.get(url=url, cookies=dict(request.cookies.items() + auth_token_cookie.items()))
        if response.status_code / 100 != 2 and catch_errors:
            raise HttpError(response.status_code, response.content)

        return response
Пример #3
0
    def delete(self, url, data=None, headers=None, auth_token_username=None, catch_errors=True):
        auth_token_cookies = make_auth_cookie(auth_token_username)
        response = requests.delete(
            url=url,
            data=json.dumps(data) if data else None,
            cookies=dict(request.cookies.items() + auth_token_cookies.items()),
            headers=headers if headers else {"content-type": "application/json"},
        )
        if response.status_code / 100 != 2 and catch_errors:
            raise HttpError(response.status_code, response.content)

        return response
Пример #4
0
 def put(self, url, data, headers=None, auth_token_username=None, catch_errors=True):
     if not headers:
         headers = {'content-type': 'application/json'}
     auth_token_cookies = make_auth_cookie(auth_token_username)
     response = requests.put(
         url=url,
         data=json.dumps(data),
         cookies=dict(request.cookies.items() + auth_token_cookies.items()),
         headers=headers
     )
     if response.status_code / 100 != 2 and catch_errors:
         raise HttpError(response.status_code, response.content)
     return response