Skip to content

Commit

Permalink
Merge pull request #385 from DalgoT4D/update-tests
Browse files Browse the repository at this point in the history
Update test script
  • Loading branch information
Ishankoradia authored Dec 11, 2023
2 parents 5d6cffd + 37f54a7 commit 702d000
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 339 deletions.
47 changes: 47 additions & 0 deletions ddpui/api/client/prefect_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,3 +1135,50 @@ def get_prefect_transformation_tasks(request):
)

return org_tasks


@prefectapi.delete("/tasks/transform/", auth=auth.CanManagePipelines())
def delete_prefect_transformation_tasks(request):
"""delete tasks and related objects for an org"""
orguser: OrgUser = request.orguser

secret_block = OrgPrefectBlockv1.objects.filter(
org=orguser.org,
block_type=SECRET,
).first()
if secret_block:
logger.info("deleting secret block %s", secret_block.block_name)
prefect_service.delete_secret_block(secret_block.block_id)
secret_block.delete()

cli_profile_block = OrgPrefectBlockv1.objects.filter(
org=orguser.org,
block_type=DBTCLIPROFILE,
).first()
if cli_profile_block:
logger.info("deleting cli profile block %s", cli_profile_block.block_name)
prefect_service.delete_dbt_cli_profile_block(cli_profile_block.block_id)
cli_profile_block.delete()

org_tasks = OrgTask.objects.filter(org=orguser.org).all()

for org_task in org_tasks:
if org_task.task.slug == TASK_DBTRUN:
dataflow_orgtask = DataflowOrgTask.objects.filter(orgtask=org_task).first()
if dataflow_orgtask:
# delete the manual deployment for this
dataflow = dataflow_orgtask.dataflow
logger.info("deleting manual deployment for dbt run")
# do this in try catch because it can fail & throw error
try:
prefect_service.delete_deployment_by_id(dataflow.deployment_id)
except Exception:
pass
logger.info("FINISHED deleting manual deployment for dbt run")
logger.info("deleting OrgDataFlowv1")
dataflow.delete()
logger.info("deleting DataflowOrgTask")
dataflow_orgtask.delete()

logger.info("deleting org task %s", org_task.task.slug)
org_task.delete()
2 changes: 0 additions & 2 deletions ddpui/api/client/user_org_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
OrgWarehouseSchema,
OrgPrefectBlock,
OrgDataFlow,
OrgDataFlowv1,
OrgPrefectBlockv1,
)
from ddpui.models.org_user import (
AcceptInvitationSchema,
Expand Down
9 changes: 6 additions & 3 deletions ddpui/ddpprefect/prefect_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ def update_dbt_core_block_schema(block_name: str, target_configs_schema: str):


# ================================================================================================


def create_dbt_cli_profile_block(
block_name: str,
profilename: str,
Expand All @@ -346,6 +344,11 @@ def create_dbt_cli_profile_block(
return response


def delete_dbt_cli_profile_block(block_id) -> None:
"""Delete dbt cli profile block in prefect"""
prefect_delete_a_block(block_id)


# ================================================================================================


Expand All @@ -359,7 +362,7 @@ def create_secret_block(secret_block: PrefectSecretBlockCreate):


def delete_secret_block(block_id) -> None:
"""Delete airbyte connection block in prefect"""
"""Delete secret block in prefect"""
prefect_delete_a_block(block_id)


Expand Down
Loading

0 comments on commit 702d000

Please sign in to comment.