Skip to content

Commit

Permalink
Make type required when creating an escalation policy step (#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasb authored May 20, 2024
1 parent 5544769 commit 3c58c2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion engine/apps/public_api/serializers/escalation_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EscalationPolicySerializer(EagerLoadingMixin, OrderedModelSerializer):
escalation_chain_id = OrganizationFilteredPrimaryKeyRelatedField(
queryset=EscalationChain.objects, source="escalation_chain"
)
type = EscalationPolicyTypeField(source="step", allow_null=True)
type = EscalationPolicyTypeField(source="step")
duration = serializers.ChoiceField(required=False, source="wait_delay", choices=EscalationPolicy.DURATION_CHOICES)
persons_to_notify = UsersFilteredByOrganizationField(
queryset=User.objects,
Expand Down
21 changes: 21 additions & 0 deletions engine/apps/public_api/tests/test_escalation_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ def test_create_escalation_policy(
assert response.data == serializer.data


@pytest.mark.django_db
def test_create_empty_escalation_policy(
make_organization_and_user_with_token,
escalation_policies_setup,
):
organization, user, token = make_organization_and_user_with_token()
escalation_chain, _, _ = escalation_policies_setup(organization, user)

data_for_create = {
"escalation_chain_id": escalation_chain.public_primary_key,
"type": None,
}

client = APIClient()
url = reverse("api-public:escalation_policies-list")
response = client.post(url, data=data_for_create, format="json", HTTP_AUTHORIZATION=token)

assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data["type"][0] == "This field may not be null."


@pytest.mark.django_db
def test_create_escalation_policy_manual_order_duplicated_position(
make_organization_and_user_with_token,
Expand Down
38 changes: 0 additions & 38 deletions engine/apps/user_management/tests/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,41 +278,3 @@ def _assert(org, arc, should_be_returned=True):
make_channel_filter(arc, is_default=False)
notifiable_direct_paging_integrations = _assert(org, arc)
assert notifiable_direct_paging_integrations.count() == 1


@pytest.mark.parametrize(
"is_rbac_permissions_enabled_initially,rollout_percentage,expected",
[
# env var is not set, no orgs have is_rbac_permissions_enabled set
(False, 0.0, False),
# env var is not set but is_rbac_permissions_enabled is already set for all orgs
(True, 0.0, True),
# env var is set, only some orgs should be considered
(False, 0.5, "partial"),
(False, 1.0, True),
],
)
@pytest.mark.django_db
def test_should_be_considered_for_rbac_permissioning(
make_organization,
settings,
is_rbac_permissions_enabled_initially,
rollout_percentage,
expected,
):
NUM_ORGS = 5
settings.CLOUD_RBAC_ROLLOUT_PERCENTAGE = rollout_percentage

orgs = [
make_organization(is_rbac_permissions_enabled=is_rbac_permissions_enabled_initially) for _ in range(NUM_ORGS)
]

assert all(org.is_rbac_permissions_enabled is is_rbac_permissions_enabled_initially for org in orgs)

if expected == "partial":
assert all(
org.should_be_considered_for_rbac_permissioning() == (org.id <= NUM_ORGS * rollout_percentage)
for org in orgs
)
else:
assert all(org.should_be_considered_for_rbac_permissioning() is expected for org in orgs)

0 comments on commit 3c58c2f

Please sign in to comment.