Skip to content

Commit

Permalink
feature: migrate endpoints from connect client to flows client
Browse files Browse the repository at this point in the history
  • Loading branch information
elitonzky committed Jun 30, 2023
1 parent 1d2e278 commit 03620e3
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 198 deletions.
4 changes: 2 additions & 2 deletions marketplace/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ProjectAuthorizationSerializer,
UserPermissionSerializer,
)
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient
from .models import ProjectAuthorization


Expand Down Expand Up @@ -90,7 +90,7 @@ def get(self, request: "Request") -> Response:
dict(detail="The project-uuid needs to be sent in headers!")
)

client = ConnectProjectClient()
client = FlowsClient()
response = client.get_user_api_token(request.user.email, project_uuid)

return Response(response.json(), status=response.status_code)
147 changes: 0 additions & 147 deletions marketplace/connect/client.py

This file was deleted.

4 changes: 2 additions & 2 deletions marketplace/core/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class ValidateAppCodeExistsTestCase(TestCase):
@patch("marketplace.connect.client.ConnectProjectClient.detail_channel_type")
@patch("marketplace.flows.client.FlowsClient.list_channel_types")
def test_invalid_app_code(self, mock_list_detail_channel_type):
response_data = None
mock_response = Mock()
Expand All @@ -27,7 +27,7 @@ def test_valid_app_code(self):
value = "wwc"
validate_app_code_exists(value)

