Skip to content

Commit 48f96d9

Browse files
committed
Improve interface
1 parent 8eaea9e commit 48f96d9

4 files changed

Lines changed: 10 additions & 18 deletions

File tree

api/organisations/subscription_info_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
]
1717

1818

19-
def update_caches(update_cache_entities: typing.Tuple[SubscriptionCacheEntity, ...]): # type: ignore[no-untyped-def]
19+
def update_caches(*update_cache_entities: SubscriptionCacheEntity) -> None:
2020
"""
2121
Update the cache objects for an update_cache_entity in the database.
2222
"""

api/organisations/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ def update_organisation_subscription_information_cache_recurring() -> None:
8989

9090
@register_task_handler()
9191
def update_organisation_subscription_information_api_usage_cache() -> None:
92-
subscription_info_cache.update_caches((SubscriptionCacheEntity.API_USAGE,))
92+
subscription_info_cache.update_caches(SubscriptionCacheEntity.API_USAGE)
9393

9494

9595
@register_task_handler(timeout=timedelta(minutes=5))
9696
def update_organisation_subscription_information_cache() -> None:
9797
subscription_info_cache.update_caches(
98-
(SubscriptionCacheEntity.CHARGEBEE, SubscriptionCacheEntity.API_USAGE)
98+
SubscriptionCacheEntity.CHARGEBEE, SubscriptionCacheEntity.API_USAGE
9999
)
100100

101101

api/tests/unit/organisations/test_unit_organisations_subscription_info_cache.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ def test_update_caches__with_usage_data__populates_cache_correctly( # type: ign
4848
mocked_get_subscription_metadata.return_value = chargebee_metadata
4949

5050
# When
51-
subscription_cache_entities = (
52-
SubscriptionCacheEntity.API_USAGE,
53-
SubscriptionCacheEntity.CHARGEBEE,
54-
)
55-
update_caches(subscription_cache_entities)
51+
update_caches(SubscriptionCacheEntity.API_USAGE, SubscriptionCacheEntity.CHARGEBEE)
5652

5753
# Then
5854
assert (
@@ -118,11 +114,7 @@ def test_update_caches__no_usage_data__resets_cache_to_zero(
118114
mocked_get_subscription_metadata.return_value = chargebee_metadata
119115

120116
# When
121-
subscription_cache_entities = (
122-
SubscriptionCacheEntity.API_USAGE,
123-
SubscriptionCacheEntity.CHARGEBEE,
124-
)
125-
update_caches(subscription_cache_entities)
117+
update_caches(SubscriptionCacheEntity.API_USAGE, SubscriptionCacheEntity.CHARGEBEE)
126118

127119
# Then
128120
organisation.refresh_from_db()
@@ -159,7 +151,7 @@ def test_update_caches__postgres_analytics__populates_cache_correctly(
159151
)
160152

161153
# When
162-
update_caches((SubscriptionCacheEntity.API_USAGE,))
154+
update_caches(SubscriptionCacheEntity.API_USAGE)
163155

164156
# Then
165157
organisation.refresh_from_db()
@@ -197,7 +189,7 @@ def test_update_caches__postgres_and_influx_configured__prefers_postgres(
197189
)
198190

199191
# When
200-
update_caches((SubscriptionCacheEntity.API_USAGE,))
192+
update_caches(SubscriptionCacheEntity.API_USAGE)
201193

202194
# Then
203195
assert mocked_get_top_organisations_from_local_db.call_count == 3
@@ -228,7 +220,7 @@ def test_update_caches__no_analytics_source_configured__skips_api_usage_update(
228220
)
229221

230222
# When
231-
update_caches((SubscriptionCacheEntity.API_USAGE,))
223+
update_caches(SubscriptionCacheEntity.API_USAGE)
232224

233225
# Then — neither analytics source was queried
234226
assert mock_get_top_organisations_from_local_db.call_count == 0

api/tests/unit/organisations/test_unit_organisations_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ def test_update_organisation_subscription_information_api_usage_cache__called__c
21822182

21832183
# Then
21842184
assert mock_update_caches.call_args_list == [
2185-
mocker.call((SubscriptionCacheEntity.API_USAGE,))
2185+
mocker.call(SubscriptionCacheEntity.API_USAGE)
21862186
]
21872187

21882188

@@ -2200,6 +2200,6 @@ def test_update_organisation_subscription_information_cache__called__calls_updat
22002200
# Then
22012201
assert mock_update_caches.call_args_list == [
22022202
mocker.call(
2203-
(SubscriptionCacheEntity.CHARGEBEE, SubscriptionCacheEntity.API_USAGE)
2203+
SubscriptionCacheEntity.CHARGEBEE, SubscriptionCacheEntity.API_USAGE
22042204
)
22052205
]

0 commit comments

Comments
 (0)