From 149d726dfc2443eeb4fd4a8bff66d651f71f7516 Mon Sep 17 00:00:00 2001 From: Ashwin Thanaraj <37061471+ashwin1111@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:49:59 +0530 Subject: [PATCH] fix: support marking an integration back as active (#217) --- apps/integrations/serializers.py | 12 +++++++----- tests/test_integrations/test_views.py | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/integrations/serializers.py b/apps/integrations/serializers.py index 7350867..8d01e8c 100644 --- a/apps/integrations/serializers.py +++ b/apps/integrations/serializers.py @@ -19,13 +19,15 @@ def create(self, validated_data): """ if validated_data['is_active']: - integration = Integration.objects.create( + integration, _ = Integration.objects.update_or_create( + is_active=True, org_id=validated_data['org_id'], - org_name=validated_data['org_name'], type=validated_data['type'], - is_active=True, - tpa_id=validated_data['tpa_id'], - tpa_name=validated_data['tpa_name'] + defaults={ + 'org_name': validated_data['org_name'], + 'tpa_id': validated_data['tpa_id'], + 'tpa_name': validated_data['tpa_name'] + } ) elif not validated_data['is_active']: integration = Integration.objects.filter(org_id=validated_data['org_id'], type=validated_data['type']).first() diff --git a/tests/test_integrations/test_views.py b/tests/test_integrations/test_views.py index 90c1d23..6400538 100644 --- a/tests/test_integrations/test_views.py +++ b/tests/test_integrations/test_views.py @@ -185,3 +185,12 @@ def test_integrations_view_mark_inactive_post(api_client, mocker, access_token, assert response['is_active'] == False assert response['is_beta'] == True assert response['disconnected_at'] != None + + # Marking inactive integration back to active + payload = dict(post_integration_accounting) + + response = api_client.post(url, payload) + assert response.status_code == 201 + + response = json.loads(response.content) + assert response['is_active'] == True