From bcb0a2dce110cc55e86ab55b567a84e92ed1213e Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Mon, 8 Jul 2024 18:50:26 +0200 Subject: [PATCH] Update tests, mock android sync endpoint --- temba/channels/types/android/tests.py | 5 ++++- temba/mailroom/tests.py | 4 +++- temba/orgs/tests.py | 6 ++++-- temba/tests/mailroom.py | 3 +++ temba/triggers/tests.py | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/temba/channels/types/android/tests.py b/temba/channels/types/android/tests.py index 9e0c56ad121..eb28d3b28cb 100644 --- a/temba/channels/types/android/tests.py +++ b/temba/channels/types/android/tests.py @@ -5,13 +5,16 @@ from temba.contacts.models import URN from temba.orgs.models import Org from temba.tests import CRUDLTestMixin, TembaTest +from temba.tests.mailroom import mock_mailroom from temba.utils import get_anonymous_user from ...models import Channel class AndroidTypeTest(TembaTest, CRUDLTestMixin): - def test_claim(self): + + @mock_mailroom + def test_claim(self, mr_mocks): # remove our explicit country so it needs to be derived from channels self.org.country = None self.org.timezone = "UTC" diff --git a/temba/mailroom/tests.py b/temba/mailroom/tests.py index 1a39cb6faee..c5ebd38e478 100644 --- a/temba/mailroom/tests.py +++ b/temba/mailroom/tests.py @@ -1,4 +1,5 @@ from datetime import timedelta +from unittest.mock import patch from django_redis import get_redis_connection @@ -71,7 +72,8 @@ def test_queue_contact_import_batch(self): }, ) - def test_queue_interrupt_channel(self): + @patch("temba.channels.models.Channel.trigger_sync") + def test_queue_interrupt_channel(self, mock_trigger_sync): self.channel.release(self.admin) self.assert_org_queued(self.org, "batch") diff --git a/temba/orgs/tests.py b/temba/orgs/tests.py index db50c4a4c12..7dad90260f1 100644 --- a/temba/orgs/tests.py +++ b/temba/orgs/tests.py @@ -671,7 +671,8 @@ def test_ui_management(self): self.editor.refresh_from_db() self.assertFalse(self.editor.is_active) - def test_release(self): + @mock_mailroom + def test_release(self, mr_mocks): # admin doesn't "own" any orgs self.assertEqual(0, len(self.admin.get_owned_orgs())) @@ -3381,7 +3382,8 @@ def test_update(self): self.assertEqual("", self.editor.last_name) self.assertEqual({alphas}, set(self.editor.groups.all())) - def test_delete(self): + @mock_mailroom + def test_delete(self, mr_mocks): delete_url = reverse("orgs.user_delete", args=[self.editor.id]) # this is a customer support only view diff --git a/temba/tests/mailroom.py b/temba/tests/mailroom.py index 9180d6ade26..e5ba3a2d558 100644 --- a/temba/tests/mailroom.py +++ b/temba/tests/mailroom.py @@ -187,6 +187,9 @@ def android_message(self, org, channel, phone: str, text: str, received_on): ) return {"id": msg.id, "duplicate": False} + def android_sync(self, channel, registration_id=None): + return {"id": channel.id} + @_client_method def contact_create(self, org, user, contact: mailroom.ContactSpec): return create_contact_locally( diff --git a/temba/triggers/tests.py b/temba/triggers/tests.py index dd19e7a818c..a7af95ae05d 100644 --- a/temba/triggers/tests.py +++ b/temba/triggers/tests.py @@ -12,6 +12,7 @@ from temba.flows.models import Flow from temba.schedules.models import Schedule from temba.tests import CRUDLTestMixin, TembaTest +from temba.tests.mailroom import mock_mailroom from temba.utils.views import TEMBA_MENU_SELECTION from .models import Trigger @@ -567,7 +568,8 @@ def test_menu(self): # the archived trigger not counted self.assertPageMenu(menu_url, self.user, ["Active (1)", "Archived (1)", "Messages (1)"]) - def test_create(self): + @mock_mailroom + def test_create(self, mr_mocks): create_url = reverse("triggers.trigger_create") create_new_convo_url = reverse("triggers.trigger_create_new_conversation") create_inbound_call_url = reverse("triggers.trigger_create_inbound_call")