def test_context_setdefault_method(): with context( ): # run in contextmanager to automatically clear when finished assert "a" not in context assert context.setdefault("a", 5) == 5 assert "a" in context assert context.setdefault("a", 10) == 5
def test_render_dict_gets_env_variables(monkeypatch): some_cred = str(uuid.uuid4()) another_secret = str(uuid.uuid4()) monkeypatch.setenv("SOME_CRED", some_cred) webhook = Webhook( build_request_kwargs={ "url": "https://content.dropboxapi.com/2/files", "headers": { "X-Api-Key": "${SOME_CRED}", "X-Custom-Key": "${ANOTHER_SECRET}", }, }, build_request_http_method="POST", get_flow_request_kwargs={ "url": "https://content.dropboxapi.com/2/files" }, get_flow_request_http_method="GET", ) # set a local secret context.setdefault("secrets", {}) context.secrets["ANOTHER_SECRET"] = another_secret new_kwargs = _render_dict(webhook.build_request_kwargs) # _render_dict should not have side effects assert webhook.build_request_kwargs == { "url": "https://content.dropboxapi.com/2/files", "headers": { "X-Api-Key": "${SOME_CRED}", "X-Custom-Key": "${ANOTHER_SECRET}" }, } # env variables and secrets should have been filled in assert new_kwargs["headers"]["X-Api-Key"] == some_cred assert new_kwargs["headers"]["X-Custom-Key"] == another_secret