def __init__(self, url, timeout_ms=None, api_key: str = None): self._timeout = Utils.to_seconds(timeout_ms or os.environ.get( 'MARQUEZ_TIMEOUT_MS', DEFAULT_TIMEOUT_MS) ) self._api_base = f"{url}{API_PATH_V1}" if api_key: Utils.add_auth_to(_HEADERS, api_key)
def post(self, path, headers, payload=None): if self._api_key: Utils.add_auth_to(headers, self._api_key) response = requests.post( url=f"{self._api_base}{path}", headers=headers, json=payload, timeout=self._timeout ) return self._response(response, as_json=True)
def test_new_client(): os.environ['MARQUEZ_API_KEY'] = API_KEY from marquez_client.client import _USER_AGENT, _HEADERS headers_with_auth = {'User-Agent': _USER_AGENT} # Add API key to headers Utils.add_auth_to(headers_with_auth, API_KEY) client = Clients.new_client() assert client._api_base == API_BASE assert _HEADERS == headers_with_auth del os.environ['MARQUEZ_API_KEY']