Skip to content

Commit

Permalink
format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmossman committed Jan 31, 2023
1 parent d6b8277 commit c8f2042
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

import re
from abc import ABC
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple

Expand Down Expand Up @@ -327,7 +326,7 @@ def request_params(self, stream_state: Mapping[str, Any], stream_slice: Mapping[
params = {
"granularity": "day",
"timeframe_start": to_utc_isoformat(stream_slice["timeframe_start"]),
"timeframe_end": to_utc_isoformat(stream_slice["timeframe_end"])
"timeframe_end": to_utc_isoformat(stream_slice["timeframe_end"]),
}

if self.subscription_usage_grouping_key:
Expand Down Expand Up @@ -416,7 +415,11 @@ def stream_slices(self, stream_state: Mapping[str, Any] = None, **kwargs) -> Ite

# create one slice for each day of usage between the start and end date
for period in chunk_date_range(start_date=start_date, end_date=end_date):
slice = {"subscription_id": subscription_id, "timeframe_start": to_utc_isoformat(period.start), "timeframe_end": to_utc_isoformat(period.end)}
slice = {
"subscription_id": subscription_id,
"timeframe_start": to_utc_isoformat(period.start),
"timeframe_end": to_utc_isoformat(period.end),
}

# if using a group_by key, yield one slice per billable_metric_id.
# otherwise, yield slices without a billable_metric_id because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import responses
from airbyte_cdk.models import SyncMode
from pytest import fixture
from source_orb.source import CreditsLedgerEntries, Customers, IncrementalOrbStream, OrbStream, Subscriptions, SubscriptionUsage, Plans
from source_orb.source import CreditsLedgerEntries, Customers, IncrementalOrbStream, OrbStream, Plans, Subscriptions, SubscriptionUsage


@fixture
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_subscription_usage_stream_slices(mocker):
Subscriptions, "read_records", return_value=iter([
{"id": "1", "plan_id": "2"},
{"id": "11", "plan_id": "2"},
{"id": "111", "plan_id": "3"} # should be ignored because plan_id set to 2
{"id": "111", "plan_id": "3"} # should be ignored because plan_id set to 2
])
)
stream = SubscriptionUsage(plan_id="2", start_date="2022-01-25T12:00:00+00:00", end_date="2022-01-26T12:00:00+00:00")
Expand All @@ -343,7 +343,7 @@ def test_subscription_usage_stream_slices_with_grouping_key(mocker):
Subscriptions, "read_records", return_value=iter([
{"id": "1", "plan_id": "2"},
{"id": "11", "plan_id": "2"},
{"id": "111", "plan_id": "3"} # should be ignored because plan_id set to 2
{"id": "111", "plan_id": "3"} # should be ignored because plan_id set to 2
])
)

Expand All @@ -353,7 +353,7 @@ def test_subscription_usage_stream_slices_with_grouping_key(mocker):
{"billable_metric": {"id": "billableMetricIdA"}},
{"billable_metric": {"id": "billableMetricIdB"}}
]},
{"id": "3", "prices": [ # should be ignored because plan_id is set to 2
{"id": "3", "prices": [ # should be ignored because plan_id is set to 2
{"billable_metric": {"id": "billableMetricIdC"}}
]}
])
Expand All @@ -374,7 +374,6 @@ def test_subscription_usage_stream_slices_with_grouping_key(mocker):
assert list(stream.stream_slices(**inputs)) == expected_stream_slice



@pytest.mark.parametrize(
("current_stream_state", "current_stream_slice", "grouping_key"),
[
Expand Down Expand Up @@ -499,6 +498,7 @@ def test_subscription_usage_yield_transformed_subrecords(mocker):

assert actual_output == expected


def test_subscription_usage_yield_transformed_subrecords_with_grouping(mocker):
stream = SubscriptionUsage(start_date="2022-01-25T12:00:00+00:00", end_date="2022-01-26T12:00:00+00:00", subscription_usage_grouping_key="grouping_key")

Expand Down Expand Up @@ -567,6 +567,7 @@ def test_subscription_usage_yield_transformed_subrecords_with_grouping(mocker):

assert actual_output == expected


def test_supports_incremental(patch_incremental_base_class, mocker):
mocker.patch.object(IncrementalOrbStream, "cursor_field", "dummy_field")
stream = IncrementalOrbStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_credit_ledger_entries_schema(patch_base_class, mocker, event_properties
for property_key in event_properties_keys:
assert property_key in json_schema["properties"]["event"]["properties"]["properties"]["properties"]


@pytest.mark.parametrize("group_by_key", ["foo-key", None])
def test_subscription_usage_schema(patch_base_class, mocker, group_by_key):
stream = SubscriptionUsage(subscription_usage_grouping_key=group_by_key)
Expand Down

0 comments on commit c8f2042

Please sign in to comment.