Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: versioning webhooks and update test to correctly test end to end #4221

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/features/versioning/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def trigger_update_version_webhooks(environment_feature_version_uuid: str) -> No

data = environment_feature_version_webhook_schema.dump(environment_feature_version)
call_environment_webhooks(
environment=environment_feature_version.environment_id,
environment_id=environment_feature_version.environment_id,
data=data,
event_type=WebhookEventType.NEW_VERSION_PUBLISHED.value,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
from datetime import timedelta

import freezegun
import responses
from django.utils import timezone
from pytest_mock import MockerFixture

from environments.identities.models import Identity
from environments.models import Environment
from environments.models import Environment, Webhook
from features.models import Feature, FeatureSegment, FeatureState
from features.versioning.models import EnvironmentFeatureVersion
from features.versioning.tasks import (
Expand Down Expand Up @@ -140,6 +142,7 @@ def test_disable_v2_versioning(
assert unaffected_environment.feature_segments.count() == 1


@responses.activate
def test_trigger_update_version_webhooks(
environment_v2_versioning: Environment, feature: Feature, mocker: MockerFixture
) -> None:
Expand All @@ -149,17 +152,19 @@ def test_trigger_update_version_webhooks(
)
feature_state = version.feature_states.first()

mock_call_environment_webhooks = mocker.patch(
"features.versioning.tasks.call_environment_webhooks"
)
webhook_url = "https://example.com/webhook/"
Webhook.objects.create(environment=environment_v2_versioning, url=webhook_url)

responses.post(url=webhook_url, status=200)

# When
trigger_update_version_webhooks(str(version.uuid))

# Then
mock_call_environment_webhooks.assert_called_once_with(
environment=environment_v2_versioning.id,
data={
assert len(responses.calls) == 1
assert responses.calls[0].request.url == webhook_url
assert json.loads(responses.calls[0].request.body) == {
"data": {
"uuid": str(version.uuid),
"feature": {"id": feature.id, "name": feature.name},
"published_by": None,
Expand All @@ -170,8 +175,8 @@ def test_trigger_update_version_webhooks(
}
],
},
event_type=WebhookEventType.NEW_VERSION_PUBLISHED.value,
)
"event_type": WebhookEventType.NEW_VERSION_PUBLISHED.name,
}


def test_enable_v2_versioning_for_scheduled_changes(
Expand Down
Loading