From 9d5d48aaab12eef18fe208e428b69eb59901f8c3 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Wed, 18 Oct 2023 14:25:34 +0530 Subject: [PATCH] Tests and script for admin subscription creation --- scripts/python/create-admin-subscriptions.py | 13 +++++++++++++ tests/test_fyle/test_tasks.py | 6 +++++- tests/test_workspaces/test_tasks.py | 17 +++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 scripts/python/create-admin-subscriptions.py diff --git a/scripts/python/create-admin-subscriptions.py b/scripts/python/create-admin-subscriptions.py new file mode 100644 index 00000000..9021649c --- /dev/null +++ b/scripts/python/create-admin-subscriptions.py @@ -0,0 +1,13 @@ +# Create admin subscriptions for existing workspaces + +from apps.workspaces.tasks import async_create_admin_subcriptions +from apps.workspaces.models import Workspace + +workspaces = Workspace.objects.all() + +for workspace in workspaces: + try: + async_create_admin_subcriptions(workspace.id) + except Exception as e: + print('Error while creating admin subscriptions for workspace - {} with ID - {}'.format(workspace.name, workspace.id)) + print(e.__dict__) diff --git a/tests/test_fyle/test_tasks.py b/tests/test_fyle/test_tasks.py index 8dcb4d7b..222ddee2 100644 --- a/tests/test_fyle/test_tasks.py +++ b/tests/test_fyle/test_tasks.py @@ -7,7 +7,11 @@ import pytest from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings -from apps.fyle.tasks import create_expense_groups, post_accounting_export_summary, import_and_export_expenses +from apps.fyle.tasks import ( + create_expense_groups, + post_accounting_export_summary, + import_and_export_expenses +) from apps.fyle.actions import mark_expenses_as_skipped from apps.tasks.models import TaskLog from apps.workspaces.models import FyleCredential, Workspace diff --git a/tests/test_workspaces/test_tasks.py b/tests/test_workspaces/test_tasks.py index e54dfe7d..0949d843 100644 --- a/tests/test_workspaces/test_tasks.py +++ b/tests/test_workspaces/test_tasks.py @@ -3,8 +3,13 @@ from apps.fyle.models import ExpenseGroupSettings from apps.tasks.models import TaskLog from apps.workspaces.models import WorkspaceGeneralSettings, WorkspaceSchedule -from apps.workspaces.tasks import run_email_notification, run_sync_schedule, \ - schedule_sync, async_add_admins_to_workspace +from apps.workspaces.tasks import ( + run_email_notification, + run_sync_schedule, + schedule_sync, + async_add_admins_to_workspace, + async_create_admin_subcriptions +) from apps.users.models import User from tests.test_workspaces.fixtures import data @@ -102,3 +107,11 @@ def test_email_notification(db): attribute.save() run_email_notification(workspace_id=workspace_id) + + +def test_async_create_admin_subcriptions(db, mocker): + mocker.patch( + 'fyle.platform.apis.v1beta.admin.Subscriptions.post', + return_value={} + ) + async_create_admin_subcriptions(3)