Skip to content

Commit

Permalink
Notifies the project in flows when there are changes in the Vtex App …
Browse files Browse the repository at this point in the history
…linked to the project
  • Loading branch information
elitonzky committed Dec 5, 2023
1 parent eeb50f4 commit 229fcfa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
13 changes: 5 additions & 8 deletions marketplace/clients/flows/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Client for connection with flows"""


from django.conf import settings
from marketplace.clients.base import RequestClient

Expand Down Expand Up @@ -53,14 +51,13 @@ def update_config(self, data, flow_object_uuid):
)
return response

def notify_vtex_app_creation(self, project_uuid, user_email):
url = f"{self.base_url}/internals/orgs/{project_uuid}/update-vtex/"
def update_vtex_integration_status(self, project_uuid, user_email, action):
url = f"{self.base_url}/api/v2/internals/orgs/{project_uuid}/update-vtex/"
payload = {"user_email": user_email}

self.make_request(
url,
method="POST",
url=url,
method=action,
headers=self.authentication_instance.headers,
data=payload,
json=payload,
)
return True
23 changes: 21 additions & 2 deletions marketplace/core/types/ecommerce/vtex/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from marketplace.applications.models import App
from marketplace.core.types.ecommerce.vtex.views import VtexViewSet
from marketplace.core.types.ecommerce.vtex.type import VtexType
from marketplace.clients.flows.client import FlowsClient


apptype = VtexType()
Expand All @@ -35,13 +36,18 @@ def configure(self, app, credentials, wpp_cloud_uuid):
return app


class MockFlowsService:
def update_vtex_integration_status(self, project_uuid, user_email, action):
return True


class SetUpService(APIBaseTestCase):
view_class = VtexViewSet

def setUp(self):
super().setUp()

# Mock service
# Mock vtex service
self.mock_service = MockVtexService()
patcher = patch.object(
self.view_class,
Expand All @@ -52,6 +58,19 @@ def setUp(self):
self.addCleanup(patcher.stop)
patcher.start()

# Mock FlowsClient
self.mock_flows_client = Mock(spec=FlowsClient)
self.mock_flows_service = MockFlowsService()
self.mock_flows_service.flows_client = self.mock_flows_client

patcher_flows = patch.object(
self.view_class,
"flows_service",
PropertyMock(return_value=self.mock_flows_service),
)
self.addCleanup(patcher_flows.stop)
patcher_flows.start()


class CreateVtexAppTestCase(SetUpService):
url = reverse("vtex-app-list")
Expand Down Expand Up @@ -166,7 +185,7 @@ def test_retrieve_app_data(self):
self.assertEqual(response.json["config"], {})


class DeleteVtexAppTestCase(APIBaseTestCase):
class DeleteVtexAppTestCase(SetUpService):
view_class = VtexViewSet

@property
Expand Down
9 changes: 6 additions & 3 deletions marketplace/core/types/ecommerce/vtex/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def create(self, request, *args, **kwargs):
app = self.get_app()
try:
updated_app = self.service.configure(app, credentials, wpp_cloud_uuid)
# self.flows_service.notify_vtex_app_creation(
# app.project_uuid, app.created_by.email
# )
self.flows_service.update_vtex_integration_status(
app.project_uuid, app.created_by.email, action="POST"
)
return Response(
data=self.get_serializer(updated_app).data,
status=status.HTTP_201_CREATED,
Expand All @@ -72,4 +72,7 @@ def create(self, request, *args, **kwargs):
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
self.flows_service.update_vtex_integration_status(
instance.project_uuid, instance.created_by.email, action="DELETE"
)
return Response(status=status.HTTP_204_NO_CONTENT)
6 changes: 4 additions & 2 deletions marketplace/services/flows/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ class FlowsService:
def __init__(self, client):
self.client = client

Check warning on line 3 in marketplace/services/flows/service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/flows/service.py#L3

Added line #L3 was not covered by tests

def notify_vtex_app_creation(self, project_uuid, user_email):
return self.client.notify_vtex_app_creation(project_uuid, user_email)
def update_vtex_integration_status(self, project_uuid, user_email, action):
return self.client.update_vtex_integration_status(

Check warning on line 6 in marketplace/services/flows/service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/flows/service.py#L6

Added line #L6 was not covered by tests
project_uuid, user_email, action
)

0 comments on commit 229fcfa

Please sign in to comment.