Skip to content

Commit 9b21af7

Browse files
authored
fix(project/realtime): only allow enterprise to enable realtime (#4843)
1 parent 9bbfdf0 commit 9b21af7

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

api/conftest.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@
5959
CREATE_PROJECT,
6060
MANAGE_USER_GROUPS,
6161
)
62-
from organisations.subscriptions.constants import CHARGEBEE, XERO
62+
from organisations.subscriptions.constants import (
63+
CHARGEBEE,
64+
FREE_PLAN_ID,
65+
SCALE_UP,
66+
STARTUP,
67+
XERO,
68+
)
6369
from permissions.models import PermissionModel
6470
from projects.models import (
6571
Project,
@@ -324,6 +330,33 @@ def enterprise_subscription(organisation: Organisation) -> Subscription:
324330
return organisation.subscription
325331

326332

333+
@pytest.fixture()
334+
def startup_subscription(organisation: Organisation) -> Subscription:
335+
Subscription.objects.filter(organisation=organisation).update(
336+
plan=STARTUP, subscription_id="subscription-id"
337+
)
338+
organisation.refresh_from_db()
339+
return organisation.subscription
340+
341+
342+
@pytest.fixture()
343+
def scale_up_subscription(organisation: Organisation) -> Subscription:
344+
Subscription.objects.filter(organisation=organisation).update(
345+
plan=SCALE_UP, subscription_id="subscription-id"
346+
)
347+
organisation.refresh_from_db()
348+
return organisation.subscription
349+
350+
351+
@pytest.fixture()
352+
def free_subscription(organisation: Organisation) -> Subscription:
353+
Subscription.objects.filter(organisation=organisation).update(
354+
plan=FREE_PLAN_ID, subscription_id="subscription-id"
355+
)
356+
organisation.refresh_from_db()
357+
return organisation.subscription
358+
359+
327360
@pytest.fixture()
328361
def project(organisation):
329362
return Project.objects.create(name="Test Project", organisation=organisation)

api/projects/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ProjectUpdateOrCreateSerializer(
6969
ReadOnlyIfNotValidPlanMixin, ProjectListSerializer
7070
):
7171
invalid_plans_regex = r"^(free|startup.*|scale-up.*)$"
72-
field_names = ("stale_flags_limit_days",)
72+
field_names = ("stale_flags_limit_days", "enable_realtime_updates")
7373

7474
def get_subscription(self) -> typing.Optional[Subscription]:
7575
view = self.context["view"]

api/tests/unit/projects/test_unit_projects_views.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,20 @@ def test_get_project_by_uuid(client, project, mocker, settings, organisation):
687687

688688

689689
@pytest.mark.parametrize(
690-
"client",
691-
[(lazy_fixture("admin_master_api_key_client")), (lazy_fixture("admin_client"))],
690+
"subscription, can_update_realtime",
691+
[
692+
(lazy_fixture("free_subscription"), False),
693+
(lazy_fixture("startup_subscription"), False),
694+
(lazy_fixture("scale_up_subscription"), False),
695+
(lazy_fixture("enterprise_subscription"), True),
696+
],
692697
)
693-
def test_can_enable_realtime_updates_for_project(
694-
client, project, mocker, settings, organisation
698+
def test_can_enable_realtime_updates_for_enterprise(
699+
admin_client: APIClient,
700+
project: Project,
701+
organisation: Organisation,
702+
subscription: Subscription,
703+
can_update_realtime: bool,
695704
):
696705
# Given
697706
url = reverse("api-v1:projects:project-detail", args=[project.id])
@@ -703,12 +712,12 @@ def test_can_enable_realtime_updates_for_project(
703712
}
704713

705714
# When
706-
response = client.put(url, data=data)
715+
response = admin_client.put(url, data=data)
707716

708717
# Then
709718
assert response.status_code == status.HTTP_200_OK
710719
assert response.json()["uuid"] == str(project.uuid)
711-
assert response.json()["enable_realtime_updates"] is True
720+
assert response.json()["enable_realtime_updates"] is can_update_realtime
712721

713722

714723
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)