Skip to content

Commit

Permalink
Update celery route, fix test, add test for getting label key by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferril committed Jan 8, 2025
1 parent 4bac86a commit 13a1f95
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion engine/apps/alerts/tests/test_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_alert_create_custom_channel_filter(make_organization, make_alert_receiv
assert alert.group.channel_filter == other_channel_filter


@patch("apps.alerts.models.alert.assign_labels")
@patch("apps.alerts.models.alert.save_alert_group_labels")
@patch("apps.alerts.models.alert.gather_alert_labels")
@patch("apps.alerts.models.ChannelFilter.select_filter", wraps=ChannelFilter.select_filter)
@pytest.mark.django_db
Expand Down
24 changes: 24 additions & 0 deletions engine/apps/api/tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ def test_get_update_key_put(
assert response.json() == expected_result


@patch(
"apps.labels.client.LabelsAPIClient.get_label_by_key_name",
return_value=(
{"key": {"id": "keyid123", "name": "keyname12"}, "values": [{"id": "valueid123", "name": "yolo"}]},
MockResponse(status_code=200),
),
)
@pytest.mark.django_db
def test_get_key_by_name(
mocked_get_label_by_key_name,
make_organization_and_user_with_plugin_token,
make_user_auth_headers,
):
_, user, token = make_organization_and_user_with_plugin_token()
client = APIClient()
url = reverse("api-internal:get_key_by_name", kwargs={"key_name": "keyname12"})
response = client.get(url, format="json", **make_user_auth_headers(user, token))
expected_result = {"key": {"id": "keyid123", "name": "keyname12"}, "values": [{"id": "valueid123", "name": "yolo"}]}

assert mocked_get_label_by_key_name.called
assert response.status_code == status.HTTP_200_OK
assert response.json() == expected_result


@patch(
"apps.labels.client.LabelsAPIClient.add_value",
return_value=(
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/api/views/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def _test_connection(self, request, pk=None):
if instance is None:
# pop extra fields so they are not passed to AlertReceiveChannel(**serializer.validated_data)
serializer.validated_data.pop("create_default_webhooks", None)
IntegrationAlertGroupLabelsSerializer.pop_alert_group_labels(serializer.validated_data)
IntegrationAlertGroupLabelsSerializer._pop_alert_group_labels(serializer.validated_data)

# create in-memory instance to test with the (possible) unsaved data
instance = AlertReceiveChannel(**serializer.validated_data)
Expand Down
1 change: 1 addition & 0 deletions engine/apps/api/views/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LabelsViewSet(LabelsFeatureFlagViewSet):
"rename_value": [RBACPermission.Permissions.LABEL_WRITE],
"get_keys": [RBACPermission.Permissions.LABEL_READ],
"get_key": [RBACPermission.Permissions.LABEL_READ],
"get_key_by_name": [RBACPermission.Permissions.LABEL_READ],
"get_value": [RBACPermission.Permissions.LABEL_READ],
}

Expand Down
1 change: 1 addition & 0 deletions engine/settings/celery_task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"apps.labels.tasks.update_label_pairs_cache": {"queue": "default"},
"apps.labels.tasks.add_service_label_for_alerting_integrations": {"queue": "default"},
"apps.labels.tasks.add_service_label_per_org": {"queue": "default"},
"apps.labels.tasks.add_service_label_for_integration": {"queue": "default"},
"apps.metrics_exporter.tasks.start_calculate_and_cache_metrics": {"queue": "default"},
"apps.metrics_exporter.tasks.update_metrics_for_alert_group": {"queue": "default"},
"apps.metrics_exporter.tasks.update_metrics_for_user": {"queue": "default"},
Expand Down

0 comments on commit 13a1f95

Please sign in to comment.