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