Skip to content

Commit

Permalink
Merge branch 'main' into 2648-feat-add-a-generic-filestream-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 26, 2024
2 parents a01449a + 64bf58e commit 92f1522
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
- id: check-readthedocs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
rev: v0.6.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
7 changes: 4 additions & 3 deletions samples/sample_tap_dummy_json/tap_dummyjson/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, auth_url, refresh_token_url, username, password):
self.refresh_token = None

self.expires = 0
self.session = requests.Session()

def __call__(self, request):
if not self.refresh_token:
Expand All @@ -45,13 +46,13 @@ def _handle_response(self, response):
response.raise_for_status()

data = response.json()
self.token = data["token"]
self.token = data["accessToken"]
self.refresh_token = data["refreshToken"]
self.expires = time.time() + EXPIRES_IN_MINS * 60
logger.info("Authenticated")

def refresh(self):
response = requests.post(
response = self.session.post(
self.refresh_token_url,
json={
"refreshToken": self.refresh_token,
Expand All @@ -61,7 +62,7 @@ def refresh(self):
self._handle_response(response)

def auth(self):
response = requests.post(
response = self.session.post(
self.auth_url,
json={
"username": self.username,
Expand Down
10 changes: 9 additions & 1 deletion singer_sdk/helpers/_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import inflection

from singer_sdk._singerlib.json import serialize_json
from singer_sdk.exceptions import ConfigValidationError

DEFAULT_FLATTENING_SEPARATOR = "__"

Expand All @@ -35,7 +36,14 @@ def get_flattening_options(
A new FlatteningOptions object or None if flattening is disabled.
"""
if plugin_config.get("flattening_enabled", False):
return FlatteningOptions(max_level=int(plugin_config["flattening_max_depth"]))
if (max_depth := plugin_config.get("flattening_max_depth")) is not None:
return FlatteningOptions(max_level=int(max_depth))

msg = "Flattening is misconfigured"
raise ConfigValidationError(
msg,
errors=["flattening_max_depth is required when flattening is enabled"],
)

return None

Expand Down
15 changes: 14 additions & 1 deletion tests/core/test_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import pytest

from singer_sdk.helpers._flattening import flatten_record
from singer_sdk.exceptions import ConfigValidationError
from singer_sdk.helpers._flattening import flatten_record, get_flattening_options


@pytest.mark.parametrize(
Expand Down Expand Up @@ -72,3 +73,15 @@ def test_flatten_record(flattened_schema, max_level, expected):
record, max_level=max_level, flattened_schema=flattened_schema
)
assert expected == result


def test_get_flattening_options_missing_max_depth():
with pytest.raises(
ConfigValidationError, match="Flattening is misconfigured"
) as exc:
get_flattening_options({"flattening_enabled": True})

assert (
exc.value.errors[0]
== "flattening_max_depth is required when flattening is enabled"
)

0 comments on commit 92f1522

Please sign in to comment.