@patch("marketplace.connect.client.ConnectProjectClient.detail_channel_type")
@patch("marketplace.flows.client.FlowsClient.list_channel_types")
def test_valid_generic_app_code(self, mock_list_detail_channel_type):
response_data = {
"attributes": {
Expand Down
4 changes: 2 additions & 2 deletions marketplace/core/types/channels/facebook/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from marketplace.core.serializers import AppTypeBaseSerializer
from marketplace.applications.models import App
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient


class FacebookSerializer(AppTypeBaseSerializer):
Expand Down Expand Up @@ -48,7 +48,7 @@ def validate(self, attrs: dict):

def _create_channel(self, attrs: dict, app: App) -> str:
user = self.context.get("request").user
client = ConnectProjectClient()
client = FlowsClient()

payload = {
"user_access_token": attrs.get("user_access_token"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def view(self):
return self.view_class.as_view({"patch": "configure"})

@patch(
"marketplace.core.types.channels.facebook.serializers.ConnectProjectClient.create_channel"
"marketplace.core.types.channels.facebook.serializers.FlowsClient.create_channel"
)
def test_configure_facebook_success(self, mock_create_external_service):
data = {
Expand Down
4 changes: 2 additions & 2 deletions marketplace/core/types/channels/generic/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from marketplace.applications.models import App
from marketplace.core.serializers import AppTypeBaseSerializer
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient


class GenericChannelSerializer(AppTypeBaseSerializer):
Expand Down Expand Up @@ -49,7 +49,7 @@ def _create_channel(self, attrs: dict, app: App) -> str:
request = self.context.get("request")
user = request.user
channeltype_code = app.config.get("channel_code")
client = ConnectProjectClient()
client = FlowsClient()
return client.create_channel(
user.email, app.project_uuid, attrs, channeltype_code.upper()
)
Expand Down
2 changes: 1 addition & 1 deletion marketplace/core/types/channels/generic/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def view(self):
return self.view_class.as_view({"patch": "configure"})

@patch(
"marketplace.core.types.channels.generic.serializers.ConnectProjectClient.create_channel"
"marketplace.core.types.channels.generic.serializers.FlowsClient.create_channel"
)
def test_configure_channel_success(self, mock_configure):
mock_configure.return_value = {"channelUuid": str(uuid.uuid4())}
Expand Down
4 changes: 2 additions & 2 deletions marketplace/core/types/channels/instagram/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from marketplace.core.serializers import AppTypeBaseSerializer
from marketplace.applications.models import App
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient


class InstagramSerializer(AppTypeBaseSerializer):
Expand Down Expand Up @@ -49,7 +49,7 @@ def validate(self, attrs: dict):

def _create_channel(self, attrs: dict, app: App) -> str:
user = self.context.get("request").user
client = ConnectProjectClient()
client = FlowsClient()

payload = {
"user_access_token": attrs.get("user_access_token"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def view(self):
return self.view_class.as_view({"patch": "configure"})

@patch(
"marketplace.core.types.channels.instagram.serializers.ConnectProjectClient.create_channel"
"marketplace.core.types.channels.instagram.serializers.FlowsClient.create_channel"
)
def test_configure_instagram_success(self, mock_create_external_service):
data = {
Expand Down
4 changes: 2 additions & 2 deletions marketplace/core/types/channels/telegram/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from marketplace.core.serializers import AppTypeBaseSerializer
from marketplace.applications.models import App
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient


class TelegramSerializer(AppTypeBaseSerializer):
Expand Down Expand Up @@ -42,7 +42,7 @@ def validate(self, attrs: dict):

def _create_channel(self, attrs: dict, app: App) -> str:
user = self.context.get("request").user
client = ConnectProjectClient()
client = FlowsClient()
return client.create_channel(
user.email,
app.project_uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def view(self):
return self.view_class.as_view({"patch": "configure"})

@patch(
"marketplace.core.types.channels.telegram.serializers.ConnectProjectClient.create_channel"
"marketplace.core.types.channels.telegram.serializers.FlowsClient.create_channel"
)
def test_configure_telegram_success(self, mock_create_external_service):
data = {
Expand Down
4 changes: 2 additions & 2 deletions marketplace/core/types/channels/weni_web_chat/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from marketplace.core.storage import AppStorage
from . import type as type_

from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient


class WeniWebChatSerializer(AppTypeBaseSerializer):
Expand Down Expand Up @@ -117,7 +117,7 @@ def _create_channel(self) -> str:
name = f"{type_.WeniWebChatType.name} - #{self.app.id}"
data = {"name": name, "base_url": settings.SOCKET_BASE_URL}

client = ConnectProjectClient()
client = FlowsClient()
return client.create_channel(
user.email, self.app.project_uuid, data, self.app.flows_type_code
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ def setUp(self):
def view(self):
return self.view_class.as_view({"patch": "configure"})

@patch(
"marketplace.core.types.channels.weni_web_chat.serializers.ConnectProjectClient"
)
@patch("marketplace.core.types.channels.weni_web_chat.serializers.FlowsClient")
@patch(
"marketplace.core.types.channels.weni_web_chat.serializers.AppStorage",
MockAppStorage,
Expand Down
5 changes: 3 additions & 2 deletions marketplace/core/types/channels/whatsapp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from marketplace.celery import app as celery_app
from marketplace.core.types import APPTYPES
from marketplace.applications.models import App
from marketplace.connect.client import ConnectProjectClient
from marketplace.flows.client import FlowsClient

from .apis import FacebookWABAApi, FacebookPhoneNumbersAPI
from ..whatsapp_base.exceptions import FacebookApiException

Expand All @@ -26,7 +27,7 @@
@celery_app.task(name="sync_whatsapp_apps")
def sync_whatsapp_apps():
apptype = APPTYPES.get("wpp")
client = ConnectProjectClient()
client = FlowsClient()
channels = client.list_channels(apptype.flows_type_code)

redis = get_redis_connection()
Expand Down
10 changes: 5 additions & 5 deletions marketplace/core/types/channels/whatsapp/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _get_mock_value(
]

@patch("marketplace.core.types.channels.whatsapp.tasks.get_redis_connection")
@patch("marketplace.connect.client.ConnectProjectClient.list_channels")
@patch("marketplace.flows.client.FlowsClient.list_channels")
def test_create_new_whatsapp_app(
self, list_channel_mock: "MagicMock", mock_redis
) -> None:
Expand All @@ -91,7 +91,7 @@ def test_create_new_whatsapp_app(
self.assertTrue(App.objects.filter(project_uuid=project_uuid).exists())

@patch("marketplace.core.types.channels.whatsapp.tasks.get_redis_connection")
@patch("marketplace.connect.client.ConnectProjectClient.list_channels")
@patch("marketplace.flows.client.FlowsClient.list_channels")
def test_update_app_auth_token(
self, list_channel_mock: "MagicMock", mock_redis
) -> None:
Expand All @@ -108,7 +108,7 @@ def test_update_app_auth_token(
self.assertEqual(app.config.get("auth_token"), "54321")

@patch("marketplace.core.types.channels.whatsapp.tasks.get_redis_connection")
@patch("marketplace.connect.client.ConnectProjectClient.list_channels")
@patch("marketplace.flows.client.FlowsClient.list_channels")
def test_channel_migration_from_wpp_cloud_to_wpp(
self, list_channel_mock: "MagicMock", mock_redis
) -> None:
Expand All @@ -119,7 +119,7 @@ def test_channel_migration_from_wpp_cloud_to_wpp(
sync_whatsapp_apps()

@patch("marketplace.core.types.channels.whatsapp.tasks.get_redis_connection")
@patch("marketplace.connect.client.ConnectProjectClient.list_channels")
@patch("marketplace.flows.client.FlowsClient.list_channels")
def test_task_that_was_executed(
self, list_channel_mock: "MagicMock", mock_redis
) -> None:
Expand All @@ -130,7 +130,7 @@ def test_task_that_was_executed(
sync_whatsapp_apps()

@patch("marketplace.core.types.channels.whatsapp.tasks.get_redis_connection")
@patch("marketplace.connect.client.ConnectProjectClient.list_channels")
@patch("marketplace.flows.client.FlowsClient.list_channels")
def test_skipping_wpp_demo(
self, list_channel_mock: "MagicMock", mock_redis
) -> None:
Expand Down
Loading

0 comments on commit 03620e3

Please sign in to comment.