-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow creating integration configurations where deleted versions…
… exist (#2531)
- Loading branch information
1 parent
721957a
commit 3430829
Showing
22 changed files
with
190 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from rest_framework import serializers | ||
|
||
from integrations.amplitude.models import AmplitudeConfiguration | ||
from integrations.common.serializers import ( | ||
BaseEnvironmentIntegrationModelSerializer, | ||
) | ||
|
||
|
||
class AmplitudeConfigurationSerializer(serializers.ModelSerializer): | ||
class AmplitudeConfigurationSerializer(BaseEnvironmentIntegrationModelSerializer): | ||
class Meta: | ||
model = AmplitudeConfiguration | ||
fields = ("id", "api_key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from integrations.amplitude.models import AmplitudeConfiguration | ||
from integrations.amplitude.serializers import AmplitudeConfigurationSerializer | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
|
||
|
||
class AmplitudeConfigurationViewSet(IntegrationCommonViewSet): | ||
class AmplitudeConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = AmplitudeConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = AmplitudeConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,8 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.generics import get_object_or_404 | ||
|
||
from integrations.common.views import ProjectIntegrationBaseViewSet | ||
from integrations.datadog.models import DataDogConfiguration | ||
from integrations.datadog.serializers import DataDogConfigurationSerializer | ||
from projects.permissions import VIEW_PROJECT | ||
|
||
|
||
class DataDogConfigurationViewSet(viewsets.ModelViewSet): | ||
class DataDogConfigurationViewSet(ProjectIntegrationBaseViewSet): | ||
serializer_class = DataDogConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
|
||
def get_queryset(self): | ||
if getattr(self, "swagger_fake_view", False): | ||
return DataDogConfiguration.objects.none() | ||
|
||
project = get_object_or_404( | ||
self.request.user.get_permitted_projects(VIEW_PROJECT), | ||
pk=self.kwargs["project_pk"], | ||
) | ||
return DataDogConfiguration.objects.filter(project=project) | ||
|
||
def perform_create(self, serializer): | ||
project_id = self.kwargs["project_pk"] | ||
if DataDogConfiguration.objects.filter(project_id=project_id).exists(): | ||
raise ValidationError( | ||
"DataDogConfiguration for this project already exist." | ||
) | ||
|
||
serializer.save(project_id=project_id) | ||
|
||
def perform_update(self, serializer): | ||
project_id = self.kwargs["project_pk"] | ||
serializer.save(project_id=project_id) | ||
model_class = DataDogConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.dynatrace.models import DynatraceConfiguration | ||
from integrations.dynatrace.serializers import DynatraceConfigurationSerializer | ||
|
||
|
||
class DynatraceConfigurationViewSet(IntegrationCommonViewSet): | ||
class DynatraceConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = DynatraceConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = DynatraceConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.heap.models import HeapConfiguration | ||
from integrations.heap.serializers import HeapConfigurationSerializer | ||
|
||
|
||
class HeapConfigurationViewSet(IntegrationCommonViewSet): | ||
class HeapConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = HeapConfigurationSerializer | ||
model_class = HeapConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.mixpanel.models import MixpanelConfiguration | ||
from integrations.mixpanel.serializers import MixpanelConfigurationSerializer | ||
|
||
|
||
class MixpanelConfigurationViewSet(IntegrationCommonViewSet): | ||
class MixpanelConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = MixpanelConfigurationSerializer | ||
model_class = MixpanelConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,8 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.generics import get_object_or_404 | ||
|
||
from integrations.common.views import ProjectIntegrationBaseViewSet | ||
from integrations.new_relic.models import NewRelicConfiguration | ||
from integrations.new_relic.serializers import NewRelicConfigurationSerializer | ||
from projects.permissions import VIEW_PROJECT | ||
|
||
|
||
class NewRelicConfigurationViewSet(viewsets.ModelViewSet): | ||
class NewRelicConfigurationViewSet(ProjectIntegrationBaseViewSet): | ||
serializer_class = NewRelicConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
|
||
def get_queryset(self): | ||
if getattr(self, "swagger_fake_view", False): | ||
return NewRelicConfiguration.objects.none() | ||
|
||
project = get_object_or_404( | ||
self.request.user.get_permitted_projects(VIEW_PROJECT), | ||
pk=self.kwargs["project_pk"], | ||
) | ||
return NewRelicConfiguration.objects.filter(project=project) | ||
|
||
def perform_create(self, serializer): | ||
project_id = self.kwargs["project_pk"] | ||
if NewRelicConfiguration.objects.filter(project_id=project_id).exists(): | ||
raise ValidationError( | ||
"NewRelicConfiguration for this project already exist." | ||
) | ||
|
||
serializer.save(project_id=project_id) | ||
|
||
def perform_update(self, serializer): | ||
project_id = self.kwargs["project_pk"] | ||
serializer.save(project_id=project_id) | ||
model_class = NewRelicConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.rudderstack.models import RudderstackConfiguration | ||
from integrations.rudderstack.serializers import ( | ||
RudderstackConfigurationSerializer, | ||
) | ||
|
||
|
||
class RudderstackConfigurationViewSet(IntegrationCommonViewSet): | ||
class RudderstackConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = RudderstackConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = RudderstackConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.segment.models import SegmentConfiguration | ||
from integrations.segment.serializers import SegmentConfigurationSerializer | ||
|
||
|
||
class SegmentConfigurationViewSet(IntegrationCommonViewSet): | ||
class SegmentConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = SegmentConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = SegmentConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from integrations.common.views import IntegrationCommonViewSet | ||
from integrations.common.views import EnvironmentIntegrationCommonViewSet | ||
from integrations.webhook.models import WebhookConfiguration | ||
from integrations.webhook.serializers import WebhookConfigurationSerializer | ||
|
||
|
||
class WebhookConfigurationViewSet(IntegrationCommonViewSet): | ||
class WebhookConfigurationViewSet(EnvironmentIntegrationCommonViewSet): | ||
serializer_class = WebhookConfigurationSerializer | ||
model_class = WebhookConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from integrations.amplitude.models import AmplitudeConfiguration | ||
|
||
|
||
@pytest.fixture() | ||
def deleted_amplitude_integration(environment): | ||
amplitude_configuration = AmplitudeConfiguration.objects.create( | ||
environment=environment, api_key="some-key" | ||
) | ||
amplitude_configuration.delete() | ||
return amplitude_configuration |
40 changes: 40 additions & 0 deletions
40
api/tests/unit/integrations/amplitude/test_unit_amplitude_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
|
||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
def test_create_amplitude_integration(environment, admin_client): | ||
# Given | ||
url = reverse( | ||
"api-v1:environments:integrations-amplitude-list", args=[environment.api_key] | ||
) | ||
|
||
# When | ||
response = admin_client.post( | ||
path=url, | ||
data=json.dumps({"api_key": "some-key"}), | ||
content_type="application/json", | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_201_CREATED | ||
|
||
|
||
def test_create_amplitude_integration_in_environment_with_deleted_integration( | ||
environment, admin_client, deleted_amplitude_integration | ||
): | ||
# Given | ||
url = reverse( | ||
"api-v1:environments:integrations-amplitude-list", args=[environment.api_key] | ||
) | ||
|
||
# When | ||
response = admin_client.post( | ||
path=url, | ||
data=json.dumps({"api_key": "some-key"}), | ||
content_type="application/json", | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_201_CREATED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from integrations.datadog.models import DataDogConfiguration | ||
|
||
|
||
@pytest.fixture() | ||
def deleted_datadog_configuration(project): | ||
configuration = DataDogConfiguration.objects.create( | ||
project=project, api_key="some-key" | ||
) | ||
configuration.delete() | ||
return configuration |
27 changes: 27 additions & 0 deletions
27
api/tests/unit/integrations/datadog/test_unit_datadog_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
|
||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
def test_create_datadog_configuration_in_project_with_deleted_configuration( | ||
admin_client, project, deleted_datadog_configuration | ||
): | ||
# Given | ||
url = reverse("api-v1:projects:integrations-datadog-list", args=[project.id]) | ||
|
||
api_key, base_url = "some-key", "https://api.newrelic.com/" | ||
|
||
# When | ||
response = admin_client.post( | ||
path=url, | ||
data=json.dumps({"api_key": api_key, "base_url": base_url}), | ||
content_type="application/json", | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_201_CREATED | ||
|
||
response_json = response.json() | ||
assert response_json["api_key"] == api_key | ||
assert response_json["base_url"] == base_url |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from integrations.new_relic.models import NewRelicConfiguration | ||
|
||
|
||
@pytest.fixture() | ||
def deleted_newrelic_configuration(project): | ||
configuration = NewRelicConfiguration.objects.create( | ||
project=project, api_key="some-key" | ||
) | ||
configuration.delete() | ||
return configuration |
28 changes: 28 additions & 0 deletions
28
api/tests/unit/integrations/newrelic/test_unit_newrelic_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
def test_create_newrelic_configuration_in_project_with_deleted_configuration( | ||
admin_client, project, deleted_newrelic_configuration | ||
): | ||
# Given | ||
url = reverse("api-v1:projects:integrations-new-relic-list", args=[project.id]) | ||
|
||
api_key, base_url, app_id = "some-key", "https://api.newrelic.com/", "1" | ||
|
||
# When | ||
response = admin_client.post( | ||
path=url, | ||
data=json.dumps({"api_key": api_key, "base_url": base_url, "app_id": app_id}), | ||
content_type="application/json", | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_201_CREATED | ||
|
||
response_json = response.json() | ||
assert response_json["api_key"] == api_key | ||
assert response_json["base_url"] == base_url | ||
assert response_json["app_id"] == app_id |