Skip to content

Commit

Permalink
Merge branch 'main' into fix/grace-period-breach-for-paid-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan committed Aug 19, 2024
2 parents 1e07369 + 7034fa4 commit 9d83904
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions api/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ def get_queryset(self):
identity__isnull=True,
feature_segment__isnull=True,
)
feature_states = FeatureState.objects.get_live_feature_states(
self.environment,
feature_states = get_environment_flags_list(
environment=self.environment,
additional_filters=q,
).select_related("feature_state_value", "feature")

additional_select_related_args=["feature_state_value", "feature"],
)
self._feature_states = {fs.feature_id: fs for fs in feature_states}

return queryset
Expand Down
1 change: 1 addition & 0 deletions api/organisations/subscriptions/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(
api_calls: int = 0,
projects: typing.Optional[int] = None,
chargebee_email=None,
**kwargs, # allows for extra unknown attrs from CB json metadata
):
self.seats = seats
self.api_calls = api_calls
Expand Down
20 changes: 12 additions & 8 deletions api/tests/unit/features/test_unit_features_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2814,18 +2814,22 @@ def test_list_features_with_feature_state(
project=project,
)

# This should be ignored due to versioning.
feature_state1 = feature.feature_states.filter(environment=environment).first()
feature_state1.enabled = True
feature_state1.version = 1
feature_state1.save()

feature_state_value1 = feature_state1.feature_state_value
feature_state_value1.string_value = None
feature_state_value1.integer_value = 1945
feature_state_value1.type = INTEGER
feature_state_value1.save()

# This should be ignored due to versioning.
# This should be ignored due to less recent live_from compared to the next feature state
# event though it has a higher version.
FeatureState.objects.create(
feature=feature,
environment=environment,
live_from=two_hours_ago,
enabled=True,
version=101,
)
# This should be returned
feature_state_versioned = FeatureState.objects.create(
feature=feature,
environment=environment,
Expand Down Expand Up @@ -2896,8 +2900,8 @@ def test_list_features_with_feature_state(

assert len(response.data["results"]) == 3
results = response.data["results"]

assert results[0]["environment_feature_state"]["enabled"] is True
assert results[0]["environment_feature_state"]["id"] == feature_state_versioned.id
assert results[0]["environment_feature_state"]["feature_state_value"] == 2005
assert results[0]["name"] == feature.name
assert results[1]["environment_feature_state"]["enabled"] is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_chargebee_cache(mocker, db):
"seats": 10,
"api_calls": 100,
"projects": 10,
"some_unknown_key": 1, # should be ignored
}
plan_id = "plan_id"
plan_items = [
Expand All @@ -69,6 +70,7 @@ def test_chargebee_cache(mocker, db):
"seats": 1,
"api_calls": 10,
"projects": 1,
"some_unknown_key": 1, # should be ignored
}
addon_id = "addon_id"
addon_items = [
Expand All @@ -90,8 +92,10 @@ def test_chargebee_cache(mocker, db):
assert cache.plans[plan_id].seats == plan_metadata["seats"]
assert cache.plans[plan_id].api_calls == plan_metadata["api_calls"]
assert cache.plans[plan_id].projects == plan_metadata["projects"]
assert not hasattr(cache.plans[plan_id], "some_unknown_key")

assert len(cache.addons) == 1
assert cache.addons[addon_id].seats == addon_metadata["seats"]
assert cache.addons[addon_id].api_calls == addon_metadata["api_calls"]
assert cache.addons[addon_id].projects == addon_metadata["projects"]
assert not hasattr(cache.addons[addon_id], "some_unknown_key")

0 comments on commit 9d83904

Please sign in to comment.