diff --git a/weni/internal/tickets/serializers.py b/weni/internal/tickets/serializers.py index 325224453..acfb0a376 100644 --- a/weni/internal/tickets/serializers.py +++ b/weni/internal/tickets/serializers.py @@ -15,7 +15,7 @@ class TicketerConfigSerializer(serializers.Serializer): class TicketerSerializer(serializers.ModelSerializer): - org = weni_serializers.OrgUUIDRelatedField(required=True) + org = weni_serializers.ProjectUUIDRelatedField(required=True) config = TicketerConfigSerializer(required=True) class Meta: @@ -28,6 +28,7 @@ def create(self, validated_data): validated_data["created_by"] = user validated_data["modified_by"] = user + validated_data["org"] = validated_data["org"] return super().create(validated_data) diff --git a/weni/internal/tickets/tests/test_views.py b/weni/internal/tickets/tests/test_views.py index 1d4693c57..4ecd1211f 100644 --- a/weni/internal/tickets/tests/test_views.py +++ b/weni/internal/tickets/tests/test_views.py @@ -5,18 +5,22 @@ from rest_framework.test import APIRequestFactory, force_authenticate from rest_framework.permissions import AllowAny from rest_framework import status +from django.contrib.auth.models import User from temba.tests import TembaTest from temba.tickets.models import Ticketer from temba.tickets.types.rocketchat import RocketChatType from weni.internal.tickets import views -from weni.internal.models import TicketerQueue +from weni.internal.models import Project, TicketerQueue class TicketerQueueViewTestMixin(object): action: dict def setUp(self): + admin = User.objects.create_user(username="testuser", password="123", email="test@weni.ai", is_superuser=True) + + project = Project.objects.create(name="Test", timezone="Africa/Kigali", created_by=admin, modified_by=admin) self.fake_chats_uuid = uuid4() self.factory = APIRequestFactory() self.view = views.TicketerQueueViewSet @@ -24,11 +28,11 @@ def setUp(self): super().setUp() - self.ticketer = Ticketer.create(self.org, self.user, RocketChatType.slug, "Email (bob@acme.com)", {}) + self.ticketer = Ticketer.create(project, self.user, RocketChatType.slug, "Email (bob@acme.com)", {}) self.queue = TicketerQueue.objects.create( created_by=self.user, modified_by=self.user, - org=self.org, + org=project.org, name="Fake Name", uuid=self.fake_chats_uuid, ticketer=self.ticketer, diff --git a/weni/serializers/__init__.py b/weni/serializers/__init__.py index a53c70a53..83ae694ed 100644 --- a/weni/serializers/__init__.py +++ b/weni/serializers/__init__.py @@ -1 +1 @@ -from weni.serializers.fields import UserEmailRelatedField, OrgUUIDRelatedField # noqa: F401 +from weni.serializers.fields import UserEmailRelatedField, OrgUUIDRelatedField, ProjectUUIDRelatedField # noqa: F401