Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete actions after deleting IntegratedFeature #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions nexus/usecases/projects/delete.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
from nexus.usecases.projects.retrieve import get_integrated_feature

from nexus.projects.models import IntegratedFeature
from nexus.usecases.actions.delete import DeleteFlowDTO, DeleteFlowsUseCase
from nexus.usecases.projects.get_by_uuid import get_project_by_uuid
from nexus.usecases.projects.retrieve import get_integrated_feature


def delete_integrated_feature(
project_uuid: str,
feature_uuid: str
feature_uuid: str,
delete_actions: bool = True
) -> bool:
try:
integrated_feature = get_integrated_feature(project_uuid, feature_uuid)
if delete_actions:
for action in integrated_feature.current_version_setup:
delete_integrated_action(
project_uuid=project_uuid,
action_uuid=action.get("root_flow_uuid")
)
integrated_feature.delete()
return True
except IntegratedFeature.DoesNotExist:
raise ValueError("IntegratedFeature does not exists")


def delete_integrated_action(project_uuid: str, action_uuid: str):
dto = DeleteFlowDTO(flow_uuid=action_uuid)

project = get_project_by_uuid(project_uuid)
usecase = DeleteFlowsUseCase()
usecase.hard_delete_flow(
flow_dto=dto,
project=project,
)
22 changes: 22 additions & 0 deletions nexus/usecases/projects/tests/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@

from nexus.usecases.projects.tests.project_factory import IntegratedFeatureFactory
from nexus.usecases.projects.delete import delete_integrated_feature
from nexus.usecases.intelligences.create import create_base_brain_structure

from nexus.usecases.intelligences.get_by_uuid import get_default_content_base_by_project
from nexus.actions.models import Flow


class TestDeleteIntegratedFeature(TestCase):

def setUp(self) -> None:
self.integrated_feature = IntegratedFeatureFactory()
self.project = self.integrated_feature.project
self.integrated_intelligence = create_base_brain_structure(self.project)
self.content_base = get_default_content_base_by_project(str(self.project.uuid))
actions = self.integrated_feature.current_version_setup

self.flow_list = []
for action in actions:
self.flow_list.append(
Flow.objects.create(
uuid=str(action.get("root_flow_uuid")),
name=action.get("name"),
prompt=action.get("prompt"),
content_base=self.content_base,
)
)

def test_delete_integrated_feature(self):
self.assertTrue(
Expand All @@ -18,6 +37,9 @@ def test_delete_integrated_feature(self):
feature_uuid=self.integrated_feature.feature_uuid
)
)
with self.assertRaises(Flow.DoesNotExist):
for flow in self.flow_list:
Flow.objects.get(uuid=flow.uuid)

def test_integrated_feature_does_not_exists(self):
with self.assertRaises(ValueError):
Expand Down
Loading