Skip to content

Commit

Permalink
POST integrations/ after completing onboarding (#473)
Browse files Browse the repository at this point in the history
* POST integrations/ after completing onboarding

* fix lint
  • Loading branch information
ashwin1111 authored Sep 1, 2023
1 parent b4c464c commit f04ce06
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/fyle/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def post_request(url, body, refresh_token=None):

response = requests.post(url, headers=api_headers, data=body)

if response.status_code == 200:
if response.status_code in [200, 201]:
return json.loads(response.text)
else:
raise Exception(response.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def update(self, instance, validated):
if instance.onboarding_state == 'ADVANCED_CONFIGURATION':
instance.onboarding_state = 'COMPLETE'
instance.save()
AdvancedConfigurationsTriggers.post_to_integration_settings(instance.id)

return instance

Expand Down
32 changes: 31 additions & 1 deletion apps/workspaces/apis/advanced_configurations/triggers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import logging
import json
from datetime import datetime

from django.conf import settings

from apps.fyle.helpers import post_request
from apps.mappings.queue import schedule_bill_payment_creation
from apps.quickbooks_online.queue import schedule_qbo_objects_status_sync, schedule_reimbursements_sync
from apps.workspaces.models import WorkspaceGeneralSettings
from apps.workspaces.models import WorkspaceGeneralSettings, FyleCredential

logger = logging.getLogger(__name__)
logger.level = logging.INFO


class AdvancedConfigurationsTriggers:
Expand All @@ -18,3 +28,23 @@ def run_workspace_general_settings_triggers(workspace_general_settings_instance:
schedule_qbo_objects_status_sync(sync_qbo_to_fyle_payments=workspace_general_settings_instance.sync_qbo_to_fyle_payments, workspace_id=workspace_general_settings_instance.workspace.id)

schedule_reimbursements_sync(sync_qbo_to_fyle_payments=workspace_general_settings_instance.sync_qbo_to_fyle_payments, workspace_id=workspace_general_settings_instance.workspace.id)

@staticmethod
def post_to_integration_settings(workspace_id: int):
"""
Post to integration settings
"""
refresh_token = FyleCredential.objects.get(workspace_id=workspace_id).refresh_token
url = '{}/integrations/'.format(settings.INTEGRATIONS_SETTINGS_API)
payload = {
'tpa_id': settings.FYLE_CLIENT_ID,
'tpa_name': 'Fyle Quickbooks Integration',
'type': 'ACCOUNTING',
'is_active': True,
'connected_at': datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')
}

try:
post_request(url, json.dumps(payload), refresh_token)
except Exception as error:
logger.error(error)
1 change: 1 addition & 0 deletions docker-compose-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
ENCRYPTION_KEY: ${ENCRYPTION_KEY}
E2E_TESTS_CLIENT_SECRET: ${E2E_TESTS_CLIENT_SECRET}
E2E_TESTS_REALM_ID: ${E2E_TESTS_REALM_ID}
INTEGRATIONS_SETTINGS_API: http://localhost:8006/api
db:
image: "postgres:15"
environment:
Expand Down
1 change: 1 addition & 0 deletions fyle_qbo_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
ENCRYPTION_KEY = os.environ.get('ENCRYPTION_KEY')
E2E_TESTS_CLIENT_SECRET = os.environ.get('E2E_TESTS_CLIENT_SECRET')
E2E_TESTS_REALM_ID = os.environ.get('E2E_TESTS_REALM_ID')
INTEGRATIONS_SETTINGS_API = os.environ.get('INTEGRATIONS_SETTINGS_API')

# Cache Settings
SENDGRID_SANDBOX_MODE_IN_DEBUG = False
Expand Down
1 change: 1 addition & 0 deletions fyle_qbo_api/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
ENCRYPTION_KEY = os.environ.get('ENCRYPTION_KEY')
E2E_TESTS_CLIENT_SECRET = os.environ.get('E2E_TESTS_CLIENT_SECRET')
E2E_TESTS_REALM_ID = os.environ.get('E2E_TESTS_REALM_ID')
INTEGRATIONS_SETTINGS_API = os.environ.get('INTEGRATIONS_SETTINGS_API')

# Cache Settings
CACHE_EXPIRY = 3600
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ pytest-django==4.4.0
pytest-mock==3.6.1
wrapt==1.12.1
gevent==22.10.2
django-filter==21.1
15 changes: 12 additions & 3 deletions tests/test_workspaces/test_apis/test_advanced_config/test_views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import json

from apps.workspaces.models import Workspace
import pytest

from apps.workspaces.models import Workspace, FyleCredential
from tests.helper import dict_compare_keys
from tests.test_workspaces.test_apis.test_advanced_config.fixtures import data


def test_advanced_config(api_client, test_connection):

@pytest.mark.django_db()
def test_advanced_config(api_client, test_connection, db):
FyleCredential.objects.update_or_create(
workspace_id=3,
defaults={
'refresh_token': 'ey.ey.ey',
'cluster_domain': 'cluster_domain'
}
)
workspace = Workspace.objects.get(id=3)
workspace.onboarding_state = 'ADVANCED_CONFIGURATION'
workspace.save()
Expand Down

0 comments on commit f04ce06

Please sign in to comment.