diff --git a/breathecode/activity/tests/tasks/tests_get_attendancy_log.py b/breathecode/activity/tests/tasks/tests_get_attendancy_log.py index ed060ffe3..c43d165ac 100644 --- a/breathecode/activity/tests/tasks/tests_get_attendancy_log.py +++ b/breathecode/activity/tests/tasks/tests_get_attendancy_log.py @@ -7,8 +7,8 @@ from django.utils import timezone -from breathecode.activity.tasks import get_attendancy_log from breathecode.activity import tasks +from breathecode.activity.tasks import get_attendancy_log from breathecode.utils import NDB from ...models import StudentActivity @@ -45,8 +45,8 @@ class MediaTestSuite(MediaTestCase): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch.object(NDB, 'fetch', MagicMock(return_value=[])) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_not_found(self): get_attendancy_log.delay(1) @@ -68,8 +68,8 @@ def test_not_found(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch.object(NDB, 'fetch', MagicMock(return_value=[])) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_syllabus_not_found(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): model = self.bc.database.create(cohort=1) @@ -100,8 +100,8 @@ def test_syllabus_not_found(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch.object(NDB, 'fetch', MagicMock(return_value=[])) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_syllabus_version_with_json_with_bad_format(self): syllabus_versions = [ { @@ -186,9 +186,9 @@ def test_syllabus_version_with_json_with_bad_format(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_student_attended_the_first_day(self): cases = [ ([get_datastore_seed(self.bc.fake.slug(), 1, {'slug': 'classroom_attendance'})], [], [1], []), @@ -266,8 +266,8 @@ def test_the_student_attended_the_first_day(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_students_attended_all_days(self): cases = [ ([ @@ -470,8 +470,8 @@ def test_the_students_attended_all_days(self): @patch('breathecode.utils.ndb.NDB.__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_students_attended_all_days__the_days_is_string(self): cases = [ ([ @@ -676,8 +676,8 @@ def test_the_students_attended_all_days__the_days_is_string(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_students_attended_all_days__duration_in_days(self): cases = [ ([ @@ -1079,8 +1079,8 @@ def test_the_students_attended_all_days__duration_in_days(self): @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_students_attended_all_days__duration_in_days__two_cohort_users(self): cases = [ ([ @@ -1480,9 +1480,9 @@ def test_the_students_attended_all_days__duration_in_days__two_cohort_users(self @patch.object(NDB, '__init__', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.activity.tasks.get_attendancy_log_per_cohort_user.delay', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_the_students_attended_all_days__duration_in_days__two_cohort_users__they_was_deleted(self): cases = [ ([ diff --git a/breathecode/activity/tests/tasks/tests_get_attendancy_log_per_cohort_user.py b/breathecode/activity/tests/tasks/tests_get_attendancy_log_per_cohort_user.py index 747ed708c..b707da041 100644 --- a/breathecode/activity/tests/tasks/tests_get_attendancy_log_per_cohort_user.py +++ b/breathecode/activity/tests/tasks/tests_get_attendancy_log_per_cohort_user.py @@ -2,14 +2,14 @@ Test /answer """ import logging -from datetime import timedelta import random +from datetime import timedelta from unittest.mock import MagicMock, call, patch from django.utils import timezone -from breathecode.activity.tasks import get_attendancy_log_per_cohort_user from breathecode.activity import tasks +from breathecode.activity.tasks import get_attendancy_log_per_cohort_user from breathecode.utils import NDB from ..mixins import MediaTestCase @@ -43,8 +43,8 @@ class MediaTestSuite(MediaTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_not_found(self): get_attendancy_log_per_cohort_user.delay(1) @@ -62,8 +62,8 @@ def test_not_found(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_cohort_user(self): cohort = {'history_log': random.choice(['', None, {}, []])} model = self.bc.database.create(cohort=cohort, cohort_user=1) @@ -94,8 +94,8 @@ def test_with_cohort_user(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_cohort_user__user_do_not_assist(self): utc_now = timezone.now() day1 = str(random.randint(1, 9)) @@ -159,8 +159,8 @@ def test_with_cohort_user__user_do_not_assist(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_cohort_user__user_assist(self): utc_now = timezone.now() day1 = str(random.randint(1, 9)) @@ -226,8 +226,8 @@ def test_with_cohort_user__user_assist(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_cohort_user__with_bad_user_log(self): utc_now = timezone.now() available_days = {str(random.randint(1, 9)) for _ in range(4)} diff --git a/breathecode/admissions/actions.py b/breathecode/admissions/actions.py index 25c01d96e..7e49e1e6f 100644 --- a/breathecode/admissions/actions.py +++ b/breathecode/admissions/actions.py @@ -207,10 +207,10 @@ def update_asset_on_json(from_slug, to_slug, asset_type, simulate=True): s.save() if not simulate and len(findings) > 0: - syllabus_asset_slug_updated.send(sender=update_asset_on_json, - from_slug=from_slug, - to_slug=to_slug, - asset_type=asset_type) + syllabus_asset_slug_updated.send_robust(sender=update_asset_on_json, + from_slug=from_slug, + to_slug=to_slug, + asset_type=asset_type) return findings diff --git a/breathecode/admissions/models.py b/breathecode/admissions/models.py index add285993..3f2276134 100644 --- a/breathecode/admissions/models.py +++ b/breathecode/admissions/models.py @@ -162,7 +162,7 @@ def save(self, *args, **kwargs): if created: self.__old_slug = self.slug - academy_saved.send(instance=self, sender=self.__class__, created=created) + academy_saved.send_robust(instance=self, sender=self.__class__, created=created) PARTIME = 'PART-TIME' @@ -259,7 +259,7 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) - if json_modified: syllabus_version_json_updated.send(instance=self, sender=SyllabusVersion) + if json_modified: syllabus_version_json_updated.send_robust(instance=self, sender=SyllabusVersion) class SyllabusSchedule(models.Model): @@ -390,7 +390,7 @@ def save_history_log(self, *args, **kwargs): super().save(*args, **kwargs) - signals.cohort_saved.send(instance=self, sender=self.__class__, created=False) + signals.cohort_saved.send_robust(instance=self, sender=self.__class__, created=False) self._current_history_log = self.history_log @@ -406,13 +406,13 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) - signals.cohort_saved.send(instance=self, sender=self.__class__, created=created) + signals.cohort_saved.send_robust(instance=self, sender=self.__class__, created=created) if self.history_log and self.history_log != self._current_history_log: - signals.cohort_log_saved.send(instance=self, sender=self.__class__, created=created) + signals.cohort_log_saved.send_robust(instance=self, sender=self.__class__, created=created) if stage_updated: - signals.cohort_stage_updated.send(instance=self, sender=self.__class__) + signals.cohort_stage_updated.send_robust(instance=self, sender=self.__class__) self._current_history_log = self.history_log @@ -518,12 +518,12 @@ def save(self, *args, **kwargs): result = super().save(*args, **kwargs) # Call the "real" save() method. if edu_status_updated: - signals.student_edu_status_updated.send(instance=self, sender=self.__class__) + signals.student_edu_status_updated.send_robust(instance=self, sender=self.__class__) - signals.cohort_log_saved.send(instance=self, sender=self.__class__) + signals.cohort_log_saved.send_robust(instance=self, sender=self.__class__) if on_create: - signals.cohort_user_created.send(instance=self, sender=self.__class__) + signals.cohort_user_created.send_robust(instance=self, sender=self.__class__) self.__old_edu_status = self.educational_status @@ -597,7 +597,7 @@ def save(self, *args, **kwargs): self.full_clean() super().save(*args, **kwargs) - # signals.timeslot_saved.send(instance=self, sender=self.__class__, created=created) + # signals.timeslot_saved.send_robust(instance=self, sender=self.__class__, created=created) class CohortTimeSlot(TimeSlot): @@ -616,4 +616,4 @@ def save(self, *args, **kwargs): self.full_clean() super().save(*args, **kwargs) - signals.timeslot_saved.send(instance=self, sender=self.__class__, created=created) + signals.timeslot_saved.send_robust(instance=self, sender=self.__class__, created=created) diff --git a/breathecode/admissions/tests/admin/tests_add_student_tag_to_active_campaign.py b/breathecode/admissions/tests/admin/tests_add_student_tag_to_active_campaign.py index 2533557fc..b97793d91 100644 --- a/breathecode/admissions/tests/admin/tests_add_student_tag_to_active_campaign.py +++ b/breathecode/admissions/tests/admin/tests_add_student_tag_to_active_campaign.py @@ -2,9 +2,12 @@ Test /cohort/user """ from unittest.mock import MagicMock, call, patch -from breathecode.admissions.models import CohortUser -from breathecode.admissions.admin import add_student_tag_to_active_campaign + from django.http.request import HttpRequest + +from breathecode.admissions.admin import add_student_tag_to_active_campaign +from breathecode.admissions.models import CohortUser + from ..mixins import AdmissionsTestCase @@ -14,8 +17,8 @@ class CohortUserTestSuite(AdmissionsTestCase): """ @patch('breathecode.marketing.tasks.add_cohort_task_to_student.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_add_student_tag_to_active_campaign__zero_cohort_users(self): from breathecode.marketing.tasks import add_cohort_task_to_student @@ -31,8 +34,8 @@ def test_add_student_tag_to_active_campaign__zero_cohort_users(self): """ @patch('breathecode.marketing.tasks.add_cohort_task_to_student.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_add_student_tag_to_active_campaign__one_cohort_user(self): from breathecode.marketing.tasks import add_cohort_task_to_student @@ -52,8 +55,8 @@ def test_add_student_tag_to_active_campaign__one_cohort_user(self): """ @patch('breathecode.marketing.tasks.add_cohort_task_to_student.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_add_student_tag_to_active_campaign__two_cohort_users(self): from breathecode.marketing.tasks import add_cohort_task_to_student diff --git a/breathecode/admissions/tests/management/commands/tests_delete_duplicates.py b/breathecode/admissions/tests/management/commands/tests_delete_duplicates.py index 40641dda3..2462c0a1a 100644 --- a/breathecode/admissions/tests/management/commands/tests_delete_duplicates.py +++ b/breathecode/admissions/tests/management/commands/tests_delete_duplicates.py @@ -2,17 +2,18 @@ Test /academy/cohort """ from unittest.mock import MagicMock, patch + from mixer.backend.django import mixer -from ...mixins import AdmissionsTestCase from ....management.commands.delete_duplicates import Command +from ...mixins import AdmissionsTestCase class AcademyCohortTestSuite(AdmissionsTestCase): """Test /academy/cohort""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_duplicates(self): """Test /academy/cohort without auth""" model = self.generate_models(cohort=True, user=True) @@ -30,8 +31,8 @@ def test_delete_duplicates(self): # @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) # @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - # @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - # @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + # @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + # @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) # def test_delete_duplicates_with_one_student_graduated(self): # """Test /academy/cohort without auth""" # model = self.generate_models(cohort=True, user=True) @@ -57,8 +58,8 @@ def test_delete_duplicates(self): # @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) # @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) # @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - # @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - # @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + # @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + # @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) # def test_delete_duplicates_with_one_student_with_finantial_status(self): # """Test /academy/cohort without auth""" # model = self.generate_models(cohort=True, user=True) diff --git a/breathecode/admissions/tests/management/commands/tests_sync_admissions.py b/breathecode/admissions/tests/management/commands/tests_sync_admissions.py index c0dfdc948..0035568ef 100644 --- a/breathecode/admissions/tests/management/commands/tests_sync_admissions.py +++ b/breathecode/admissions/tests/management/commands/tests_sync_admissions.py @@ -9,8 +9,12 @@ from mixer.backend.django import mixer # from random import randint -from breathecode.tests.mocks import (GOOGLE_CLOUD_PATH, apply_google_cloud_blob_mock, apply_google_cloud_bucket_mock, - apply_google_cloud_client_mock) +from breathecode.tests.mocks import ( + GOOGLE_CLOUD_PATH, + apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, +) from ....management.commands.sync_admissions import Command from ....models import Cohort, CohortUser, User @@ -48,8 +52,8 @@ class AcademyCohortTestSuite(AdmissionsTestCase): """Test /academy/cohort""" @patch(LEGACY_API_PATH['get'], apply_screenshotmachine_requests_get_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_students(self): """Test /academy/cohort without auth""" cohorts = set() @@ -114,8 +118,8 @@ def test_students(self): self.assertEqual(self.count_cohort_user(), cohort_user_acc) @patch(LEGACY_API_PATH['get'], apply_screenshotmachine_requests_get_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_students_twice(self): """Test /academy/cohort without auth""" cohorts = set() @@ -181,8 +185,8 @@ def test_students_twice(self): self.assertEqual(self.count_cohort_user(), cohort_user_acc) @patch(LEGACY_API_PATH['get'], apply_screenshotmachine_requests_get_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_teachers(self): """Test /academy/cohort without auth""" cohorts = set() @@ -247,8 +251,8 @@ def test_teachers(self): self.assertEqual(self.count_cohort_user(), cohort_user_acc) @patch(LEGACY_API_PATH['get'], apply_screenshotmachine_requests_get_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_teachers_twice(self): """Test /academy/cohort without auth""" cohorts = set() diff --git a/breathecode/admissions/tests/mixins/admissions_test_case.py b/breathecode/admissions/tests/mixins/admissions_test_case.py index d70b42c28..c83b244b0 100644 --- a/breathecode/admissions/tests/mixins/admissions_test_case.py +++ b/breathecode/admissions/tests/mixins/admissions_test_case.py @@ -3,11 +3,19 @@ """ import re from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy -from rest_framework.test import APITestCase -from breathecode.tests.mixins import (GenerateModelsMixin, CacheMixin, GenerateQueriesMixin, DatetimeMixin, ICallMixin, - BreathecodeMixin) from rest_framework import status +from rest_framework.test import APITestCase + +from breathecode.tests.mixins import ( + BreathecodeMixin, + CacheMixin, + DatetimeMixin, + GenerateModelsMixin, + GenerateQueriesMixin, + ICallMixin, +) class AdmissionsTestCase(APITestCase, GenerateModelsMixin, CacheMixin, GenerateQueriesMixin, DatetimeMixin, ICallMixin, @@ -128,7 +136,7 @@ def check_cohort_user_that_not_have_role_student_can_be_teacher(self, role, upda 'watching': False, }]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def check_academy_cohort__with_data(self, models=None, deleted=False): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -157,7 +165,7 @@ def check_academy_cohort__with_data(self, models=None, deleted=False): ] # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models.sort(key=lambda x: x.cohort.kickoff_date, reverse=True) @@ -247,10 +255,10 @@ def check_academy_cohort__with_data(self, models=None, deleted=False): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), self.all_model_dict([x.cohort for x in models])) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) return models - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def check_cohort_me__with_data(self, models=None, deleted=False): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -280,7 +288,7 @@ def check_cohort_me__with_data(self, models=None, deleted=False): ] # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models.sort(key=lambda x: x.cohort.kickoff_date, reverse=True) @@ -371,5 +379,5 @@ def check_cohort_me__with_data(self, models=None, deleted=False): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), self.all_model_dict([x.cohort for x in models])) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) return models diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort.py b/breathecode/admissions/tests/urls/tests_academy_cohort.py index 756a37517..4a9bce277 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort.py @@ -3,16 +3,18 @@ """ import random import re -from unittest.mock import MagicMock, call, patch -from django.utils import timezone -from breathecode.admissions.caches import CohortCache -from breathecode.services import datetime_to_iso_format -from random import choice from datetime import datetime, timedelta +from random import choice +from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy +from django.utils import timezone from rest_framework import status +from breathecode.admissions.caches import CohortCache +from breathecode.services import datetime_to_iso_format from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + from ..mixins import AdmissionsTestCase UTC_NOW = timezone.now() @@ -86,8 +88,8 @@ class AcademyCohortTestSuite(AdmissionsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__without_authorization(self): """Test /academy/cohort without auth""" self.headers(academy=1) @@ -100,8 +102,8 @@ def test_academy_cohort__post__without_authorization(self): self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) self.assertEqual(self.all_cohort_time_slot_dict(), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__without_capability(self): """Test /cohort/:id without auth""" self.headers(academy=1) @@ -121,9 +123,9 @@ def test_academy_cohort__without_capability(self): 🔽🔽🔽 Post """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__without_profile_academy(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -138,7 +140,7 @@ def test_academy_cohort__post__without_profile_academy(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = {} @@ -152,11 +154,11 @@ def test_academy_cohort__post__without_profile_academy(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_bad_fields(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -174,7 +176,7 @@ def test_academy_cohort__post__with_bad_fields(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -192,11 +194,11 @@ def test_academy_cohort__post__with_bad_fields(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_bad_current_day(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -214,7 +216,7 @@ def test_academy_cohort__post__with_bad_current_day(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -232,11 +234,11 @@ def test_academy_cohort__post__with_bad_current_day(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__without_ending_date_or_never_ends(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -256,7 +258,7 @@ def test_academy_cohort__post__without_ending_date_or_never_ends(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -277,11 +279,11 @@ def test_academy_cohort__post__without_ending_date_or_never_ends(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_ending_date_and_never_ends_true(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -301,7 +303,7 @@ def test_academy_cohort__post__with_ending_date_and_never_ends_true(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -324,11 +326,11 @@ def test_academy_cohort__post__with_ending_date_and_never_ends_true(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__without_ending_date_and_never_ends_false(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -348,7 +350,7 @@ def test_academy_cohort__post__without_ending_date_and_never_ends_false(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -370,11 +372,11 @@ def test_academy_cohort__post__without_ending_date_and_never_ends_false(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_kickoff_date_null(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -394,7 +396,7 @@ def test_academy_cohort__post__with_kickoff_date_null(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') data = { @@ -415,15 +417,15 @@ def test_academy_cohort__post__with_kickoff_date_null(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put assigning the syllabus version 1 """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__assigning_syllabus_version_1(self): from breathecode.admissions.signals import cohort_saved @@ -443,7 +445,7 @@ def test_academy_cohort__post__assigning_syllabus_version_1(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models_dict = self.bc.database.list_of('admissions.Cohort') url = reverse_lazy('admissions:academy_cohort') @@ -463,11 +465,11 @@ def test_academy_cohort__post__assigning_syllabus_version_1(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__without_timezone(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -487,7 +489,7 @@ def test_academy_cohort__post__without_timezone(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models_dict = self.bc.database.list_of('admissions.Cohort') url = reverse_lazy('admissions:academy_cohort') @@ -545,12 +547,12 @@ def test_academy_cohort__post__without_timezone(self): self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), models_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=cohort, sender=cohort.__class__, created=True)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__kickoff_date_greater_than_ending_date(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -570,7 +572,7 @@ def test_academy_cohort__post__kickoff_date_greater_than_ending_date(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') utc_now = timezone.now() @@ -591,11 +593,11 @@ def test_academy_cohort__post__kickoff_date_greater_than_ending_date(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), []) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_timezone(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -617,7 +619,7 @@ def test_academy_cohort__post__with_timezone(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models_dict = self.bc.database.list_of('admissions.Cohort') url = reverse_lazy('admissions:academy_cohort') @@ -688,12 +690,12 @@ def test_academy_cohort__post__with_timezone(self): 'recurrency_type': model.syllabus_schedule_time_slot.recurrency_type, 'timezone': model.academy.timezone, }]) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=cohort, sender=cohort.__class__, created=True)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__with_timezone__passing_custom_timezone(self): """Test /academy/cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -715,7 +717,7 @@ def test_academy_cohort__post__with_timezone__passing_custom_timezone(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] models_dict = self.bc.database.list_of('admissions.Cohort') url = reverse_lazy('admissions:academy_cohort') @@ -786,13 +788,13 @@ def test_academy_cohort__post__with_timezone__passing_custom_timezone(self): 'recurrency_type': model.syllabus_schedule_time_slot.recurrency_type, 'timezone': 'Pacific/Pago_Pago', }]) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=cohort, sender=cohort.__class__, created=True)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__passing_all_statuses__uppercase(self): from breathecode.admissions.signals import cohort_saved @@ -813,7 +815,7 @@ def test_academy_cohort__post__passing_all_statuses__uppercase(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') @@ -869,14 +871,14 @@ def test_academy_cohort__post__passing_all_statuses__uppercase(self): cohort = self.get_cohort(1) - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=cohort, sender=cohort.__class__, created=True), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__passing_all_statuses__lowercase(self): from breathecode.admissions.signals import cohort_saved @@ -897,7 +899,7 @@ def test_academy_cohort__post__passing_all_statuses__lowercase(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') @@ -953,14 +955,14 @@ def test_academy_cohort__post__passing_all_statuses__lowercase(self): cohort = self.get_cohort(1) - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=cohort, sender=cohort.__class__, created=True), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__passing_available_as_saas_with__true(self): from breathecode.admissions.signals import cohort_saved @@ -981,7 +983,7 @@ def test_academy_cohort__post__passing_available_as_saas_with__true(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') @@ -1037,14 +1039,14 @@ def test_academy_cohort__post__passing_available_as_saas_with__true(self): cohort = self.get_cohort(1) - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=cohort, sender=cohort.__class__, created=True), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__passing_available_as_saas_with__false(self): from breathecode.admissions.signals import cohort_saved @@ -1065,7 +1067,7 @@ def test_academy_cohort__post__passing_available_as_saas_with__false(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') @@ -1121,14 +1123,14 @@ def test_academy_cohort__post__passing_available_as_saas_with__false(self): cohort = self.get_cohort(1) - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=cohort, sender=cohort.__class__, created=True), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__post__not_passing_available_as_saas(self): from breathecode.admissions.signals import cohort_saved @@ -1149,7 +1151,7 @@ def test_academy_cohort__post__not_passing_available_as_saas(self): academy_kwargs=academy_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') @@ -1204,7 +1206,7 @@ def test_academy_cohort__post__not_passing_available_as_saas(self): cohort = self.get_cohort(1) - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=cohort, sender=cohort.__class__, created=True), ]) @@ -1215,9 +1217,9 @@ def test_academy_cohort__post__not_passing_available_as_saas(self): 🔽🔽🔽 Without data """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_without_data(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1232,7 +1234,7 @@ def test_academy_cohort_without_data(self): skip_cohort=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] response = self.client.get(url) json = response.json() @@ -1246,9 +1248,9 @@ def test_academy_cohort_without_data(self): 🔽🔽🔽 With data (this method is reusable) """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data(self): """Test /cohort without auth""" self.check_academy_cohort__with_data() @@ -1257,9 +1259,9 @@ def test_academy_cohort__with_data(self): 🔽🔽🔽 Put """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__put__without_id(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1273,7 +1275,7 @@ def test_academy_cohort__put__without_id(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = {} response = self.client.put(url, data) @@ -1282,15 +1284,15 @@ def test_academy_cohort__put__without_id(self): self.assertEqual(json, {'detail': 'Missing cohort_id', 'status_code': 400}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Get """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data__with_upcoming_false(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1310,7 +1312,7 @@ def test_academy_cohort__with_data__with_upcoming_false(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) del model_dict['ending_date'] @@ -1382,11 +1384,11 @@ def test_academy_cohort__with_data__with_upcoming_false(self): del cohort_dict['kickoff_date'] self.assertEqual(cohort_dict, model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data__with_upcoming_true__without_data(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1403,7 +1405,7 @@ def test_academy_cohort__with_data__with_upcoming_true__without_data(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) base_url = reverse_lazy('admissions:academy_cohort') @@ -1416,11 +1418,11 @@ def test_academy_cohort__with_data__with_upcoming_true__without_data(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data__with_upcoming_true(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1439,7 +1441,7 @@ def test_academy_cohort__with_data__with_upcoming_true(self): cohort=cohort_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -1503,11 +1505,11 @@ def test_academy_cohort__with_data__with_upcoming_true(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data__with_bad_academy(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1524,7 +1526,7 @@ def test_academy_cohort__with_data__with_bad_academy(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -1537,11 +1539,11 @@ def test_academy_cohort__with_data__with_bad_academy(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_data_with_academy(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1561,7 +1563,7 @@ def test_academy_cohort_with_data_with_academy(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -1625,11 +1627,11 @@ def test_academy_cohort_with_data_with_academy(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_data_with_academy_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1649,7 +1651,7 @@ def test_academy_cohort_with_data_with_academy_with_comma(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -1713,11 +1715,11 @@ def test_academy_cohort_with_data_with_academy_with_comma(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_ten_datas_with_academy_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1745,7 +1747,7 @@ def test_academy_cohort_with_ten_datas_with_academy_with_comma(self): models.sort(key=lambda x: x.cohort.kickoff_date, reverse=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] self.client.force_authenticate(user=models[0]['user']) base_url = reverse_lazy('admissions:academy_cohort') @@ -1817,15 +1819,15 @@ def test_academy_cohort_with_ten_datas_with_academy_with_comma(self): del j['kickoff_date'] self.assertEqual(self_all_cohort, self_all_model) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Sort in querystring """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__with_data__with_sort(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1850,7 +1852,7 @@ def test_academy_cohort__with_data__with_sort(self): ] # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] ordened_models = sorted(models, key=lambda x: x['cohort'].slug, reverse=True) @@ -1920,11 +1922,11 @@ def test_academy_cohort__with_data__with_sort(self): del dict['ending_date'] del dict['kickoff_date'] self.assertEqual(all_cohort_dict, models_dict) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_data_with_bad_location(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1940,7 +1942,7 @@ def test_academy_cohort_with_data_with_bad_location(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -1953,11 +1955,11 @@ def test_academy_cohort_with_data_with_bad_location(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_data_with_location(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -1977,7 +1979,7 @@ def test_academy_cohort_with_data_with_location(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -2041,11 +2043,11 @@ def test_academy_cohort_with_data_with_location(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_data_with_location_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -2065,7 +2067,7 @@ def test_academy_cohort_with_data_with_location_with_comma(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort') @@ -2129,11 +2131,11 @@ def test_academy_cohort_with_data_with_location_with_comma(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_with_ten_datas_with_location_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -2164,7 +2166,7 @@ def test_academy_cohort_with_ten_datas_with_location_with_comma(self): models.sort(key=lambda x: x.cohort.kickoff_date, reverse=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] self.client.force_authenticate(user=models[0]['user']) base_url = reverse_lazy('admissions:academy_cohort') @@ -2238,11 +2240,11 @@ def test_academy_cohort_with_ten_datas_with_location_with_comma(self): self.assertEqual(self_all_cohort, self_all_model) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_delete_without_args_in_url_or_bulk(self): """Test /cohort/:id/user without auth""" from breathecode.admissions.signals import cohort_saved @@ -2254,7 +2256,7 @@ def test_academy_cohort_delete_without_args_in_url_or_bulk(self): role='potato') # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort') response = self.client.delete(url) @@ -2267,11 +2269,11 @@ def test_academy_cohort_delete_without_args_in_url_or_bulk(self): **self.model_to_dict(model, 'cohort'), }]) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_delete_in_bulk_with_students(self): """Test /cohort/:id/user without auth""" from breathecode.admissions.signals import cohort_saved @@ -2290,7 +2292,7 @@ def test_academy_cohort_delete_in_bulk_with_students(self): model = self.bc.database.create(authenticate=True, profile_academy=True, cohort_user=True, models=base) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] value = getattr(model['cohort'], field) @@ -2302,11 +2304,11 @@ def test_academy_cohort_delete_in_bulk_with_students(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_delete_in_bulk_with_one(self): """Test /cohort/:id/user without auth""" from breathecode.admissions.signals import cohort_saved @@ -2325,7 +2327,7 @@ def test_academy_cohort_delete_in_bulk_with_one(self): model = self.bc.database.create(authenticate=True, profile_academy=True, cohort=cohort_kwargs, models=base) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] value = getattr(model['cohort'], field) @@ -2335,12 +2337,12 @@ def test_academy_cohort_delete_in_bulk_with_one(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.count_cohort_user(), 0) self.assertEqual(self.count_cohort_stage(model['cohort'].id), 'DELETED') - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_delete_in_bulk_with_two(self): """Test /cohort/:id/user without auth""" from breathecode.admissions.signals import cohort_saved @@ -2370,7 +2372,7 @@ def test_academy_cohort_delete_in_bulk_with_two(self): model2 = self.bc.database.create(profile_academy=True, syllabus=True, cohort=cohort_kwargs, models=base) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] value1 = getattr(model1['cohort'], field) value1 = self.datetime_to_iso(value1) if isinstance(value1, datetime) else value1 @@ -2386,15 +2388,15 @@ def test_academy_cohort_delete_in_bulk_with_two(self): self.assertEqual(self.count_cohort_stage(model1['cohort'].id), 'DELETED') self.assertEqual(self.count_cohort_stage(model2['cohort'].id), 'DELETED') - self.assertEqual(cohort_saved.send.call_args_list, [ + self.assertEqual(cohort_saved.send_robust.call_args_list, [ call(instance=model1.cohort, sender=model1.cohort.__class__, created=False), call(instance=model2.cohort, sender=model2.cohort.__class__, created=False), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__spy_extensions(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -2409,7 +2411,7 @@ def test_academy_cohort__spy_extensions(self): skip_cohort=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] self.client.get(url) @@ -2417,10 +2419,10 @@ def test_academy_cohort__spy_extensions(self): call(['CacheExtension', 'LanguageExtension', 'LookupExtension', 'PaginationExtension', 'SortExtension']), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort__spy_extension_arguments(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -2435,7 +2437,7 @@ def test_academy_cohort__spy_extension_arguments(self): skip_cohort=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] self.client.get(url) diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort_id.py b/breathecode/admissions/tests/urls/tests_academy_cohort_id.py index 150f1f98c..45cfbe6f9 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort_id.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort_id.py @@ -9,8 +9,7 @@ from rest_framework import status from breathecode.admissions.caches import CohortCache -from breathecode.utils.api_view_extensions.api_view_extension_handlers import \ - APIViewExtensionHandlers +from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers from breathecode.utils.datetime_integer import DatetimeInteger from ..mixins import AdmissionsTestCase @@ -24,8 +23,8 @@ class AcademyCohortIdTestSuite(AdmissionsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__without_auth(self): """Test /cohort/:id without auth""" self.headers(academy=1) @@ -39,8 +38,8 @@ def test_cohort_id__without_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_put__without_capability(self): """Test /cohort/:id without auth""" self.headers(academy=1) @@ -60,9 +59,9 @@ def test_cohort_id_put__without_capability(self): 🔽🔽🔽 Put without cohort """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__without_cohort(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -76,7 +75,7 @@ def test_cohort_id__put__without_cohort(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = {} response = self.client.put(url, data) @@ -86,15 +85,15 @@ def test_cohort_id__put__without_cohort(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put not have ending_date and never_ends """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__without_ending_date_or_never_ends(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -104,7 +103,7 @@ def test_cohort_id__put__without_ending_date_or_never_ends(self): model = self.generate_models(authenticate=True, profile_academy=True, capability='crud_cohort', role='potato') # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = {} response = self.client.put(url, data) @@ -118,15 +117,15 @@ def test_cohort_id__put__without_ending_date_or_never_ends(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with ending_date and never_ends=True """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_ending_date_and_never_ends_true(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -136,7 +135,7 @@ def test_cohort_id__put__with_ending_date_and_never_ends_true(self): model = self.generate_models(authenticate=True, profile_academy=True, capability='crud_cohort', role='potato') # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = { 'ending_date': timezone.now().isoformat(), @@ -154,15 +153,15 @@ def test_cohort_id__put__with_ending_date_and_never_ends_true(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with date """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -172,7 +171,7 @@ def test_cohort_id__put(self): model = self.generate_models(authenticate=True, profile_academy=True, capability='crud_cohort', role='potato') # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = { 'never_ends': True, @@ -224,16 +223,16 @@ def test_cohort_id__put(self): 'never_ends': True, }]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) """ 🔽🔽🔽 Put with date, kickoff_date greater than ending_date """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__kickoff_date_greater_than_ending_date(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -249,7 +248,7 @@ def test_cohort_id__put__kickoff_date_greater_than_ending_date(self): role='potato') # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] cases = [ { @@ -276,15 +275,15 @@ def test_cohort_id__put__kickoff_date_greater_than_ending_date(self): self.model_to_dict(model, 'cohort'), ]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put syllabus with id instead of {slug}.v{id} """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_bad_syllabus_version_malformed(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -299,7 +298,7 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version_malformed(self): syllabus_version=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) data = { @@ -320,15 +319,15 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version_malformed(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put syllabus but it doesn't exists """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_bad_syllabus_version(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -342,7 +341,7 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) data = { @@ -363,15 +362,15 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put syllabus with bad slug {slug}.v{id} """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_slug(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -389,7 +388,7 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_slug(self) syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) data = { @@ -410,15 +409,15 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_slug(self) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put syllabus with bad version {slug}.v{id} """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_version(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -437,7 +436,7 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_version(se cohort_kwargs=cohort_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) data = { @@ -458,15 +457,15 @@ def test_cohort_id__put__with_id__with_bad_syllabus_version__with_bad_version(se self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put assigning the syllabus version 1 """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__assigning_syllabus_version_1(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -492,7 +491,7 @@ def test_cohort_id__put__with_id__assigning_syllabus_version_1(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model2 = self.generate_models(academy=model.academy, skip_cohort=True, @@ -523,15 +522,15 @@ def test_cohort_id__put__with_id__assigning_syllabus_version_1(self): self.bc.format.to_dict(model.cohort_time_slot), ]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with some data """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_data_in_body(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -556,7 +555,7 @@ def test_cohort_id__put__with_id__with_data_in_body(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model2 = self.generate_models(academy=model.academy, skip_cohort=True, @@ -695,12 +694,12 @@ def test_cohort_id__put__with_id__with_data_in_body(self): 'starting_at': syllabus_schedule_time_slot.starting_at, } for syllabus_schedule_time_slot in model2.syllabus_schedule_time_slot]) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__with_data_in_body__cohort_with_timezone(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -725,7 +724,7 @@ def test_cohort_id__put__with_id__with_data_in_body__cohort_with_timezone(self): syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model2 = self.generate_models(academy=model.academy, skip_cohort=True, @@ -864,16 +863,16 @@ def test_cohort_id__put__with_id__with_data_in_body__cohort_with_timezone(self): 'starting_at': syllabus_schedule_time_slot.starting_at, } for syllabus_schedule_time_slot in model2.syllabus_schedule_time_slot]) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) """ 🔽🔽🔽 Put with some data, of other academy, syllabus public """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_public(self): """Test /cohort/:id without auth""" @@ -899,7 +898,7 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] syllabus = {'private': False} model2 = self.generate_models(academy=1, @@ -1039,16 +1038,16 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ 'starting_at': syllabus_schedule_time_slot.starting_at, } for syllabus_schedule_time_slot in model2.syllabus_schedule_time_slot]) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) """ 🔽🔽🔽 Put with some data, of other academy, syllabus private """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_private(self): """Test /cohort/:id without auth""" @@ -1074,7 +1073,7 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ syllabus_kwargs=syllabus_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] syllabus = {'private': True} model2 = self.generate_models(academy=1, @@ -1192,16 +1191,16 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ }]) self.assertEqual(self.bc.database.list_of('admissions.CohortTimeSlot'), []) - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) """ 🔽🔽🔽 Get data """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__get__with_id(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1217,7 +1216,7 @@ def test_cohort_id__get__with_id(self): syllabus_version=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) @@ -1279,15 +1278,15 @@ def test_cohort_id__get__with_id(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Get with bad slug """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__get__with_bad_slug(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1301,22 +1300,22 @@ def test_cohort_id__get__with_bad_slug(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': 'they-killed-kenny'}) response = self.client.get(url) self.assertEqual(response.data, None) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Get with slug """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__get__with_slug(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1332,7 +1331,7 @@ def test_cohort_id__get__with_slug(self): syllabus_version=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].slug}) @@ -1396,15 +1395,15 @@ def test_cohort_id__get__with_slug(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Delete with bad id """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__delete__with_bad_id(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1420,7 +1419,7 @@ def test_cohort_id__delete__with_bad_id(self): cohort_user=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': 0}) self.assertEqual(self.count_cohort_user(), 1) @@ -1429,15 +1428,15 @@ def test_cohort_id__delete__with_bad_id(self): self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.count_cohort_stage(model['cohort'].id), 'INACTIVE') - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Delete with id """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__delete__with_id(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1452,7 +1451,7 @@ def test_cohort_id__delete__with_id(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) self.assertEqual(self.count_cohort_stage(model['cohort'].id), 'INACTIVE') @@ -1461,12 +1460,12 @@ def test_cohort_id__delete__with_id(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.count_cohort_user(), 0) self.assertEqual(self.count_cohort_stage(model['cohort'].id), 'DELETED') - self.assertEqual(cohort_saved.send.call_args_list, + self.assertEqual(cohort_saved.send_robust.call_args_list, [call(instance=model.cohort, sender=model.cohort.__class__, created=False)]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id__delete__cohort_with_students(self): from breathecode.admissions.signals import cohort_saved @@ -1478,7 +1477,7 @@ def test_academy_cohort_id__delete__cohort_with_students(self): cohort_user=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': 1}) response = self.client.delete(url) @@ -1492,16 +1491,16 @@ def test_academy_cohort_id__delete__cohort_with_students(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{**self.model_to_dict(model, 'cohort')}]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Spy the extensions """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__get__spy_extensions(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1517,7 +1516,7 @@ def test_cohort_id__get__spy_extensions(self): syllabus_version=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) self.client.get(url) @@ -1526,10 +1525,10 @@ def test_cohort_id__get__spy_extensions(self): call(['CacheExtension', 'LanguageExtension', 'LookupExtension', 'PaginationExtension', 'SortExtension']), ]) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id__get__spy_extension_arguments(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -1545,7 +1544,7 @@ def test_cohort_id__get__spy_extension_arguments(self): syllabus_version=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_id', kwargs={'cohort_id': model['cohort'].id}) self.client.get(url) diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort_id_user_id.py b/breathecode/admissions/tests/urls/tests_academy_cohort_id_user_id.py index 6c5c2aa2c..65ef47262 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort_id_user_id.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort_id_user_id.py @@ -3,9 +3,11 @@ """ import re from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy -from rest_framework import status from django.utils import timezone +from rest_framework import status + from ..mixins import AdmissionsTestCase UTC_NOW = timezone.now() @@ -164,8 +166,8 @@ class CohortUserTestSuite(AdmissionsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__without_auth(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -184,8 +186,8 @@ def test_academy_cohort_user__without_auth(self): """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__post(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -230,8 +232,8 @@ def test_academy_cohort_user__post(self): """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__post__same_teacher_in_two_cohorts(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -300,8 +302,8 @@ def test_academy_cohort_user__post__same_teacher_in_two_cohorts(self): 🔽🔽🔽 Put """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__put(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -338,8 +340,8 @@ def test_academy_cohort_user__put(self): 🔽🔽🔽 Put teacher """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__put__teacher_with_role_student(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -370,8 +372,8 @@ def test_academy_cohort_user__put__teacher_with_role_student(self): 'role': 'STUDENT', }]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__put__teacher(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -406,8 +408,8 @@ def test_academy_cohort_user__put__teacher(self): }]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_staff(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -416,8 +418,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_staff(self): additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_teacher(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -426,8 +428,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_teacher(self): additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_syllabus_coordinator(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -436,8 +438,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_syllabus_coordinat additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_homework_reviewer(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -446,8 +448,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_homework_reviewer( additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_growth_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -456,8 +458,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_growth_manager(sel additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_culture_and_recruitment(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -466,8 +468,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_culture_and_recrui additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_country_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -476,8 +478,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_country_manager(se additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_community_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -486,8 +488,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_community_manager( additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_career_support(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -496,8 +498,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_career_support(sel additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_assistant(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -506,8 +508,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_assistant(self): additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_admissions_developer(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -516,8 +518,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_admissions_develop additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_admin(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -526,8 +528,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_admin(self): additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_academy_token(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, @@ -536,8 +538,8 @@ def test_academy_cohort_id_user__post__one_teacher__with_role_academy_token(self additional_data={'watching': False}) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_id_user__post__one_teacher__with_role_academy_coordinator(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort_me.py b/breathecode/admissions/tests/urls/tests_academy_cohort_me.py index 661d96c5d..b79d3c07d 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort_me.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort_me.py @@ -2,14 +2,16 @@ Test /academy/cohort """ import re -from unittest.mock import MagicMock, call, patch -from django.utils import timezone -from breathecode.admissions.caches import CohortCache from datetime import timedelta +from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy +from django.utils import timezone from rest_framework import status +from breathecode.admissions.caches import CohortCache from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + from ..mixins import AdmissionsTestCase @@ -21,8 +23,8 @@ class AcademyCohortTestSuite(AdmissionsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__post__without_authorization(self): """Test /academy/cohort without auth""" self.headers(academy=1) @@ -35,8 +37,8 @@ def test_cohort_me__post__without_authorization(self): self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) self.assertEqual(self.all_cohort_time_slot_dict(), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__without_capability(self): """Test /cohort/:id without auth""" self.headers(academy=1) @@ -59,9 +61,9 @@ def test_cohort_me__without_capability(self): 🔽🔽🔽 Without data """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_without_data(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -76,7 +78,7 @@ def test_cohort_me_without_data(self): skip_cohort=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] response = self.client.get(url) json = response.json() @@ -90,9 +92,9 @@ def test_cohort_me_without_data(self): 🔽🔽🔽 With data (this method is reusable) """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__with_data(self): """Test /cohort without auth""" self.check_cohort_me__with_data() @@ -101,9 +103,9 @@ def test_cohort_me__with_data(self): 🔽🔽🔽 Get """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__with_data__with_upcoming_false(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -120,7 +122,7 @@ def test_cohort_me__with_data__with_upcoming_false(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -184,11 +186,11 @@ def test_cohort_me__with_data__with_upcoming_false(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__with_data__with_upcoming_true__without_data(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -206,7 +208,7 @@ def test_cohort_me__with_data__with_upcoming_true__without_data(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.remove_dinamics_fields(model['cohort'].__dict__) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -219,11 +221,11 @@ def test_cohort_me__with_data__with_upcoming_true__without_data(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__with_data__with_upcoming_true(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -244,7 +246,7 @@ def test_cohort_me__with_data__with_upcoming_true(self): cohort_kwargs=cohort_kwargs) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -308,11 +310,11 @@ def test_cohort_me__with_data__with_upcoming_true(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_with_data_with_academy(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -329,7 +331,7 @@ def test_cohort_me_with_data_with_academy(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -393,11 +395,11 @@ def test_cohort_me_with_data_with_academy(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_with_data_with_academy_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -414,7 +416,7 @@ def test_cohort_me_with_data_with_academy_with_comma(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -478,11 +480,11 @@ def test_cohort_me_with_data_with_academy_with_comma(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - # @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - # @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - # @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + # @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + # @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + # @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) # def test_cohort_me_with_ten_datas_with_academy_with_comma(self): # """Test /cohort without auth""" # from breathecode.admissions.signals import cohort_saved @@ -506,7 +508,7 @@ def test_cohort_me_with_data_with_academy_with_comma(self): # models.sort(key=lambda x: x.cohort.kickoff_date, reverse=True) # # reset because this call are coming from mixer - # cohort_saved.send.call_args_list = [] + # cohort_saved.send_robust.call_args_list = [] # self.client.force_authenticate(user=models[0]['user']) # base_url = reverse_lazy('admissions:academy_cohort_me') @@ -565,14 +567,14 @@ def test_cohort_me_with_data_with_academy_with_comma(self): # self.assertEqual(response.status_code, status.HTTP_200_OK) # self.assertEqual(self.bc.database.list_of('admissions.Cohort'), self.all_model_dict([x.cohort for x in models])) # self.assertEqual(self.all_cohort_time_slot_dict(), []) - # self.assertEqual(cohort_saved.send.call_args_list, []) + # self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Sort in querystring """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__with_data__with_sort(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -596,7 +598,7 @@ def test_cohort_me__with_data__with_sort(self): ] # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] ordened_models = sorted(models, key=lambda x: x['cohort'].slug, reverse=True) @@ -660,11 +662,11 @@ def test_cohort_me__with_data__with_sort(self): self.assertEqual(self.bc.database.list_of('admissions.Cohort'), [{ **self.model_to_dict(model, 'cohort') } for model in models]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_with_data__ignore_cohort_then_student_is_not_registered(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -680,7 +682,7 @@ def test_cohort_me_with_data__ignore_cohort_then_student_is_not_registered(self) syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -693,11 +695,11 @@ def test_cohort_me_with_data__ignore_cohort_then_student_is_not_registered(self) self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_with_data_with_location(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -714,7 +716,7 @@ def test_cohort_me_with_data_with_location(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -778,11 +780,11 @@ def test_cohort_me_with_data_with_location(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me_with_data_with_location_with_comma(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -799,7 +801,7 @@ def test_cohort_me_with_data_with_location_with_comma(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] model_dict = self.get_cohort_dict(1) base_url = reverse_lazy('admissions:academy_cohort_me') @@ -863,12 +865,12 @@ def test_cohort_me_with_data_with_location_with_comma(self): self.assertEqual(self.count_cohort(), 1) self.assertEqual(self.get_cohort_dict(1), model_dict) self.assertEqual(self.all_cohort_time_slot_dict(), []) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__spy_extensions(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -885,7 +887,7 @@ def test_cohort_me__spy_extensions(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_me') + f'?location={model["academy"].slug},they-killed-kenny' self.client.get(url) @@ -897,10 +899,10 @@ def test_cohort_me__spy_extensions(self): 'SortExtension']), ])) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_me__spy_extension_arguments(self): """Test /cohort without auth""" from breathecode.admissions.signals import cohort_saved @@ -917,7 +919,7 @@ def test_cohort_me__spy_extension_arguments(self): syllabus_schedule=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] url = reverse_lazy('admissions:academy_cohort_me') + f'?location={model["academy"].slug},they-killed-kenny' self.client.get(url) diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort_user.py b/breathecode/admissions/tests/urls/tests_academy_cohort_user.py index 07813009e..bf2d0cf98 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort_user.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort_user.py @@ -3,13 +3,15 @@ """ import random import re -from unittest.mock import MagicMock, patch -from django.utils import timezone from random import choice +from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy +from django.utils import timezone from rest_framework import status from breathecode.admissions.models import STARTED + from ..mixins import AdmissionsTestCase UTC_NOW = timezone.now() @@ -107,8 +109,8 @@ class CohortUserTestSuite(AdmissionsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__without_auth(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -126,9 +128,9 @@ def test__without_auth(self): 🔽🔽🔽 Without data """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__without_data(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -148,9 +150,9 @@ def test__without_data(self): 🔽🔽🔽 With data """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -204,9 +206,9 @@ def test__with_data(self): 🔽🔽🔽 Roles in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_bad_roles(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -226,8 +228,8 @@ def test__with_data__with_bad_roles(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_roles(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -282,9 +284,9 @@ def test__with_data__with_roles(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_roles__with_comma(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -340,9 +342,9 @@ def test__with_data__with_roles__with_comma(self): 🔽🔽🔽 Finantial status in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_bad_finantial_status(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -362,9 +364,9 @@ def test__with_data__with_bad_finantial_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_finantial_status(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -420,9 +422,9 @@ def test__with_data__with_finantial_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_finantial_status__with_comma(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -478,9 +480,9 @@ def test__with_data__with_finantial_status__with_comma(self): 🔽🔽🔽 Educational status in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_bad_educational_status(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -500,9 +502,9 @@ def test__with_data__with_bad_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_educational_status(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -558,9 +560,9 @@ def test__with_data__with_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_educational_status__with_comma(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -617,9 +619,9 @@ def test__with_data__with_educational_status__with_comma(self): 🔽🔽🔽 Academy in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_academy(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -671,9 +673,9 @@ def test__with_data__with_academy(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_academy__with_comma(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -729,9 +731,9 @@ def test__with_data__with_academy__with_comma(self): 🔽🔽🔽 Cohorts in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_bad_cohorts(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -751,9 +753,9 @@ def test__with_data__with_bad_cohorts(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_cohorts(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -805,9 +807,9 @@ def test__with_data__with_cohorts(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_cohorts_get_tasks_with_no_tasks(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -860,9 +862,9 @@ def test__with_data__with_cohorts_get_tasks_with_no_tasks(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_data__with_cohorts_get_tasks_with_no_tasks(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -952,9 +954,9 @@ def test__with_data__with_cohorts_get_tasks_with_no_tasks(self): 🔽🔽🔽 Put without id """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__without_id(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -974,9 +976,9 @@ def test__put__without_id(self): 🔽🔽🔽 Put bulk mode """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__in_bulk__without_data(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -991,9 +993,9 @@ def test__put__in_bulk__without_data(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__in_bulk__without_data__without_id(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -1008,9 +1010,9 @@ def test__put__in_bulk__without_data__without_id(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__in_bulk__without_data__with_bad_id(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -1025,9 +1027,9 @@ def test__put__in_bulk__without_data__with_bad_id(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__in_bulk__with_one_item(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -1057,9 +1059,9 @@ def test__put__in_bulk__with_one_item(self): self.bc.format.to_dict(model.cohort_user), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__in_bulk__with_two_items(self): """Test /cohort/user without auth""" self.headers(academy=1) @@ -1120,9 +1122,9 @@ def test__put__in_bulk__with_two_items(self): 🔽🔽🔽 Post bulk mode """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__in_bulk__0_items(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1142,9 +1144,9 @@ def test__post__in_bulk__0_items(self): self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__in_bulk__1_item(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1180,9 +1182,9 @@ def test__post__in_bulk__1_item(self): ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post_in_bulk__2_items(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1228,9 +1230,9 @@ def test__post_in_bulk__2_items(self): """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__in_bulk__1_item__statuses_in_lowercase(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1289,9 +1291,9 @@ def test__post__in_bulk__1_item__statuses_in_lowercase(self): 🔽🔽🔽 Delete in bulk """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__delete__without_args_in_url_or_bulk(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1305,9 +1307,9 @@ def test__delete__without_args_in_url_or_bulk(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__delete__in_bulk__with_one(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1332,9 +1334,9 @@ def test__delete__in_bulk__with_one(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__delete__in_bulk__with_two(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1366,9 +1368,9 @@ def test__delete__in_bulk__with_two(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__post__1_item(self): prohibited_stages = ['INACTIVE', 'DELETED', 'ENDED'] @@ -1397,9 +1399,9 @@ def test_academy_cohort_user__post__1_item(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_cohort_user__post__2_item(self): #incomplete test prohibited_stages = ['INACTIVE', 'DELETED', 'ENDED'] diff --git a/breathecode/admissions/tests/urls/tests_academy_me.py b/breathecode/admissions/tests/urls/tests_academy_me.py index 557aa981a..4338d3c31 100644 --- a/breathecode/admissions/tests/urls/tests_academy_me.py +++ b/breathecode/admissions/tests/urls/tests_academy_me.py @@ -1,16 +1,18 @@ """ Test /cohort """ -from datetime import timedelta import random -from django.utils import timezone -from breathecode.admissions.caches import CohortCache +from datetime import timedelta from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy +from django.utils import timezone from rest_framework import status -from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers +from breathecode.admissions.caches import CohortCache +from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers from breathecode.utils.datetime_integer import DatetimeInteger + from ..mixins import AdmissionsTestCase @@ -67,7 +69,7 @@ def test_put__without_capability(self): 🔽🔽🔽 Put without required fields """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def test__put__without_required_fields(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -82,7 +84,7 @@ def test__put__without_required_fields(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = {} response = self.client.put(url, data, format='json') @@ -98,13 +100,13 @@ def test__put__without_required_fields(self): self.assertEqual(self.bc.database.list_of('admissions.Academy'), [ self.bc.format.to_dict(model.academy), ]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with Academy, try to modify slug """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def test__put__with_academy__try_to_modify_slug(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -119,7 +121,7 @@ def test__put__with_academy__try_to_modify_slug(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] data = { 'name': self.bc.fake.name(), @@ -135,13 +137,13 @@ def test__put__with_academy__try_to_modify_slug(self): self.assertEqual(self.bc.database.list_of('admissions.Academy'), [ self.bc.format.to_dict(model.academy), ]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with Academy, passing all the fields """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def test__put__with_academy__passing_all_the_fields(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -158,7 +160,7 @@ def test__put__with_academy__passing_all_the_fields(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] country = random.choice(model.country) city = random.choice(model.city) @@ -184,13 +186,13 @@ def test__put__with_academy__passing_all_the_fields(self): **self.bc.format.to_dict(model.academy), **data, }]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with Academy, passing all the wrong fields """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def test__put__with_academy__passing_all_the_wrong_fields(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -207,7 +209,7 @@ def test__put__with_academy__passing_all_the_wrong_fields(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] country = random.choice(model.country) city = random.choice(model.city) @@ -261,13 +263,13 @@ def test__put__with_academy__passing_all_the_wrong_fields(self): **self.bc.format.to_dict(model.academy), **data, }]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Put with Academy, passing all the fields """ - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) def test__put__with_academy__passing_all_the_status(self): """Test /cohort/:id without auth""" from breathecode.admissions.signals import cohort_saved @@ -284,7 +286,7 @@ def test__put__with_academy__passing_all_the_status(self): syllabus=True) # reset because this call are coming from mixer - cohort_saved.send.call_args_list = [] + cohort_saved.send_robust.call_args_list = [] country = random.choice(model.country) city = random.choice(model.city) @@ -310,4 +312,4 @@ def test__put__with_academy__passing_all_the_status(self): **self.bc.format.to_dict(model.academy), **data, }]) - self.assertEqual(cohort_saved.send.call_args_list, []) + self.assertEqual(cohort_saved.send_robust.call_args_list, []) diff --git a/breathecode/admissions/tests/urls/tests_cohort_id_join.py b/breathecode/admissions/tests/urls/tests_cohort_id_join.py index 282cfa32f..96f2b3339 100644 --- a/breathecode/admissions/tests/urls/tests_cohort_id_join.py +++ b/breathecode/admissions/tests/urls/tests_cohort_id_join.py @@ -81,8 +81,8 @@ def cohort_user_field(data={}): class CohortIdUserIdTestSuite(AdmissionsTestCase): # When: no auth # Then: should return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__no_auth(self): """Test /cohort/:id/user without auth""" url = reverse_lazy('admissions:cohort_id_join', kwargs={'cohort_id': 999}) @@ -96,8 +96,8 @@ def test__post__no_auth(self): # When: no cohort # Then: should return 404 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__no_cohort(self): @@ -123,8 +123,8 @@ def test__post__no_cohort(self): # When: no have a PlanFinancing or Subscription belonging to the user # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__not_subscribed(self): @@ -164,8 +164,8 @@ def test__post__not_subscribed(self): # When: have one of PlanFinancing or Subscription belonging to the user # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__have_a_subscription_or_a_plan_financing(self): @@ -240,8 +240,8 @@ def test__post__have_a_subscription_or_a_plan_financing(self): # When: joined to cohort externally to subscription # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__joined_to_cohort(self): @@ -317,8 +317,8 @@ def test__post__joined_to_cohort(self): # When: rejoining to cohort from a subscription # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__rejoining_from_a_subscription(self): @@ -391,8 +391,8 @@ def test__post__rejoining_from_a_subscription(self): # When: joined to another endable cohort # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__joined_to_another_endable_cohort(self): @@ -457,8 +457,8 @@ def test__post__joined_to_another_endable_cohort(self): # When: joined to another endable cohort # Then: should return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.admissions.tasks.build_cohort_user.delay', MagicMock()) @patch('breathecode.admissions.tasks.build_profile_academy.delay', MagicMock()) def test__post__joined_to_another_endable_cohort(self): diff --git a/breathecode/admissions/tests/urls/tests_cohort_id_user.py b/breathecode/admissions/tests/urls/tests_cohort_id_user.py index 4eaf44699..ad5408b20 100644 --- a/breathecode/admissions/tests/urls/tests_cohort_id_user.py +++ b/breathecode/admissions/tests/urls/tests_cohort_id_user.py @@ -8,8 +8,12 @@ from django.utils import timezone from rest_framework import status -from breathecode.tests.mocks import (GOOGLE_CLOUD_PATH, apply_google_cloud_blob_mock, apply_google_cloud_bucket_mock, - apply_google_cloud_client_mock) +from breathecode.tests.mocks import ( + GOOGLE_CLOUD_PATH, + apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, +) from ..mixins import AdmissionsTestCase @@ -140,8 +144,8 @@ class CohortIdUserIdTestSuite(AdmissionsTestCase): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__with_bad_cohort_id(self): """Test /cohort/:id/user without auth""" url = reverse_lazy('admissions:cohort_id_user', kwargs={'cohort_id': 999}) @@ -161,8 +165,8 @@ def test_cohort_id_user__post__with_bad_cohort_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__with_bad_user(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort=True) @@ -182,8 +186,8 @@ def test_cohort_id_user__post__with_bad_user(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__without_user(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort=True, user=True, profile_academy=True, cohort_user=True) @@ -203,8 +207,8 @@ def test_cohort_id_user__post__without_user(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__without_profile_academy(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, user=True, cohort=1) @@ -223,8 +227,8 @@ def test_cohort_id_user__post__without_profile_academy(self): post to a cohort with stage DELETED ''' - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__stage_deleted(self): """Test /cohort/:id/user without auth""" cohort_kwargs = {'stage': 'DELETED'} @@ -253,8 +257,8 @@ def test_cohort_id_user__post__stage_deleted(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test_cohort_id_user__post(self): """Test /cohort/:id/user without auth""" @@ -289,8 +293,8 @@ def test_cohort_id_user__post(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__status_in_upper_and_lower(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort={'stage': 'STARTED'}, user=True, profile_academy=True) @@ -336,8 +340,8 @@ def test_cohort_id_user__post__status_in_upper_and_lower(self): 🔽🔽🔽 Post in bulk mode """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__in_bulk__cohort_with_stage_deleted(self): """Test /cohort/:id/user without auth""" @@ -361,8 +365,8 @@ def test_cohort_id_user__post__in_bulk__cohort_with_stage_deleted(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__in_bulk__zero_items(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort=True) @@ -380,8 +384,8 @@ def test_cohort_id_user__post__in_bulk__zero_items(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__in_bulk__with_one_item(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort={'stage': 'STARTED'}, user=True, profile_academy=True) @@ -412,8 +416,8 @@ def test_cohort_id_user__post__in_bulk__with_one_item(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__in_bulk__with_two_items(self): """Test /cohort/:id/user without auth""" base = self.generate_models(authenticate=True, cohort={'stage': 'STARTED'}, profile_academy=True) @@ -464,8 +468,8 @@ def test_cohort_id_user__post__in_bulk__with_two_items(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__with_two_cohort__with_the_same_certificate(self): """Test /cohort/:id/user without auth""" models = [ @@ -508,8 +512,8 @@ def test_cohort_id_user__post__with_two_cohort__with_the_same_certificate(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__twice(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, @@ -536,8 +540,8 @@ def test_cohort_id_user__post__twice(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__role_student(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, @@ -563,8 +567,8 @@ def test_cohort_id_user__post__one_teacher__role_student(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_staff(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'staff') @@ -573,8 +577,8 @@ def test_cohort_id_user__post__one_teacher__with_role_staff(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_teacher(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'teacher') @@ -583,8 +587,8 @@ def test_cohort_id_user__post__one_teacher__with_role_teacher(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_syllabus_coordinator(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'syllabus_coordinator') @@ -593,8 +597,8 @@ def test_cohort_id_user__post__one_teacher__with_role_syllabus_coordinator(self) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_homework_reviewer(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'homework_reviewer') @@ -603,8 +607,8 @@ def test_cohort_id_user__post__one_teacher__with_role_homework_reviewer(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_growth_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'growth_manager') @@ -613,8 +617,8 @@ def test_cohort_id_user__post__one_teacher__with_role_growth_manager(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_culture_and_recruitment(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'culture_and_recruitment') @@ -623,8 +627,8 @@ def test_cohort_id_user__post__one_teacher__with_role_culture_and_recruitment(se @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_country_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'country_manager') @@ -633,8 +637,8 @@ def test_cohort_id_user__post__one_teacher__with_role_country_manager(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_community_manager(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'community_manager') @@ -643,8 +647,8 @@ def test_cohort_id_user__post__one_teacher__with_role_community_manager(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_career_support(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'career_support') @@ -653,8 +657,8 @@ def test_cohort_id_user__post__one_teacher__with_role_career_support(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_assistant(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'assistant') @@ -663,8 +667,8 @@ def test_cohort_id_user__post__one_teacher__with_role_assistant(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_admissions_developer(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'admissions_developer') @@ -673,8 +677,8 @@ def test_cohort_id_user__post__one_teacher__with_role_admissions_developer(self) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_admin(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'admin') @@ -683,8 +687,8 @@ def test_cohort_id_user__post__one_teacher__with_role_admin(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_academy_token(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'academy_token') @@ -693,8 +697,8 @@ def test_cohort_id_user__post__one_teacher__with_role_academy_token(self): @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__one_teacher__with_role_academy_coordinator(self): """Test /cohort/:id/user without auth""" check_cohort_user_that_not_have_role_student_can_be_teacher(self, 'academy_coordinator') @@ -706,8 +710,8 @@ def test_cohort_id_user__post__one_teacher__with_role_academy_coordinator(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__two_teacher(self): """Test /cohort/:id/user without auth""" models = [ @@ -738,8 +742,8 @@ def test_cohort_id_user__post__two_teacher(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__with_unsuccess_task(self): """Test /cohort/:id/user without auth""" task = {'task_status': 'PENDING', 'task_type': 'PROJECT', 'associated_slug': 'testing-slug'} @@ -780,8 +784,8 @@ def test_cohort_id_user__post__with_unsuccess_task(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user__post__with_unsuccess_finantial_status(self): """Test /cohort/:id/user without auth""" model = self.generate_models(authenticate=True, cohort={'stage': 'STARTED'}, user=True, profile_academy=True) diff --git a/breathecode/admissions/tests/urls/tests_cohort_id_user_id.py b/breathecode/admissions/tests/urls/tests_cohort_id_user_id.py index ebde6cbe7..10fbe749f 100644 --- a/breathecode/admissions/tests/urls/tests_cohort_id_user_id.py +++ b/breathecode/admissions/tests/urls/tests_cohort_id_user_id.py @@ -3,14 +3,17 @@ """ import re from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy from rest_framework import status + from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import AdmissionsTestCase @@ -56,8 +59,8 @@ class CohortIdUserIdTestSuite(AdmissionsTestCase): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_without_auth(self): """Test /cohort/:id/user/:id without auth""" url = reverse_lazy('admissions:cohort_id_user_id', kwargs={'cohort_id': 1, 'user_id': 1}) @@ -73,8 +76,8 @@ def test_cohort_id_user_id_without_auth(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_bad_cohort_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True) @@ -90,8 +93,8 @@ def test_cohort_id_user_id_put_with_bad_cohort_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_bad_user_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, cohort=True) @@ -107,8 +110,8 @@ def test_cohort_id_user_id_put_with_bad_user_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_bad_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, cohort=True, user=True) @@ -128,8 +131,8 @@ def test_cohort_id_user_id_put_with_bad_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_id_but_without_user(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, cohort=True) @@ -149,8 +152,8 @@ def test_cohort_id_user_id_put_with_id_but_without_user(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_id_but_with_user(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, cohort=True, user=True) @@ -170,8 +173,8 @@ def test_cohort_id_user_id_put_with_id_but_with_user(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, @@ -199,8 +202,8 @@ def test_cohort_id_user_id_put_with_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_delete_with_id_with_bad_user_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, @@ -217,8 +220,8 @@ def test_cohort_id_user_id_delete_with_id_with_bad_user_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_delete_with_id_with_bad_cohort_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, @@ -235,8 +238,8 @@ def test_cohort_id_user_id_delete_with_id_with_bad_cohort_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_delete_with_id(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, @@ -258,8 +261,8 @@ def test_cohort_id_user_id_delete_with_id(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_unsuccess_task(self): """Test /cohort/:id/user/:id without auth""" task = {'task_status': 'PENDING', 'task_type': 'PROJECT', 'associated_slug': 'testing-slug'} @@ -300,8 +303,8 @@ def test_cohort_id_user_id_put_with_unsuccess_task(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_unsuccess_finantial_status(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(authenticate=True, cohort=True, user=True, profile_academy=True, cohort_user=True) @@ -324,8 +327,8 @@ def test_cohort_id_user_id_put_with_unsuccess_finantial_status(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_id_put_with_stage_delete(self): """Test /cohort/:id/user/:id without auth""" cohort_kwargs = {'stage': 'DELETED'} diff --git a/breathecode/admissions/tests/urls/tests_cohort_user.py b/breathecode/admissions/tests/urls/tests_cohort_user.py index 1c0905e74..05c0000d5 100644 --- a/breathecode/admissions/tests/urls/tests_cohort_user.py +++ b/breathecode/admissions/tests/urls/tests_cohort_user.py @@ -1,20 +1,23 @@ """ Test /cohort/user """ -from random import choice import re +from random import choice from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy from rest_framework import status + +from breathecode.admissions.caches import CohortUserCache from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + from ..mixins import AdmissionsTestCase -from breathecode.admissions.caches import CohortUserCache def put_serializer(self, cohort_user, cohort, user, profile_academy=None, data={}): @@ -56,8 +59,8 @@ def put_serializer(self, cohort_user, cohort, user, profile_academy=None, data={ class CohortUserTestSuite(AdmissionsTestCase): """Test /cohort/user""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_without_auth(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -70,8 +73,8 @@ def test_without_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_without_data(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True) @@ -86,8 +89,8 @@ def test_without_data(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -125,12 +128,12 @@ def test_with_data(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_bad_roles(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -148,8 +151,8 @@ def test_with_data_with_bad_roles(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_roles(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -192,8 +195,8 @@ def test_with_data_with_roles(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_roles_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -237,8 +240,8 @@ def test_with_data_with_roles_with_comma(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_user_with_data_with_bad_financial_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -256,8 +259,8 @@ def test_cohort_user_with_data_with_bad_financial_status(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_finantial_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -302,8 +305,8 @@ def test_with_data_with_finantial_status(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_finantial_status_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -348,8 +351,8 @@ def test_with_data_with_finantial_status_with_comma(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_bad_educational_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -364,12 +367,12 @@ def test_with_data_with_bad_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_educational_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -411,12 +414,12 @@ def test_with_data_with_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_educational_status_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -462,8 +465,8 @@ def test_with_data_with_educational_status_with_comma(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_bad_academy(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -478,12 +481,12 @@ def test_with_data_with_bad_academy(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_academy(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -529,12 +532,12 @@ def test_with_data_with_academy(self): 🔽🔽🔽 With profile academy """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__with_profile_academy(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -583,12 +586,12 @@ def test__with_profile_academy(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_academy_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -633,8 +636,8 @@ def test_with_data_with_academy_with_comma(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_bad_cohorts(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -649,12 +652,12 @@ def test_with_data_with_bad_cohorts(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data_with_cohorts(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -699,8 +702,8 @@ def test_with_data_with_cohorts(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_without_id(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -713,12 +716,12 @@ def test_put_without_id(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_without_data(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -735,8 +738,8 @@ def test_put_in_bulk_without_data(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_without_data__without_passing_attrs(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -753,8 +756,8 @@ def test_put_in_bulk_without_data__without_passing_attrs(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_without_data__cannot_determine_the_cohort_user(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -771,8 +774,8 @@ def test_put_in_bulk_without_data__cannot_determine_the_cohort_user(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_without_profile_academy(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -795,8 +798,8 @@ def test_put_in_bulk_without_profile_academy(self): 'history_log': {}, }]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_with_stage_delete(self): """Test /cohort/user without auth""" cohort_kwargs = {'stage': 'DELETED'} @@ -823,12 +826,12 @@ def test_put_in_bulk_with_stage_delete(self): 'history_log': {}, }]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_with_one_item(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -871,8 +874,8 @@ def test_put_in_bulk_with_one_item(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_in_bulk_with_two_items(self): """Test /cohort/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -948,8 +951,8 @@ def test_put_in_bulk_with_two_items(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_delete_without_auth(self): """Test /cohort/:id/user without auth""" url = reverse_lazy('admissions:cohort_user') @@ -964,8 +967,8 @@ def test_cohort_id_user_delete_without_auth(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_delete_without_args_in_url_or_bulk(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -979,12 +982,12 @@ def test_cohort_id_user_delete_without_args_in_url_or_bulk(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_cohort_id_user_delete_in_bulk_with_one(self): """Test /cohort/:id/user without auth""" self.headers(academy=1) @@ -1008,8 +1011,8 @@ def test_cohort_id_user_delete_in_bulk_with_one(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @@ -1046,8 +1049,8 @@ def test_cohort_id_user_delete_in_bulk_with_two(self): @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) diff --git a/breathecode/admissions/tests/urls/tests_me_cohort_id_user_log.py b/breathecode/admissions/tests/urls/tests_me_cohort_id_user_log.py index 12956234e..42b283109 100644 --- a/breathecode/admissions/tests/urls/tests_me_cohort_id_user_log.py +++ b/breathecode/admissions/tests/urls/tests_me_cohort_id_user_log.py @@ -3,14 +3,17 @@ """ import re from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy from rest_framework import status + from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import AdmissionsTestCase @@ -27,8 +30,8 @@ def get_serializer(cohort_user, cohort, data={}): class CohortIdUserIdTestSuite(AdmissionsTestCase): """Test /cohort/:id/user/:id""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): """Test /cohort/:id/user/:id without auth""" url = reverse_lazy('admissions:me_cohort_id_user_log', kwargs={'cohort_id': 1}) @@ -41,8 +44,8 @@ def test_no_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_items(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(user=1) @@ -56,8 +59,8 @@ def test_zero_items(self): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_two_items(self): """Test /cohort/:id/user/:id without auth""" diff --git a/breathecode/admissions/tests/urls/tests_me_cohort_user_log.py b/breathecode/admissions/tests/urls/tests_me_cohort_user_log.py index 2d7c0333b..73dc63c06 100644 --- a/breathecode/admissions/tests/urls/tests_me_cohort_user_log.py +++ b/breathecode/admissions/tests/urls/tests_me_cohort_user_log.py @@ -3,14 +3,17 @@ """ import re from unittest.mock import MagicMock, patch + from django.urls.base import reverse_lazy from rest_framework import status + from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import AdmissionsTestCase @@ -27,8 +30,8 @@ def get_serializer(cohort_user, cohort, data={}): class CohortIdUserIdTestSuite(AdmissionsTestCase): """Test /cohort/:id/user/:id""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): """Test /cohort/:id/user/:id without auth""" url = reverse_lazy('admissions:me_cohort_user_log') @@ -41,8 +44,8 @@ def test_no_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_items(self): """Test /cohort/:id/user/:id without auth""" model = self.generate_models(user=1) @@ -56,8 +59,8 @@ def test_zero_items(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('admissions.CohortUser'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_two_items(self): """Test /cohort/:id/user/:id without auth""" diff --git a/breathecode/admissions/tests/urls/tests_public_cohort_user.py b/breathecode/admissions/tests/urls/tests_public_cohort_user.py index d25146a61..5939b6d82 100644 --- a/breathecode/admissions/tests/urls/tests_public_cohort_user.py +++ b/breathecode/admissions/tests/urls/tests_public_cohort_user.py @@ -1,13 +1,15 @@ """ Test /cohort/all """ -from unittest.mock import MagicMock, call, patch -from datetime import timedelta import random import re +from datetime import timedelta +from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy from django.utils import timezone from rest_framework import status + from ..mixins import AdmissionsTestCase @@ -50,7 +52,7 @@ def test_without_data(self): 🔽🔽🔽 With data """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data(self): """Test /cohort/all without auth""" model = self.generate_models(authenticate=True, cohort_user=True, profile_academy=True, syllabus_version=True) @@ -70,7 +72,7 @@ def test_with_data(self): 🔽🔽🔽 roles in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_bad_roles(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -85,7 +87,7 @@ def test_with_data_with_bad_roles(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_roles(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -105,7 +107,7 @@ def test_with_data_with_roles(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_roles_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -126,7 +128,7 @@ def test_with_data_with_roles_with_comma(self): 🔽🔽🔽 finantial_status in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_bad_finantial_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -141,7 +143,7 @@ def test_with_data_with_bad_finantial_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_finantial_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -163,7 +165,7 @@ def test_with_data_with_finantial_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_finantial_status_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -185,7 +187,7 @@ def test_with_data_with_finantial_status_with_comma(self): 🔽🔽🔽 educational_status in querystring """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_bad_educational_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, cohort_user=True) @@ -200,7 +202,7 @@ def test_with_data_with_bad_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_educational_status(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, @@ -223,7 +225,7 @@ def test_with_data_with_educational_status(self): self.assertEqual(self.count_cohort_user(), 1) self.assertEqual(self.get_cohort_user_dict(1), model_dict) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_with_data_with_educational_status_with_comma(self): """Test /cohort/user without auth""" model = self.generate_models(authenticate=True, diff --git a/breathecode/assessment/models.py b/breathecode/assessment/models.py index 9df4d5944..1a1442ffc 100644 --- a/breathecode/assessment/models.py +++ b/breathecode/assessment/models.py @@ -1,12 +1,15 @@ -from django.db import models -import os import binascii import hashlib +import os from datetime import timedelta + from django.contrib.auth.models import User +from django.core.validators import RegexValidator +from django.db import models + from breathecode.admissions.models import Academy + from . import signals -from django.core.validators import RegexValidator __all__ = ['UserProxy', 'Assessment', 'Question', 'Option', 'UserAssessment', 'Answer'] @@ -280,7 +283,7 @@ def save(self, *args, **kwargs): # Answer is being closed if self.status != self._old_status: - signals.userassessment_status_updated.send(instance=self, sender=self.__class__) + signals.userassessment_status_updated.send_robust(instance=self, sender=self.__class__) return super().save(*args, **kwargs) diff --git a/breathecode/assignments/models.py b/breathecode/assignments/models.py index 4e3b874ce..16c82e432 100644 --- a/breathecode/assignments/models.py +++ b/breathecode/assignments/models.py @@ -129,14 +129,14 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) if not creating and self.task_status != self._current_task_status: - signals.assignment_status_updated.send(instance=self, sender=self.__class__) + signals.assignment_status_updated.send_robust(instance=self, sender=self.__class__) if not creating and self.revision_status != self._current_revision_status: - signals.revision_status_updated.send(instance=self, sender=self.__class__) + signals.revision_status_updated.send_robust(instance=self, sender=self.__class__) # only validate this on creation if creating: - signals.assignment_created.send(instance=self, sender=self.__class__) + signals.assignment_created.send_robust(instance=self, sender=self.__class__) self._current_task_status = self.task_status self._current_revision_status = self.revision_status diff --git a/breathecode/assignments/tests/tasks/tests_set_cohort_user_assignments.py b/breathecode/assignments/tests/tasks/tests_set_cohort_user_assignments.py index 2a5ad38f7..c6bfbceed 100644 --- a/breathecode/assignments/tests/tasks/tests_set_cohort_user_assignments.py +++ b/breathecode/assignments/tests/tasks/tests_set_cohort_user_assignments.py @@ -25,11 +25,11 @@ def x(db, monkeypatch): monkeypatch.setattr('logging.Logger.info', MagicMock()) monkeypatch.setattr('logging.Logger.error', MagicMock()) - monkeypatch.setattr('breathecode.assignments.signals.assignment_created.send', empty) - monkeypatch.setattr('breathecode.assignments.signals.assignment_status_updated.send', empty) + monkeypatch.setattr('breathecode.assignments.signals.assignment_created.send_robust', empty) + monkeypatch.setattr('breathecode.assignments.signals.assignment_status_updated.send_robust', empty) monkeypatch.setattr('breathecode.activity.tasks.get_attendancy_log.delay', empty) - monkeypatch.setattr('django.db.models.signals.pre_delete.send', empty) - monkeypatch.setattr('breathecode.admissions.signals.student_edu_status_updated.send', empty) + monkeypatch.setattr('django.db.models.signals.pre_delete.send_robust', empty) + monkeypatch.setattr('breathecode.admissions.signals.student_edu_status_updated.send_robust', empty) yield diff --git a/breathecode/assignments/tests/tasks/tests_student_task_notification.py b/breathecode/assignments/tests/tasks/tests_student_task_notification.py index a7f4a09d5..e4db763c1 100644 --- a/breathecode/assignments/tests/tasks/tests_student_task_notification.py +++ b/breathecode/assignments/tests/tasks/tests_student_task_notification.py @@ -31,7 +31,7 @@ def test_student_task_notification__without_tasks(self): self.assertEqual(send_email_message.call_args_list, []) self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, [call('Task not found')]) - self.assertEqual(signals.assignment_created.send.call_args_list, []) + self.assertEqual(signals.assignment_created.send_robust.call_args_list, []) """ 🔽🔽🔽 With Task and Cohort revision_status PENDING @@ -66,7 +66,7 @@ def test_student_task_notification__pending__with_task__with_cohort(self): self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -98,7 +98,7 @@ def test_student_task_notification__with_task__pending__with_cohort__url_ends_wi self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -131,7 +131,7 @@ def test_student_task_notification__with_task__pending__with_cohort__lang_es(sel self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) """ @@ -167,7 +167,7 @@ def test_student_task_notification__approved__with_task__with_cohort(self): self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -199,7 +199,7 @@ def test_student_task_notification__with_task__approved__with_cohort__url_ends_w self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -232,7 +232,7 @@ def test_student_task_notification__with_task__approved__with_cohort__lang_es(se self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) """ @@ -268,7 +268,7 @@ def test_student_task_notification__rejected__with_task__with_cohort(self): self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -300,7 +300,7 @@ def test_student_task_notification__with_task__rejected__with_cohort__url_ends_w self.assertEqual(str(Logger.info.call_args_list), str([call('Starting student_task_notification')])) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @@ -333,5 +333,5 @@ def test_student_task_notification__with_task__rejected__with_cohort__lang_es(se self.assertEqual(Logger.info.call_args_list, [call('Starting student_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) diff --git a/breathecode/assignments/tests/tasks/tests_teacher_task_notification.py b/breathecode/assignments/tests/tasks/tests_teacher_task_notification.py index db1eeae82..5afbf0cd6 100644 --- a/breathecode/assignments/tests/tasks/tests_teacher_task_notification.py +++ b/breathecode/assignments/tests/tasks/tests_teacher_task_notification.py @@ -33,7 +33,7 @@ def test_teacher_task_notification__without_env(self): self.assertEqual(os.getenv.call_args_list, [call('TEACHER_URL')]) self.assertEqual(Logger.info.call_args_list, [call('Starting teacher_task_notification')]) self.assertEqual(Logger.error.call_args_list, [call('TEACHER_URL is not set as environment variable')]) - self.assertEqual(signals.assignment_created.send.call_args_list, []) + self.assertEqual(signals.assignment_created.send_robust.call_args_list, []) """ 🔽🔽🔽 Without Task @@ -59,7 +59,7 @@ def test_teacher_task_notification__without_tasks(self): self.assertEqual(os.getenv.call_args_list, [call('TEACHER_URL')]) self.assertEqual(Logger.info.call_args_list, [call('Starting teacher_task_notification')]) self.assertEqual(Logger.error.call_args_list, [call('Task not found')]) - self.assertEqual(signals.assignment_created.send.call_args_list, []) + self.assertEqual(signals.assignment_created.send_robust.call_args_list, []) """ 🔽🔽🔽 With Task and Cohort @@ -102,7 +102,7 @@ def test_teacher_task_notification__with_task__with_cohort(self): call('TEACHER_URL'), ]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) """ @@ -148,7 +148,7 @@ def test_teacher_task_notification__with_task__with_cohort__lang_es(self): ]) self.assertEqual(Logger.info.call_args_list, [call('Starting teacher_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) """ @@ -194,5 +194,5 @@ def test_teacher_task_notification__with_task__with_cohort__ends_with_slash(self ]) self.assertEqual(Logger.info.call_args_list, [call('Starting teacher_task_notification')]) self.assertEqual(Logger.error.call_args_list, []) - self.assertEqual(signals.assignment_created.send.call_args_list, + self.assertEqual(signals.assignment_created.send_robust.call_args_list, [call(instance=model.task, sender=model.task.__class__)]) diff --git a/breathecode/assignments/tests/urls/tests_task.py b/breathecode/assignments/tests/urls/tests_task.py index 7daccbc19..90dbb5db8 100644 --- a/breathecode/assignments/tests/urls/tests_task.py +++ b/breathecode/assignments/tests/urls/tests_task.py @@ -43,8 +43,8 @@ class MediaTestSuite(AssignmentsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__without_auth(self): url = reverse_lazy('assignments:task') response = self.client.get(url) @@ -60,8 +60,8 @@ def test_task__without_auth(self): 🔽🔽🔽 Get without ProfileAcademy """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__without_profile_academy(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -83,8 +83,8 @@ def test_task__without_profile_academy(self): 🔽🔽🔽 Get without Task """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__without_data(self): model = self.bc.database.create(user=1, profile_academy=1) self.client.force_authenticate(model.user) @@ -103,8 +103,8 @@ def test_task__without_data(self): 🔽🔽🔽 Get with Task """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__one_task__cohort_null(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -123,8 +123,8 @@ def test_task__one_task__cohort_null(self): 🔽🔽🔽 Get with two Task """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__two_tasks(self): model = self.bc.database.create(profile_academy=1, task=2) self.client.force_authenticate(model.user) @@ -143,8 +143,8 @@ def test_task__two_tasks(self): 🔽🔽🔽 Query academy """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_academy__found_zero__academy_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -159,8 +159,8 @@ def test_task__query_academy__found_zero__academy_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_academy__found_one(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -175,8 +175,8 @@ def test_task__query_academy__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_academy__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -195,8 +195,8 @@ def test_task__query_academy__found_two(self): 🔽🔽🔽 Query user """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_user__found_zero__user_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -211,8 +211,8 @@ def test_task__query_user__found_zero__user_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_user__found_one(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -227,8 +227,8 @@ def test_task__query_user__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_user__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -243,8 +243,8 @@ def test_task__query_user__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_user__found_two__related_to_two_users(self): tasks = [{'user_id': 1}, {'user_id': 2}] model = self.bc.database.create(profile_academy=1, user=2, task=tasks, cohort=1) @@ -264,8 +264,8 @@ def test_task__query_user__found_two__related_to_two_users(self): 🔽🔽🔽 Query cohort """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__id__found_zero__cohort_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -280,8 +280,8 @@ def test_task__query_cohort__id__found_zero__cohort_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__slug__found_zero__cohort_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -296,8 +296,8 @@ def test_task__query_cohort__slug__found_zero__cohort_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__id__found_one(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -312,8 +312,8 @@ def test_task__query_cohort__id__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__slug__found_one(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -328,8 +328,8 @@ def test_task__query_cohort__slug__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__id__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -344,8 +344,8 @@ def test_task__query_cohort__id__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__slug__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -360,8 +360,8 @@ def test_task__query_cohort__slug__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__id__found_two__related_to_two_users(self): tasks = [{'cohort_id': 1}, {'cohort_id': 2}] model = self.bc.database.create(profile_academy=1, user=1, task=tasks, cohort=2) @@ -377,8 +377,8 @@ def test_task__query_cohort__id__found_two__related_to_two_users(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_cohort__slug__found_two__related_to_two_users(self): tasks = [{'cohort_id': 1}, {'cohort_id': 2}] model = self.bc.database.create(profile_academy=1, user=1, task=tasks, cohort=2) @@ -398,8 +398,8 @@ def test_task__query_cohort__slug__found_two__related_to_two_users(self): 🔽🔽🔽 Query stu_cohort """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__id__found_zero__cohort_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -414,8 +414,8 @@ def test_task__query_stu_cohort__id__found_zero__cohort_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__slug__found_zero__cohort_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -430,9 +430,9 @@ def test_task__query_stu_cohort__slug__found_zero__cohort_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__id__found_one(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1, cohort_user=1) self.client.force_authenticate(model.user) @@ -447,9 +447,9 @@ def test_task__query_stu_cohort__id__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__slug__found_one(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1, cohort_user=1) self.client.force_authenticate(model.user) @@ -464,9 +464,9 @@ def test_task__query_stu_cohort__slug__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__id__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1, cohort_user=1) self.client.force_authenticate(model.user) @@ -481,9 +481,9 @@ def test_task__query_stu_cohort__id__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__slug__found_two(self): model = self.bc.database.create(profile_academy=1, task=2, cohort=1, cohort_user=1) self.client.force_authenticate(model.user) @@ -498,9 +498,9 @@ def test_task__query_stu_cohort__slug__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__id__found_two__related_to_two_users(self): tasks = [{'cohort_id': 1, 'user_id': 1}, {'cohort_id': 2, 'user_id': 2}] cohort_users = [{'cohort_id': 1, 'user_id': 1}, {'cohort_id': 2, 'user_id': 2}] @@ -517,9 +517,9 @@ def test_task__query_stu_cohort__id__found_two__related_to_two_users(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_stu_cohort__slug__found_two__related_to_two_users(self): tasks = [{'cohort_id': 1, 'user_id': 1}, {'cohort_id': 2, 'user_id': 2}] cohort_users = [{'cohort_id': 1, 'user_id': 1}, {'cohort_id': 2, 'user_id': 2}] @@ -540,8 +540,8 @@ def test_task__query_stu_cohort__slug__found_two__related_to_two_users(self): 🔽🔽🔽 Query edu_status """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_edu_status__found_zero__edu_status_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1) self.client.force_authenticate(model.user) @@ -556,9 +556,9 @@ def test_task__query_edu_status__found_zero__edu_status_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_edu_status__found_one(self): cohort_user = {'user_id': 1, 'educational_status': 'ACTIVE'} model = self.bc.database.create(profile_academy=1, task=1, cohort=1, cohort_user=cohort_user) @@ -574,9 +574,9 @@ def test_task__query_edu_status__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_edu_status__found_two(self): cohort_user = {'user_id': 1, 'educational_status': 'ACTIVE'} model = self.bc.database.create(profile_academy=1, task=2, cohort=1, cohort_user=cohort_user) @@ -592,9 +592,9 @@ def test_task__query_edu_status__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_edu_status__found_two__related_to_two_edu_status(self): tasks = [{'user_id': 1, 'cohort_id': 1}, {'user_id': 2, 'cohort_id': 2}] cohort_users = [ @@ -624,8 +624,8 @@ def test_task__query_edu_status__found_two__related_to_two_edu_status(self): 🔽🔽🔽 Query teacher """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_teacher__found_zero__academy_not_exists(self): model = self.bc.database.create(profile_academy=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -640,8 +640,8 @@ def test_task__query_teacher__found_zero__academy_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_teacher__found_one(self): cohort_users = [ { @@ -668,8 +668,8 @@ def test_task__query_teacher__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_teacher__found_two(self): tasks = [{'user_id': 1, 'cohort_id': 1}, {'user_id': 1, 'cohort_id': 2}] cohort_users = [ @@ -711,8 +711,8 @@ def test_task__query_teacher__found_two(self): 🔽🔽🔽 Query task_status """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_status__found_zero__task_status_not_exists(self): task = {'task_status': 'PENDING'} model = self.bc.database.create(profile_academy=1, task=task) @@ -728,8 +728,8 @@ def test_task__query_task_status__found_zero__task_status_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_status__found_one(self): task = {'user_id': 1, 'task_status': 'DONE'} model = self.bc.database.create(profile_academy=1, task=task) @@ -745,8 +745,8 @@ def test_task__query_task_status__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_status__found_two(self): tasks = [{'user_id': 1, 'task_status': 'DONE'}, {'user_id': 1, 'task_status': 'DONE'}] model = self.bc.database.create(profile_academy=1, task=tasks) @@ -763,8 +763,8 @@ def test_task__query_task_status__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_status__found_two__related_to_two_task_status(self): tasks = [{'task_status': 'DONE'}, {'task_status': 'PENDING'}] model = self.bc.database.create(profile_academy=1, user=1, task=tasks) @@ -784,8 +784,8 @@ def test_task__query_task_status__found_two__related_to_two_task_status(self): 🔽🔽🔽 Query revision_status """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_revision_status__found_zero__revision_status_not_exists(self): task = {'revision_status': 'PENDING'} model = self.bc.database.create(profile_academy=1, task=task) @@ -801,8 +801,8 @@ def test_task__query_revision_status__found_zero__revision_status_not_exists(sel self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_revision_status__found_one(self): task = {'user_id': 1, 'revision_status': 'APPROVED'} model = self.bc.database.create(profile_academy=1, task=task) @@ -818,8 +818,8 @@ def test_task__query_revision_status__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_revision_status__found_two(self): tasks = [{'user_id': 1, 'revision_status': 'APPROVED'}, {'user_id': 1, 'revision_status': 'APPROVED'}] model = self.bc.database.create(profile_academy=1, task=tasks) @@ -835,8 +835,8 @@ def test_task__query_revision_status__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_revision_status__found_two__related_to_two_revision_status(self): tasks = [{'revision_status': 'APPROVED'}, {'revision_status': 'PENDING'}] model = self.bc.database.create(profile_academy=1, user=1, task=tasks) @@ -856,8 +856,8 @@ def test_task__query_revision_status__found_two__related_to_two_revision_status( 🔽🔽🔽 Query task_type """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_type__found_zero__task_type_not_exists(self): task = {'task_type': 'QUIZ'} model = self.bc.database.create(profile_academy=1, task=task) @@ -873,8 +873,8 @@ def test_task__query_task_type__found_zero__task_type_not_exists(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_type__found_one(self): task = {'user_id': 1, 'task_type': 'PROJECT'} model = self.bc.database.create(profile_academy=1, task=task) @@ -890,8 +890,8 @@ def test_task__query_task_type__found_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), [self.bc.format.to_dict(model.task)]) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_task_type__found_two(self): tasks = [{'user_id': 1, 'task_type': 'PROJECT'}, {'user_id': 1, 'task_type': 'PROJECT'}] model = self.bc.database.create(profile_academy=1, task=tasks) @@ -907,8 +907,8 @@ def test_task__query_task_type__found_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.bc.database.list_of('assignments.Task'), self.bc.format.to_dict(model.task)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task__query_revision_status__found_two__related_to_two_revision_status(self): tasks = [{'task_type': 'PROJECT'}, {'task_type': 'QUIZ'}] model = self.bc.database.create(profile_academy=1, user=1, task=tasks) diff --git a/breathecode/assignments/tests/urls/tests_task_id.py b/breathecode/assignments/tests/urls/tests_task_id.py index e516ae3d9..0690486b1 100644 --- a/breathecode/assignments/tests/urls/tests_task_id.py +++ b/breathecode/assignments/tests/urls/tests_task_id.py @@ -95,8 +95,8 @@ class MediaTestSuite(AssignmentsTestCase): 🔽🔽🔽 Auth """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__without_auth(self): url = reverse_lazy('assignments:task_id', kwargs={'task_id': 1}) response = self.client.get(url) @@ -113,8 +113,8 @@ def test_task_id__without_auth(self): 🔽🔽🔽 Get without Task """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__without_task(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -134,8 +134,8 @@ def test_task_id__without_task(self): 🔽🔽🔽 Get with Task """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__with_one_task(self): model = self.bc.database.create(user=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -155,8 +155,8 @@ def test_task_id__with_one_task(self): 🔽🔽🔽 Get with Task but the other user """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__with_one_task__but_the_other_user(self): task = {'user_id': 2} model = self.bc.database.create(user=2, task=task, cohort=1) @@ -179,8 +179,8 @@ def test_task_id__with_one_task__but_the_other_user(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__without_tasks(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -207,8 +207,8 @@ def test_task_id__put__without_tasks(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -244,8 +244,8 @@ def test_task_id__put__with_one_task(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_task_status(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -278,8 +278,8 @@ def test_task_id__put__with_one_task__with_task_status(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_live_url(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -312,8 +312,8 @@ def test_task_id__put__with_one_task__with_live_url(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_github_url(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -346,8 +346,8 @@ def test_task_id__put__with_one_task__with_github_url(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_revision_status(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -375,8 +375,8 @@ def test_task_id__put__with_one_task__with_revision_status(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_revision_status__teacher_auth(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -437,8 +437,8 @@ def test_task_id__put__with_one_task__with_revision_status__teacher_auth(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_id__put__with_one_task__with_revision_status__staff_auth(self): from breathecode.assignments.tasks import student_task_notification, teacher_task_notification @@ -485,8 +485,8 @@ def test_task_id__put__with_one_task__with_revision_status__staff_auth(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_status_pending_and_revision_status_pending(self): """Test /task with task_status = pending and revision_status = pending should pass""" @@ -519,8 +519,8 @@ def test_task_status_pending_and_revision_status_pending(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_status_pending_and_revision_status_approved(self): """Test /task with task_status = pending and revision_status = approved should fail""" @@ -554,8 +554,8 @@ def test_task_status_pending_and_revision_status_approved(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_task_status_pending_and_revision_status_approved_both(self): """Test /task with task_status = pending and revision_status = approved should fail""" @@ -583,8 +583,8 @@ def test_task_status_pending_and_revision_status_approved_both(self): self.assertEqual(teacher_task_notification.delay.call_args_list, []) self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_task_not_found(self): model = self.bc.database.create(user=1) @@ -601,8 +601,8 @@ def test_delete_task_not_found(self): self.assertEqual(self.bc.database.list_of('assignments.Task'), []) self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_task_found_and_deleted(self): model = self.bc.database.create(user=1, task=1, cohort=1) @@ -615,8 +615,8 @@ def test_delete_task_found_and_deleted(self): self.assertEqual(self.bc.database.list_of('assignments.Task'), []) self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_task_associated_with_another_user(self): model = self.bc.database.create(user=2, task=1, cohort=1) diff --git a/breathecode/assignments/tests/urls/tests_user_me_project.py b/breathecode/assignments/tests/urls/tests_user_me_project.py index 71cd0c69e..44071c473 100644 --- a/breathecode/assignments/tests/urls/tests_user_me_project.py +++ b/breathecode/assignments/tests/urls/tests_user_me_project.py @@ -78,7 +78,7 @@ def test_final_project_when_not_a_member(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_final_project_members_from_different_cohort(self): self.bc.request.set_headers(academy=1) @@ -123,7 +123,7 @@ def test_final_project_without_cohort(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_final_project(self): self.bc.request.set_headers(academy=1) diff --git a/breathecode/assignments/tests/urls/tests_user_me_task.py b/breathecode/assignments/tests/urls/tests_user_me_task.py index feed85959..85c52374b 100644 --- a/breathecode/assignments/tests/urls/tests_user_me_task.py +++ b/breathecode/assignments/tests/urls/tests_user_me_task.py @@ -146,9 +146,9 @@ class MediaTestSuite(AssignmentsTestCase): 🔽🔽🔽 Auth """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__without_auth(self): url = reverse_lazy('assignments:user_me_task') response = self.client.get(url) @@ -165,9 +165,9 @@ def test_user_me_task__without_auth(self): 🔽🔽🔽 Get without Task """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__without_task(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -187,9 +187,9 @@ def test_user_me_task__without_task(self): 🔽🔽🔽 Get with one Task """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_one_task(self): model = self.bc.database.create(user=1, task=1, cohort=1) self.client.force_authenticate(model.user) @@ -209,9 +209,9 @@ def test_user_me_task__with_one_task(self): 🔽🔽🔽 Get with two Task """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_two_task(self): model = self.bc.database.create(user=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -231,9 +231,9 @@ def test_user_me_task__with_two_task(self): 🔽🔽🔽 Get with querystring assets """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_query_string_assets(self): model = self.bc.database.create(user=1, task=[{ @@ -259,9 +259,9 @@ def test_user_me_task__with_query_string_assets(self): 🔽🔽🔽 Get with querystring assets no results """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_query_string_assets_no_results(self): model = self.bc.database.create(user=1, task=[{ @@ -287,9 +287,9 @@ def test_user_me_task__with_query_string_assets_no_results(self): 🔽🔽🔽 Get with one Task but the other user """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_one_task__but_the_other_user(self): task = {'user_id': 2} model = self.bc.database.create(user=2, task=task, cohort=1) @@ -310,9 +310,9 @@ def test_user_me_task__with_one_task__but_the_other_user(self): 🔽🔽🔽 Get with two Task but the other user """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_user_me_task__with_two_tasks__but_the_other_user(self): task = {'user_id': 2} model = self.bc.database.create(user=2, task=(2, task), cohort=1) @@ -333,9 +333,9 @@ def test_user_me_task__with_two_tasks__but_the_other_user(self): 🔽🔽🔽 Delete """ - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_tasks_in_bulk_found_and_deleted(self): model = self.bc.database.create(user=1, task=2, cohort=1) @@ -349,9 +349,9 @@ def test_delete_tasks_in_bulk_found_and_deleted(self): self.assertEqual(self.bc.database.list_of('assignments.Task'), []) self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_tasks_in_bulk_tasks_not_found(self): model = self.bc.database.create(user=1) @@ -385,9 +385,9 @@ def test_delete_tasks_in_bulk_tasks_not_found(self): self.assertEqual(self.bc.database.list_of('assignments.Task'), []) self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_task_in_bulk_associated_with_another_user(self): model = self.bc.database.create(user=2, task=2, cohort=1) @@ -423,9 +423,9 @@ def test_delete_task_in_bulk_associated_with_another_user(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put__without_task(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -444,9 +444,9 @@ def test_put__without_task(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__without_task__passing_list(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -468,9 +468,9 @@ def test__put__without_task__passing_list(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__without_task__one_item_in_body(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -493,9 +493,9 @@ def test__put__without_task__one_item_in_body(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__without_task__one_item_in_body__with_id(self): model = self.bc.database.create(user=1) self.client.force_authenticate(model.user) @@ -518,10 +518,10 @@ def test__put__without_task__one_item_in_body__with_id(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_passing_taks_id(self): model = self.bc.database.create(user=1, task=2, cohort=1) self.client.force_authenticate(model.user) @@ -540,9 +540,9 @@ def test_put_passing_taks_id(self): self.bc.check.calls(activity_tasks.add_activity.delay.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_put_passing_random_values_to_update_task(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): model = self.bc.database.create(user=1, task=2, cohort=2) @@ -590,9 +590,9 @@ def test_put_passing_random_values_to_update_task(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__with_task__one_item_in_body__passing_revision_status(self): statuses = ['APPROVED', 'REJECTED', 'IGNORED'] for index in range(0, 3): @@ -631,9 +631,9 @@ def test__put__with_task__one_item_in_body__passing_revision_status(self): @patch('breathecode.assignments.tasks.student_task_notification', MagicMock()) @patch('breathecode.assignments.tasks.teacher_task_notification', MagicMock()) - @patch('breathecode.assignments.signals.assignment_status_updated.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.assignments.signals.assignment_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__put__with_task__one_item_in_body__passing_revision_status__teacher_token(self): statuses = ['APPROVED', 'REJECTED', 'IGNORED'] for index in range(0, 3): @@ -698,8 +698,8 @@ def test__put__with_task__one_item_in_body__passing_revision_status__teacher_tok @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_data(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): model = self.bc.database.create(user=1, task=2, cohort=2) diff --git a/breathecode/authenticate/models.py b/breathecode/authenticate/models.py index f0fb7586f..18a66eeba 100644 --- a/breathecode/authenticate/models.py +++ b/breathecode/authenticate/models.py @@ -233,7 +233,7 @@ def save(self, *args, **kwargs): tasks_authenticate.async_validate_email_invite.delay(self.id) if status_updated: - signals.invite_status_updated.send(instance=self, sender=UserInvite) + signals.invite_status_updated.send_robust(instance=self, sender=UserInvite) self._email = self.email self._old_status = self.status @@ -280,7 +280,7 @@ def __str__(self): def save(self, *args, **kwargs): if self.__old_status != self.status and self.status == 'ACTIVE': - academy_invite_accepted.send(instance=self, sender=ProfileAcademy) + academy_invite_accepted.send_robust(instance=self, sender=ProfileAcademy) super().save(*args, **kwargs) # Call the "real" save() method. diff --git a/breathecode/authenticate/receivers.py b/breathecode/authenticate/receivers.py index 3ac01cfe7..27c184d7b 100644 --- a/breathecode/authenticate/receivers.py +++ b/breathecode/authenticate/receivers.py @@ -27,7 +27,7 @@ @receiver(post_save) def update_user_group(sender, instance, created: bool, **_): # redirect to other signal to be able to mock it - user_info_updated.send(sender=sender, instance=instance, created=created) + user_info_updated.send_robust(sender=sender, instance=instance, created=created) @receiver(user_info_updated) @@ -68,7 +68,7 @@ def set_user_group(sender, instance, created: bool, **_): @receiver(post_delete) def delete_user_group(sender, instance, **_): # redirect to other signal to be able to mock it - user_info_deleted.send(sender=sender, instance=instance) + user_info_deleted.send_robust(sender=sender, instance=instance) @receiver(user_info_deleted) @@ -103,7 +103,7 @@ def unset_user_group(sender, instance, **_): @receiver(pre_delete, sender=CohortUser) def delete_cohort_user(sender, instance, **_): - cohort_user_deleted.send(sender=sender, instance=instance) + cohort_user_deleted.send_robust(sender=sender, instance=instance) @receiver(cohort_user_deleted, sender=CohortUser) diff --git a/breathecode/authenticate/tests/actions/tests_github_sync.py b/breathecode/authenticate/tests/actions/tests_github_sync.py index 19a56e8e8..8077f8e11 100644 --- a/breathecode/authenticate/tests/actions/tests_github_sync.py +++ b/breathecode/authenticate/tests/actions/tests_github_sync.py @@ -27,7 +27,7 @@ def test_add_to_organization_no_cohort(self): self.assertEqual(context.exception.slug, 'invalid-cohort-user') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_add_to_organization_success(self): """ When a student enters into a cohort, but he was not in the academy @@ -43,7 +43,7 @@ def test_add_to_organization_success(self): self.assertEqual('PENDING', users[0]['storage_status']) self.assertEqual('ADD', users[0]['storage_action']) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_add_to_organization_already_added(self): """ No need to double add student if it was already added previously @@ -61,7 +61,7 @@ def test_add_to_organization_already_added(self): self.assertEqual('SYNCHED', users[0]['storage_status']) self.assertEqual('ADD', users[0]['storage_action']) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_add_to_organization_success_previously_errored(self): """ It there was a previous error, we should still try and re-attempt @@ -93,7 +93,7 @@ def test_remove_from_organization__no_cohort(self): self.assertEqual(context.exception.slug, 'invalid-cohort-user') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_remove_from_organization__no_org_user(self): """ If user its not part of an organization, it cannot be removed @@ -111,7 +111,7 @@ def test_remove_from_organization__no_org_user(self): self.assertEqual(context.exception.slug, 'user-not-found-in-org') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_remove_from_organization__still_active(self): """ Trying to remove someone that its still active in any cohort @@ -130,8 +130,8 @@ def test_remove_from_organization__still_active(self): self.assertEqual(context.exception.slug, 'still-active') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) - @patch('django.db.models.signals.post_save.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) + @patch('django.db.models.signals.post_save.send_robust', MagicMock()) def test_remove_from_organization__still_active_another_org(self): """ Trying to remove someone that its still active in another diff --git a/breathecode/authenticate/tests/receivers/tests_unset_user_group.py b/breathecode/authenticate/tests/receivers/tests_unset_user_group.py index ea139e21d..3ed8fbe79 100644 --- a/breathecode/authenticate/tests/receivers/tests_unset_user_group.py +++ b/breathecode/authenticate/tests/receivers/tests_unset_user_group.py @@ -12,7 +12,7 @@ class TestModelProfileAcademy(LegacyAPITestCase): 🔽🔽🔽 Adding a ProfileAcademy, with bad role """ - @patch('django.db.models.signals.post_save.send', MagicMock()) + @patch('django.db.models.signals.post_save.send_robust', MagicMock()) def test_adding_a_profile_academy__with_bad_role(self, enable_signals): enable_signals() @@ -27,7 +27,7 @@ def test_adding_a_profile_academy__with_bad_role(self, enable_signals): 🔽🔽🔽 Adding a ProfileAcademy, with right role, status INVITED """ - @patch('django.db.models.signals.post_save.send', MagicMock()) + @patch('django.db.models.signals.post_save.send_robust', MagicMock()) def test_adding_a_profile_academy__with_right_role__status_invited(self, enable_signals): enable_signals() @@ -50,7 +50,7 @@ def test_adding_a_profile_academy__with_right_role__status_invited(self, enable_ 🔽🔽🔽 Adding a ProfileAcademy, with right role, status ACTIVE """ - @patch('django.db.models.signals.post_save.send', MagicMock()) + @patch('django.db.models.signals.post_save.send_robust', MagicMock()) def test_adding_a_profile_academy__with_right_role__status_active(self, enable_signals): enable_signals() @@ -72,7 +72,7 @@ def test_adding_a_profile_academy__with_right_role__status_active(self, enable_s 🔽🔽🔽 Adding two ProfileAcademy, with right role, status ACTIVE """ - @patch('django.db.models.signals.post_save.send', MagicMock()) + @patch('django.db.models.signals.post_save.send_robust', MagicMock()) def test_adding_two_profile_academy__with_right_role__status_active(self, enable_signals): enable_signals() diff --git a/breathecode/authenticate/tests/urls/tests_github_callback.py b/breathecode/authenticate/tests/urls/tests_github_callback.py index 8c15fc022..256ba842f 100644 --- a/breathecode/authenticate/tests/urls/tests_github_callback.py +++ b/breathecode/authenticate/tests/urls/tests_github_callback.py @@ -11,9 +11,8 @@ from rest_framework import status from rest_framework.test import APIClient -from breathecode.tests.mixins.breathecode_mixin.breathecode import Breathecode - from breathecode.authenticate.tests.mocks.mocks import FakeResponse +from breathecode.tests.mixins.breathecode_mixin.breathecode import Breathecode from ...models import Role from ..mixins.new_auth_test_case import AuthTestCase @@ -39,8 +38,8 @@ def post_mock(url, *args, **kwargs): monkeypatch.setattr('requests.get', GithubRequestsMock.apply_get_requests_mock()) monkeypatch.setattr('requests.post', post_mock) - monkeypatch.setattr('django.db.models.signals.pre_delete.send', mock.MagicMock(return_value=None)) - monkeypatch.setattr('breathecode.admissions.signals.student_edu_status_updated.send', + monkeypatch.setattr('django.db.models.signals.pre_delete.send_robust', mock.MagicMock(return_value=None)) + monkeypatch.setattr('breathecode.admissions.signals.student_edu_status_updated.send_robust', mock.MagicMock(return_value=None)) yield diff --git a/breathecode/authenticate/tests/urls/tests_member_invite_token.py b/breathecode/authenticate/tests/urls/tests_member_invite_token.py index b83ed104a..d54c082f3 100644 --- a/breathecode/authenticate/tests/urls/tests_member_invite_token.py +++ b/breathecode/authenticate/tests/urls/tests_member_invite_token.py @@ -188,8 +188,8 @@ class AuthenticateTestSuite(AuthTestCase): 🔽🔽🔽 GET without UserInvite """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__without_user_invite(self): url = reverse_lazy('authenticate:member_invite_token', kwargs={'token': 'invalid'}) response = self.client.get(url) @@ -214,8 +214,8 @@ def test_member_invite_token__without_user_invite(self): """ @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__with_user_invite(self): model = self.bc.database.create(user_invite=1) @@ -244,8 +244,8 @@ def test_member_invite_token__with_user_invite(self): """ @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__with_user_invite__already_as_user(self): user = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user, user=user) @@ -277,8 +277,8 @@ def test_member_invite_token__with_user_invite__already_as_user(self): """ @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__with_user_invite__user_with_another_email(self): user = {'email': 'user1@dotdotdotdot.dot'} user_invite = {'email': 'user2@dotdotdotdot.dot'} @@ -309,8 +309,8 @@ def test_member_invite_token__with_user_invite__user_with_another_email(self): """ @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__bad_token(self): url = reverse_lazy('authenticate:member_invite_token', kwargs={'token': 'invalid'}) data = {} @@ -339,8 +339,8 @@ def test_member_invite_token__post__bad_token(self): """ @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__bad_first_and_last_name(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -377,8 +377,8 @@ def test_member_invite_token__post__bad_first_and_last_name(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__password_is_empty(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -415,8 +415,8 @@ def test_member_invite_token__post__password_is_empty(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__passwords_does_not_match(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -458,8 +458,8 @@ def test_member_invite_token__post__passwords_does_not_match(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_first_name_last_name_and_passwords(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -515,8 +515,8 @@ def test_member_invite_token__post__with_first_name_last_name_and_passwords(self @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_first_name_last_name_and_passwords__with_callback(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -574,8 +574,8 @@ def test_member_invite_token__post__with_first_name_last_name_and_passwords__wit @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_first_name_last_name_and_passwords__with_profile_academy(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} model = self.bc.database.create(user=user, user_invite=user, profile_academy=user, role='reviewer') @@ -637,8 +637,8 @@ def test_member_invite_token__post__with_first_name_last_name_and_passwords__wit @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.build_plan_financing.delay', MagicMock(return_value=None)) def test__post__cohort_saas(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} @@ -710,8 +710,8 @@ def test__post__cohort_saas(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.build_plan_financing.delay', MagicMock(return_value=None)) def test__post__academy_saas(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} @@ -786,8 +786,8 @@ def test__post__academy_saas(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_cohort__with_role(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} model = self.bc.database.create(user=user, user_invite=user, cohort=1, role='student') @@ -842,8 +842,8 @@ def test_member_invite_token__post__with_cohort__with_role(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_cohort__with_role__accept_first_invite(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} user_invites = [{**user, 'cohort_id': 1}, {**user, 'cohort_id': 2}] @@ -897,8 +897,8 @@ def test_member_invite_token__post__with_cohort__with_role__accept_first_invite( @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_cohort__with_role__accept_second_invite(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} user_invites = [{**user, 'cohort_id': 1}, {**user, 'cohort_id': 2}] @@ -957,8 +957,8 @@ def test_member_invite_token__post__with_cohort__with_role__accept_second_invite @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_cohort__without_role_in_the_invite__role_student_exists(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} user_invite = {**user, 'role_id': None} @@ -1014,8 +1014,8 @@ def test_member_invite_token__post__with_cohort__without_role_in_the_invite__rol @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_member_invite_token__post__with_cohort__without_role(self): user = {'email': 'user@dotdotdotdot.dot', 'first_name': 'Lord', 'last_name': 'Valdomero'} model = self.bc.database.create(user=user, user_invite=user, cohort=1) @@ -1063,8 +1063,8 @@ def test_member_invite_token__post__with_cohort__without_role(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__json__password_is_empty(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) @@ -1092,8 +1092,8 @@ def test__post__json__password_is_empty(self): @patch('django.template.loader.render_to_string', MagicMock(side_effect=render_to_string_mock)) @patch('django.contrib.auth.hashers.get_hasher', MagicMock(side_effect=GetHasherMock)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test__post__json__with_first_name_last_name_and_passwords(self): user_invite = {'email': 'user@dotdotdotdot.dot'} model = self.bc.database.create(user_invite=user_invite) diff --git a/breathecode/authenticate/tests/urls/tests_user_me_invite_status.py b/breathecode/authenticate/tests/urls/tests_user_me_invite_status.py index dfda05e93..de96355d0 100644 --- a/breathecode/authenticate/tests/urls/tests_user_me_invite_status.py +++ b/breathecode/authenticate/tests/urls/tests_user_me_invite_status.py @@ -1,11 +1,13 @@ """ Set of tests for MeInviteView, this include duck tests """ +from random import choice from unittest.mock import MagicMock, PropertyMock, patch + from django.urls.base import reverse_lazy from rest_framework import status -from random import choice from rest_framework.response import Response + from ..mixins.new_auth_test_case import AuthTestCase @@ -21,7 +23,7 @@ class MemberSetOfDuckTestSuite(AuthTestCase): """ @patch('breathecode.authenticate.views.MeInviteView.get', MagicMock(side_effect=view_method_mock)) - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_duck_test__get__with_auth___mock_view(self): model = self.bc.database.create(user=3) @@ -42,7 +44,7 @@ def test_duck_test__get__with_auth___mock_view(self): """ @patch('breathecode.authenticate.views.MeInviteView.put', MagicMock(side_effect=view_method_mock)) - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_duck_test__put__with_auth___mock_view(self): model = self.bc.database.create(user=3) @@ -64,7 +66,7 @@ class AuthenticateTestSuite(AuthTestCase): 🔽🔽🔽 Auth """ - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__without_auth(self): """Test /academy/user/invite without auth""" url = reverse_lazy('authenticate:user_me_invite_status', kwargs={'new_status': 'pending'}) @@ -78,7 +80,7 @@ def test_user_me_invite_status__without_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__wrong_academy(self): self.bc.request.set_headers(academy=1) url = reverse_lazy('authenticate:user_me_invite_status', kwargs={'new_status': 'pending'}) @@ -89,7 +91,7 @@ def test_user_me_invite_status__wrong_academy(self): 🔽🔽🔽 PUT passing status is not allowed or invalid through of the url """ - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__passing_invalid_status(self): """Test academy/user/me/invite""" self.bc.request.set_headers(academy=1) @@ -119,7 +121,7 @@ def test_user_me_invite_status__passing_invalid_status(self): 🔽🔽🔽 PUT passing valid statuses through of the url """ - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__passing_valid_status__without_bulk_mode(self): """Test academy/user/me/invite""" self.bc.request.set_headers(academy=1) @@ -149,7 +151,7 @@ def test_user_me_invite_status__passing_valid_status__without_bulk_mode(self): 🔽🔽🔽 PUT bulk mode """ - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__to_accepted_in_bulk_with_ids(self): """Test academy/user/me/invite""" self.bc.request.set_headers(academy=1) @@ -246,7 +248,7 @@ def test_user_me_invite_status__to_accepted_in_bulk_with_ids(self): self.bc.format.to_dict(model1.user), ]) - @patch('breathecode.authenticate.signals.invite_status_updated.send', MagicMock()) + @patch('breathecode.authenticate.signals.invite_status_updated.send_robust', MagicMock()) def test_user_me_invite_status__to_accepted_invitations_not_matched(self): """Test academy/user/me/invite""" self.bc.request.set_headers(academy=1) diff --git a/breathecode/certificate/models.py b/breathecode/certificate/models.py index 2a9ff68b3..4bc83c476 100644 --- a/breathecode/certificate/models.py +++ b/breathecode/certificate/models.py @@ -1,10 +1,12 @@ import hashlib -from django.utils import timezone -from django.db import models + from django.contrib.auth.models import User from django.core.exceptions import ValidationError -from breathecode.admissions.models import Academy, Cohort, Syllabus +from django.db import models +from django.utils import timezone + import breathecode.certificate.signals as signals +from breathecode.admissions.models import Academy, Cohort, Syllabus __all__ = ['UserProxy', 'Specialty', 'Badge', 'LayoutDesign', 'UserSpecialty'] @@ -155,7 +157,10 @@ def save(self, *args, **kwargs): hash = self.generate_update_hash() self._hash_was_updated = self.update_hash != hash self.update_hash = hash + print(1, self._hash_was_updated) super().save(*args, **kwargs) # Call the "real" save() method. + print(2, signals.user_specialty_saved.send) + print(3, signals.user_specialty_saved.send_robust) - signals.user_specialty_saved.send(instance=self, sender=self.__class__) + signals.user_specialty_saved.send_robust(instance=self, sender=self.__class__) diff --git a/breathecode/certificate/receivers.py b/breathecode/certificate/receivers.py index eb3ae128b..2ab6b70a7 100644 --- a/breathecode/certificate/receivers.py +++ b/breathecode/certificate/receivers.py @@ -14,6 +14,9 @@ @receiver(user_specialty_saved, sender=UserSpecialty) def post_save_user_specialty(sender, instance: UserSpecialty, **kwargs): + print('instance._hash_was_updated', instance._hash_was_updated) + print('instance.status', instance.status) + print('instance.preview_url', instance.preview_url) if instance._hash_was_updated and instance.status == 'PERSISTED' and instance.preview_url: tasks.reset_screenshot.delay(instance.id) diff --git a/breathecode/certificate/tests/actions/tests_certificate_screenshot.py b/breathecode/certificate/tests/actions/tests_certificate_screenshot.py index 856f70377..d1cccef3b 100644 --- a/breathecode/certificate/tests/actions/tests_certificate_screenshot.py +++ b/breathecode/certificate/tests/actions/tests_certificate_screenshot.py @@ -2,15 +2,18 @@ Tasks tests """ import os +from unittest.mock import MagicMock, PropertyMock, call, patch +from urllib.parse import urlencode + import requests + import breathecode.certificate.signals as signals -from unittest.mock import MagicMock, PropertyMock, patch, call +from breathecode.services.google_cloud import File, Storage from breathecode.tests.mocks import apply_requests_get_mock -from urllib.parse import urlencode + from ...actions import certificate_screenshot -from ..mixins import CertificateTestCase from ...models import UserSpecialty -from breathecode.services.google_cloud import Storage, File +from ..mixins import CertificateTestCase token = '12345a67890b12345c67890d' query_string = urlencode({ @@ -32,7 +35,7 @@ class ActionCertificateScreenshotTestCase(CertificateTestCase): apply_requests_get_mock([ (200, f'https://api.screenshotmachine.com?{query_string}', 'mailgun response'), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) @patch('requests.get', apply_requests_get_mock([(200, f'https://api.screenshotmachine.com?{query_string}')])) @patch.multiple('breathecode.services.google_cloud.Storage', __init__=MagicMock(return_value=None), @@ -54,7 +57,7 @@ def test_certificate_screenshot__with_invalid_id(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) self.assertEqual(requests.get.call_args_list, []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) self.assertEqual(File.upload.call_args_list, []) self.assertEqual(File.url.call_args_list, []) @@ -67,7 +70,7 @@ def test_certificate_screenshot__with_invalid_id(self): apply_requests_get_mock([ (200, f'https://api.screenshotmachine.com?{query_string}', 'mailgun response'), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) @patch('requests.get', apply_requests_get_mock([(200, f'https://api.screenshotmachine.com?{query_string}')])) @patch.multiple('breathecode.services.google_cloud.Storage', __init__=MagicMock(return_value=None), @@ -101,7 +104,7 @@ def test_certificate_screenshot__with_invalid_preview_url__equal_to_empty_string call(f'https://api.screenshotmachine.com?{query_string}', stream=True), ]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -120,7 +123,7 @@ def test_certificate_screenshot__with_invalid_preview_url__equal_to_empty_string apply_requests_get_mock([ (200, f'https://api.screenshotmachine.com?{query_string}', 'mailgun response'), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) @patch.multiple('breathecode.services.google_cloud.Storage', __init__=MagicMock(return_value=None), client=PropertyMock(), @@ -153,7 +156,7 @@ def test_certificate_screenshot__with_invalid_preview_url__equal_to_none(self): call(f'https://api.screenshotmachine.com?{query_string}', stream=True), ]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -172,7 +175,7 @@ def test_certificate_screenshot__with_invalid_preview_url__equal_to_none(self): apply_requests_get_mock([ (200, f'https://api.screenshotmachine.com?{query_string}', 'mailgun response'), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) @patch.multiple('breathecode.services.google_cloud.Storage', __init__=MagicMock(return_value=None), client=PropertyMock(), @@ -203,7 +206,7 @@ def test_certificate_screenshot__with_invalid_preview_url__the_objects_exists_in self.assertEqual(requests.get.call_args_list, []) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -222,7 +225,7 @@ def test_certificate_screenshot__with_invalid_preview_url__the_objects_exists_in apply_requests_get_mock([ (200, f'https://api.screenshotmachine.com?{query_string}', 'mailgun response'), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) @patch.multiple('breathecode.services.google_cloud.Storage', __init__=MagicMock(return_value=None), client=PropertyMock(), @@ -252,7 +255,7 @@ def test_certificate_screenshot__with_correct_preview_url(self): ]) self.assertEqual(requests.get.call_args_list, []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) diff --git a/breathecode/certificate/tests/actions/tests_certificate_set_default_issued_at.py b/breathecode/certificate/tests/actions/tests_certificate_set_default_issued_at.py index 7862ad149..ae461b048 100644 --- a/breathecode/certificate/tests/actions/tests_certificate_set_default_issued_at.py +++ b/breathecode/certificate/tests/actions/tests_certificate_set_default_issued_at.py @@ -1,17 +1,20 @@ """ Tasks tests """ -from unittest.mock import patch, call, MagicMock +from unittest.mock import MagicMock, call, patch + +from django.utils import timezone + from breathecode.certificate import signals + from ...actions import certificate_set_default_issued_at -from ..mixins import CertificateTestCase from ...models import UserSpecialty -from django.utils import timezone +from ..mixins import CertificateTestCase class ActionCertificateSetDefaultIssuedAtTestCase(CertificateTestCase): - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_error(self): # the issues_at should remain None because the certificate generation gave an error. @@ -34,11 +37,11 @@ def test_issued_at_null_status_error(self): 'issued_at': None, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_set_status_error(self): # the issues_at should remain the same and not be modified because the certificate gave an error. @@ -64,11 +67,11 @@ def test_issued_at_set_status_error(self): 'issued_at': now, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_persisted_one_item(self): # The issued_at should remain None because the user_specialty does not have cohort specified, # and it is impossible to determine cohort ending_at @@ -93,11 +96,11 @@ def test_issued_at_null_status_persisted_one_item(self): 'issued_at': None, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_persisted_two_items(self): # both certificates should have issued_at None because both cohorts are null @@ -133,12 +136,12 @@ def test_issued_at_null_status_persisted_two_items(self): 'issued_at': None, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model1.user_specialty, sender=model1.user_specialty.__class__), call(instance=model2.user_specialty, sender=model2.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_persisted_one_item_with_cohort(self): model = self.generate_models(user_specialty=True, @@ -161,11 +164,11 @@ def test_issued_at_null_status_persisted_one_item_with_cohort(self): 'issued_at': model.cohort.ending_date, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_persisted_two_items_with_cohort(self): model1 = self.generate_models(user_specialty=True, @@ -199,12 +202,12 @@ def test_issued_at_null_status_persisted_two_items_with_cohort(self): 'issued_at': model2.cohort.ending_date, }])) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model1.user_specialty, sender=model1.user_specialty.__class__), call(instance=model2.user_specialty, sender=model2.user_specialty.__class__), ]) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_set_status_persisted(self): # issuet_at should remain the same because there was already a value so the default should no be applied. now = timezone.now() @@ -227,12 +230,12 @@ def test_issued_at_set_status_persisted(self): 'issued_at': now, }])) - self.assertEqual(str(signals.user_specialty_saved.send.call_args_list), + self.assertEqual(str(signals.user_specialty_saved.send_robust.call_args_list), str([ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_set_status_pending(self): # issuet_at should remain the same because there was already a value so the default should no be applied. @@ -252,12 +255,12 @@ def test_issued_at_set_status_pending(self): 'issued_at': now, }])) - self.assertEqual(str(signals.user_specialty_saved.send.call_args_list), + self.assertEqual(str(signals.user_specialty_saved.send_robust.call_args_list), str([ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ])) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_issued_at_null_status_pending(self): # issuet_at should remain the same because status=Pending @@ -280,7 +283,7 @@ def test_issued_at_null_status_pending(self): 'issued_at': None, }])) - self.assertEqual(str(signals.user_specialty_saved.send.call_args_list), + self.assertEqual(str(signals.user_specialty_saved.send_robust.call_args_list), str([ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ])) diff --git a/breathecode/certificate/tests/actions/tests_generate_certificate.py b/breathecode/certificate/tests/actions/tests_generate_certificate.py index 0082f46f0..a447ca434 100644 --- a/breathecode/certificate/tests/actions/tests_generate_certificate.py +++ b/breathecode/certificate/tests/actions/tests_generate_certificate.py @@ -66,9 +66,9 @@ def generate_update_hash(self, instance): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_user_without_cohort(self): model = self.generate_models(user=True) try: @@ -79,7 +79,7 @@ def test_generate_certificate__with_user_without_cohort(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 without CohortUser @@ -88,9 +88,9 @@ def test_generate_certificate__with_user_without_cohort(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_cohort_user(self): model = self.generate_models(user=True, cohort=True) try: @@ -101,19 +101,19 @@ def test_generate_certificate__without_cohort_user(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Cohort not ended """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__cohort_not_ended(self): cohort_user_kwargs = { 'finantial_status': 'FULLY_PAID', @@ -178,7 +178,7 @@ def test_generate_certificate__cohort_not_ended(self): [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -189,9 +189,9 @@ def test_generate_certificate__cohort_not_ended(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_syllabus_version(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, cohort=True, cohort_user=True, cohort_kwargs=cohort_kwargs) @@ -204,7 +204,7 @@ def test_generate_certificate__without_syllabus_version(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 without Specialty @@ -213,9 +213,9 @@ def test_generate_certificate__without_syllabus_version(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_specialty(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, @@ -232,7 +232,7 @@ def test_generate_certificate__without_specialty(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 without Syllabus @@ -241,9 +241,9 @@ def test_generate_certificate__without_specialty(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_syllabus(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, @@ -260,7 +260,7 @@ def test_generate_certificate__without_syllabus(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 without default Layout @@ -269,9 +269,9 @@ def test_generate_certificate__without_syllabus(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_specialty_layout(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, @@ -290,7 +290,7 @@ def test_generate_certificate__without_specialty_layout(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 without main teacher @@ -299,9 +299,9 @@ def test_generate_certificate__without_specialty_layout(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_teacher(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, @@ -321,7 +321,7 @@ def test_generate_certificate__without_teacher(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Bad financial status @@ -330,9 +330,9 @@ def test_generate_certificate__without_teacher(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_with_bad_student_financial_status(self): cohort_kwargs = {'stage': 'ENDED'} model = self.generate_models(user=True, @@ -385,7 +385,7 @@ def test_generate_certificate_with_bad_student_financial_status(self): [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -396,9 +396,9 @@ def test_generate_certificate_with_bad_student_financial_status(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_student_that_didnt_finish_tasks(self): cohort_kwargs = {'stage': 'ENDED'} task_kwargs = {'task_type': 'PROJECT', 'revision_status': 'PENDING'} @@ -474,7 +474,7 @@ def test_generate_certificate__with_student_that_didnt_finish_tasks(self): [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -485,9 +485,9 @@ def test_generate_certificate__with_student_that_didnt_finish_tasks(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_student_that_didnt_finish_tasks_without_mandatory(self): cohort_kwargs = {'stage': 'ENDED'} task_kwargs = {'task_type': 'PROJECT', 'revision_status': 'PENDING'} @@ -552,7 +552,7 @@ def test_generate_certificate__with_student_that_didnt_finish_tasks_without_mand [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -563,9 +563,9 @@ def test_generate_certificate__with_student_that_didnt_finish_tasks_without_mand @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_student_that_didnt_finish_mandatory_tasks(self): cohort_kwargs = {'stage': 'ENDED'} task_kwargs = {'task_type': 'PROJECT', 'revision_status': 'PENDING'} @@ -631,7 +631,7 @@ def test_generate_certificate__with_student_that_didnt_finish_mandatory_tasks(se [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -642,9 +642,9 @@ def test_generate_certificate__with_student_that_didnt_finish_mandatory_tasks(se @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__without_proper_educational_status(self): cohort_kwargs = {'stage': 'ENDED'} cohort_user_kwargs = {'finantial_status': 'FULLY_PAID'} @@ -697,7 +697,7 @@ def test_generate_certificate__without_proper_educational_status(self): [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -708,9 +708,9 @@ def test_generate_certificate__without_proper_educational_status(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_cohort_user__with_finantial_status_eq_up_to_date(self): cohort_kwargs = {'stage': 'ENDED'} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE'} @@ -763,7 +763,7 @@ def test_generate_certificate__with_cohort_user__with_finantial_status_eq_up_to_ [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -771,13 +771,13 @@ def test_generate_certificate__with_cohort_user__with_finantial_status_eq_up_to_ 🔽🔽🔽 Student dropped """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_cohort_user__with_educational_status_eq_dropped(self): cohort_kwargs = {'stage': 'ENDED'} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE', 'educational_status': 'DROPPED'} @@ -831,7 +831,7 @@ def test_generate_certificate__with_cohort_user__with_educational_status_eq_drop [expected]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -839,13 +839,13 @@ def test_generate_certificate__with_cohort_user__with_educational_status_eq_drop 🔽🔽🔽 Cohort not finished """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__with_cohort_not_finished(self): cohort_kwargs = {'stage': 'ENDED'} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE', 'educational_status': 'GRADUATED'} @@ -901,7 +901,7 @@ def test_generate_certificate__with_cohort_not_finished(self): }]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -909,13 +909,13 @@ def test_generate_certificate__with_cohort_not_finished(self): 🔽🔽🔽 Generate certificate """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate(self): cohort_kwargs = {'stage': 'ENDED', 'current_day': 9545799} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE', 'educational_status': 'GRADUATED'} @@ -981,7 +981,7 @@ def test_generate_certificate(self): }]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) @@ -989,13 +989,13 @@ def test_generate_certificate(self): 🔽🔽🔽 Translations """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__lang_en(self): cohort_kwargs = {'stage': 'ENDED', 'current_day': 9545799, 'language': 'en'} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE', 'educational_status': 'GRADUATED'} @@ -1063,17 +1063,17 @@ def test_generate_certificate__lang_en(self): }]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @pytest.mark.parametrize('current_day,duration_in_days,never_ends', [ (9545799, 9545799, False), (1, 9545799, True), @@ -1094,7 +1094,7 @@ def test_generate_certificate__lang_es(self, current_day, duration_in_days, neve cohort_user_kwargs=cohort_user_kwargs, syllabus_kwargs=syllabus_kwargs) - signals.user_specialty_saved.send.call_args_list = [] + signals.user_specialty_saved.send_robust.call_args_list = [] base = model.copy() del base['user'] @@ -1145,17 +1145,17 @@ def test_generate_certificate__lang_es(self, current_day, duration_in_days, neve }]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @pytest.mark.parametrize('stage', ['INACTIVE', 'PREWORK', 'STARTED', 'FINAL_PROJECT', 'ENDED']) def test_generate_certificate__lang_es__never_ends_true(self, stage): cohort_kwargs = {'stage': stage, 'current_day': 1, 'language': 'es', 'never_ends': True} @@ -1183,7 +1183,7 @@ def test_generate_certificate__lang_es__never_ends_true(self, stage): cohort_user_kwargs=cohort_user_kwargs, models=base) - signals.user_specialty_saved.send.call_args_list = [] + signals.user_specialty_saved.send_robust.call_args_list = [] start = timezone.now() result = self.remove_dinamics_fields(generate_certificate(model['user'], model['cohort']).__dict__) @@ -1225,17 +1225,17 @@ def test_generate_certificate__lang_es__never_ends_true(self, stage): }]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__lang_es__never_ends_true__stage_deleted(self): stage = 'DELETED' cohort_kwargs = {'stage': stage, 'current_day': 1, 'language': 'es', 'never_ends': True} @@ -1260,25 +1260,25 @@ def test_generate_certificate__lang_es__never_ends_true__stage_deleted(self): cohort_user_kwargs = {'role': 'TEACHER'} self.generate_models(user=True, cohort_user=True, cohort_user_kwargs=cohort_user_kwargs, models=base) - signals.user_specialty_saved.send.call_args_list = [] + signals.user_specialty_saved.send_robust.call_args_list = [] with pytest.raises(ValidationException, match='missing-cohort-user'): self.remove_dinamics_fields(generate_certificate(model['user'], model['cohort']).__dict__) self.assertEqual(self.clear_preview_url(self.bc.database.list_of('certificate.UserSpecialty')), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Retry generate certificate """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate__retry_generate_certificate(self): cohort_kwargs = {'stage': 'ENDED', 'current_day': 9545799} cohort_user_kwargs = {'finantial_status': 'UP_TO_DATE', 'educational_status': 'GRADUATED'} @@ -1317,6 +1317,6 @@ def test_generate_certificate__retry_generate_certificate(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), [user_specialty]) user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=user_specialty, sender=user_specialty.__class__), ]) diff --git a/breathecode/certificate/tests/actions/tests_remove_certificate_screenshot.py b/breathecode/certificate/tests/actions/tests_remove_certificate_screenshot.py index e3e906a24..b2615b679 100644 --- a/breathecode/certificate/tests/actions/tests_remove_certificate_screenshot.py +++ b/breathecode/certificate/tests/actions/tests_remove_certificate_screenshot.py @@ -2,11 +2,30 @@ Tasks tests """ from unittest.mock import MagicMock, PropertyMock, call, patch + +import pytest + +import breathecode.certificate.signals as signals +from breathecode.services.google_cloud import File, Storage + from ...actions import remove_certificate_screenshot -from ..mixins import CertificateTestCase from ...models import UserSpecialty -import breathecode.certificate.signals as signals -from breathecode.services.google_cloud import Storage, File +from ..mixins import CertificateTestCase + + +@pytest.fixture(autouse=True) +def setup(db, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + monkeypatch.setattr('breathecode.services.google_cloud.Storage.__init__', MagicMock(return_value=None)) + monkeypatch.setattr('breathecode.services.google_cloud.Storage.client', PropertyMock(), raising=False) + monkeypatch.setattr('breathecode.services.google_cloud.File.__init__', MagicMock(return_value=None)) + monkeypatch.setattr('breathecode.services.google_cloud.File.bucket', PropertyMock(), raising=False) + monkeypatch.setattr('breathecode.services.google_cloud.File.file_name', PropertyMock(), raising=False) + monkeypatch.setattr('breathecode.services.google_cloud.File.blob', PropertyMock(return_value=1), raising=False) + monkeypatch.setattr('breathecode.services.google_cloud.File.upload', MagicMock()) + monkeypatch.setattr('breathecode.services.google_cloud.File.delete', MagicMock()) + monkeypatch.setattr('breathecode.services.google_cloud.File.url', + MagicMock(return_value='https://xyz/hardcoded_url')) class ActionCertificateScreenshotTestCase(CertificateTestCase): @@ -15,20 +34,6 @@ class ActionCertificateScreenshotTestCase(CertificateTestCase): 🔽🔽🔽 UserSpecialty not exists """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch.multiple('breathecode.services.google_cloud.Storage', - __init__=MagicMock(return_value=None), - client=PropertyMock(), - create=True) - @patch.multiple('breathecode.services.google_cloud.File', - __init__=MagicMock(return_value=None), - bucket=PropertyMock(), - file_name=PropertyMock(), - blob=PropertyMock(return_value=1), - upload=MagicMock(), - delete=MagicMock(), - url=MagicMock(return_value='https://xyz/hardcoded_url'), - create=True) def test_remove_certificate_screenshot_with_invalid_id(self): """remove_certificate_screenshot don't call open in development environment""" @@ -37,27 +42,13 @@ def test_remove_certificate_screenshot_with_invalid_id(self): self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) self.assertEqual(File.delete.call_args_list, []) """ 🔽🔽🔽 With preview_url as a empty string """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch.multiple('breathecode.services.google_cloud.Storage', - __init__=MagicMock(return_value=None), - client=PropertyMock(), - create=True) - @patch.multiple('breathecode.services.google_cloud.File', - __init__=MagicMock(return_value=None), - bucket=PropertyMock(), - file_name=PropertyMock(), - blob=PropertyMock(return_value=1), - upload=MagicMock(), - delete=MagicMock(), - url=MagicMock(return_value='https://xyz/hardcoded_url'), - create=True) def test_remove_certificate_screenshot__with_preview_url_as_empty_string(self): """remove_certificate_screenshot don't call open in development environment""" @@ -73,7 +64,7 @@ def test_remove_certificate_screenshot__with_preview_url_as_empty_string(self): }, ]) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) self.assertEqual(File.delete.call_args_list, []) @@ -82,20 +73,6 @@ def test_remove_certificate_screenshot__with_preview_url_as_empty_string(self): 🔽🔽🔽 With preview_url as a None """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch.multiple('breathecode.services.google_cloud.Storage', - __init__=MagicMock(return_value=None), - client=PropertyMock(), - create=True) - @patch.multiple('breathecode.services.google_cloud.File', - __init__=MagicMock(return_value=None), - bucket=PropertyMock(), - file_name=PropertyMock(), - blob=PropertyMock(return_value=1), - upload=MagicMock(), - delete=MagicMock(), - url=MagicMock(return_value='https://xyz/hardcoded_url'), - create=True) def test_remove_certificate_screenshot__with_preview_url_as_none(self): """remove_certificate_screenshot don't call open in development environment""" @@ -111,7 +88,7 @@ def test_remove_certificate_screenshot__with_preview_url_as_none(self): }, ]) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, [ + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, [ call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) self.assertEqual(File.delete.call_args_list, []) @@ -120,20 +97,6 @@ def test_remove_certificate_screenshot__with_preview_url_as_none(self): 🔽🔽🔽 With a properly preview_url """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch.multiple('breathecode.services.google_cloud.Storage', - __init__=MagicMock(return_value=None), - client=PropertyMock(), - create=True) - @patch.multiple('breathecode.services.google_cloud.File', - __init__=MagicMock(return_value=None), - bucket=PropertyMock(), - file_name=PropertyMock(), - blob=PropertyMock(return_value=1), - upload=MagicMock(), - delete=MagicMock(), - url=MagicMock(return_value='https://xyz/hardcoded_url'), - create=True) def test_remove_certificate_screenshot__with_a_properly_preview_url(self): """remove_certificate_screenshot don't call open in development environment""" @@ -151,7 +114,7 @@ def test_remove_certificate_screenshot__with_a_properly_preview_url(self): ]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), diff --git a/breathecode/certificate/tests/signals/tests_user_specialty_saved.py b/breathecode/certificate/tests/signals/tests_user_specialty_saved.py index 41be13703..c61fe2772 100644 --- a/breathecode/certificate/tests/signals/tests_user_specialty_saved.py +++ b/breathecode/certificate/tests/signals/tests_user_specialty_saved.py @@ -1,10 +1,11 @@ import hashlib from unittest.mock import MagicMock, call, patch -from breathecode.tests.mixins.legacy import LegacyAPITestCase -import breathecode.certificate.tasks as tasks from django.utils import timezone +import breathecode.certificate.tasks as tasks +from breathecode.tests.mixins.legacy import LegacyAPITestCase + def remove_is_clean_for_one_item(item): if 'is_cleaned' in item: @@ -38,18 +39,21 @@ class TestAcademyEvent(LegacyAPITestCase): @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_error(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'ERROR'} + user_specialty = {'status': 'ERROR', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), [user_specialty_db]) + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [user_specialty_db] """ 🔽🔽🔽 Status PENDING @@ -58,18 +62,21 @@ def test_user_specialty_saved__status_error(self, enable_signals): @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_pending(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PENDING'} + user_specialty = {'status': 'PENDING', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), [user_specialty_db]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [user_specialty_db] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty @@ -78,18 +85,21 @@ def test_user_specialty_saved__status_pending(self, enable_signals): @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1)] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), [user_specialty_db]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [user_specialty_db] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty, changing signed_by @@ -98,24 +108,28 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty(self, enab @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_signed_by(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.signed_by = 'GOD 🤷‍♂️' model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1), call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'signed_by': 'GOD 🤷‍♂️', - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1), call(1)] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'signed_by': + 'GOD 🤷‍♂️', + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty, changing signed_by_role @@ -125,24 +139,28 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_signed_by_role( self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.signed_by_role = 'GOD 🤷‍♂️' model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1), call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1), call(1)] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'signed_by_role': 'GOD 🤷‍♂️', - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'signed_by_role': + 'GOD 🤷‍♂️', + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty, changing layout @@ -151,9 +169,9 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_layout(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model1 = self.bc.database.create(user_specialty=user_specialty) model2 = self.bc.database.create(layout_design=1) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model1.user_specialty)) @@ -161,15 +179,19 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ model1.user_specialty.layout = model2.layout_design model1.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1), call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'layout_id': 1, - 'update_hash': generate_update_hash(model1.user_specialty), - }]) + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1), call(1)] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'layout_id': + 1, + 'update_hash': + generate_update_hash(model1.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty, changing expires_at @@ -178,9 +200,9 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_expires_at(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) @@ -188,15 +210,19 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ model.user_specialty.expires_at = utc_now model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1), call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1), call(1)] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'expires_at': utc_now, - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'expires_at': + utc_now, + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url is empty, changing issued_at @@ -205,9 +231,9 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_issued_at(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': ''} + user_specialty = {'status': 'PERSISTED', 'preview_url': '', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) @@ -215,15 +241,19 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ model.user_specialty.issued_at = utc_now model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, []) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, [call(1), call(1)]) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [] + assert tasks.take_screenshot.delay.call_args_list == [call(1), call(1)] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'issued_at': utc_now, - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'issued_at': + utc_now, + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url set @@ -232,18 +262,21 @@ def test_user_specialty_saved__status_persisted__preview_url_is_empty__changing_ @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), [user_specialty_db]) + assert tasks.reset_screenshot.delay.call_args_list == [call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [user_specialty_db] """ 🔽🔽🔽 Status PERSISTED and preview_url set, changing signed_by @@ -252,24 +285,28 @@ def test_user_specialty_saved__status_persisted__preview_url_set(self, enable_si @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set__changing_signed_by(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.signed_by = 'GOD 🤷‍♂️' model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1), call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [call(1), call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'signed_by': 'GOD 🤷‍♂️', - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'signed_by': + 'GOD 🤷‍♂️', + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url set, changing signed_by_role @@ -278,24 +315,28 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_signe @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set__changing_signed_by_role(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) model.user_specialty.signed_by_role = 'GOD 🤷‍♂️' model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1), call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'signed_by_role': 'GOD 🤷‍♂️', - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert tasks.reset_screenshot.delay.call_args_list == [call(1), call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'signed_by_role': + 'GOD 🤷‍♂️', + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url set, changing layout @@ -304,9 +345,9 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_signe @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set__changing_layout(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model1 = self.bc.database.create(user_specialty=user_specialty) model2 = self.bc.database.create(layout_design=1) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model1.user_specialty)) @@ -314,15 +355,19 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_layou model1.user_specialty.layout = model2.layout_design model1.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1), call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [call(1), call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'layout_id': 1, - 'update_hash': generate_update_hash(model1.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'layout_id': + 1, + 'update_hash': + generate_update_hash(model1.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url set, changing expires_at @@ -331,9 +376,9 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_layou @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set__changing_expires_at(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) @@ -341,15 +386,19 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_expir model.user_specialty.expires_at = utc_now model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1), call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'expires_at': utc_now, - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert tasks.reset_screenshot.delay.call_args_list == [call(1), call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] + + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'expires_at': + utc_now, + 'update_hash': + generate_update_hash(model.user_specialty), + }] """ 🔽🔽🔽 Status PERSISTED and preview_url set, changing issued_at @@ -358,9 +407,9 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_expir @patch('breathecode.certificate.tasks.reset_screenshot.delay', MagicMock()) @patch('breathecode.certificate.tasks.take_screenshot.delay', MagicMock()) def test_user_specialty_saved__status_persisted__preview_url_set__changing_issued_at(self, enable_signals): - enable_signals() + enable_signals('breathecode.certificate.signals.user_specialty_saved') - user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️'} + user_specialty = {'status': 'PERSISTED', 'preview_url': 'GOD 🤷‍♂️', 'update_hash': '⬛🌷'} model = self.bc.database.create(user_specialty=user_specialty) user_specialty_db = remove_is_clean_for_one_item(self.bc.format.to_dict(model.user_specialty)) @@ -368,12 +417,16 @@ def test_user_specialty_saved__status_persisted__preview_url_set__changing_issue model.user_specialty.issued_at = utc_now model.user_specialty.save() - self.assertEqual(tasks.reset_screenshot.delay.call_args_list, [call(1), call(1)]) - self.assertEqual(tasks.take_screenshot.delay.call_args_list, []) + print('tasks.reset_screenshot', tasks.reset_screenshot.delay.call_args_list) + print('tasks.take_screenshot', tasks.take_screenshot.delay.call_args_list) + + assert tasks.reset_screenshot.delay.call_args_list == [call(1), call(1)] + assert tasks.take_screenshot.delay.call_args_list == [] - self.assertEqual(self.bc.database.list_of('certificate.UserSpecialty'), - [{ - **user_specialty_db, - 'issued_at': utc_now, - 'update_hash': generate_update_hash(model.user_specialty), - }]) + assert self.bc.database.list_of('certificate.UserSpecialty') == [{ + **user_specialty_db, + 'issued_at': + utc_now, + 'update_hash': + generate_update_hash(model.user_specialty), + }] diff --git a/breathecode/certificate/tests/tasks/tests_async_generate_certificate.py b/breathecode/certificate/tests/tasks/tests_async_generate_certificate.py index 156f61d70..ba68e276e 100644 --- a/breathecode/certificate/tests/tasks/tests_async_generate_certificate.py +++ b/breathecode/certificate/tests/tasks/tests_async_generate_certificate.py @@ -19,8 +19,8 @@ class ActionCertificateGenerateOneCertificateTestCase(CertificateTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('breathecode.certificate.actions.generate_certificate', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_async_generate_certificate__cohort_user_not_found(self): layout = 'vanilla' async_generate_certificate(1, 1, layout) @@ -37,8 +37,8 @@ def test_async_generate_certificate__cohort_user_not_found(self): @patch('logging.Logger.error', MagicMock()) @patch('breathecode.certificate.actions.generate_certificate', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_async_generate_certificate_with_user_role_student(self): cohort_user = {'role': 'STUDENT'} with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): @@ -66,8 +66,8 @@ def test_async_generate_certificate_with_user_role_student(self): @patch('logging.Logger.error', MagicMock()) @patch('breathecode.certificate.actions.generate_certificate', MagicMock(side_effect=Exception())) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_async_generate_certificate_with_user_role_teacher(self): cohort_user = {'role': 'STUDENT'} with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): diff --git a/breathecode/certificate/tests/urls/tests_cohort_id.py b/breathecode/certificate/tests/urls/tests_cohort_id.py index d14f53565..278ad08fe 100644 --- a/breathecode/certificate/tests/urls/tests_cohort_id.py +++ b/breathecode/certificate/tests/urls/tests_cohort_id.py @@ -2,17 +2,20 @@ Test /certificate """ from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy from django.utils import timezone from rest_framework import status + +import breathecode.certificate.signals as signals from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import CertificateTestCase -import breathecode.certificate.signals as signals class CertificateTestSuite(CertificateTestCase): @@ -24,9 +27,9 @@ class CertificateTestSuite(CertificateTestCase): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_cohort_user__without_auth(self): self.headers(academy=1) url = reverse_lazy('certificate:cohort_id', kwargs={'cohort_id': 1}) @@ -39,14 +42,14 @@ def test_certificate_cohort_user__without_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_cohort_user__with_auth_without_permissions(self): self.headers(academy=1) self.generate_models(authenticate=True) @@ -62,7 +65,7 @@ def test_certificate_cohort_user__with_auth_without_permissions(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 403) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Post method @@ -71,9 +74,9 @@ def test_certificate_cohort_user__with_auth_without_permissions(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_with_role_student_without_syllabus_version(self): """ No main teacher in cohort """ self.headers(academy=1) @@ -100,14 +103,14 @@ def test_generate_certificate_with_role_student_without_syllabus_version(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_with_role_student_without_main_teacher(self): """ No main teacher in cohort """ self.headers(academy=1) @@ -135,14 +138,14 @@ def test_generate_certificate_with_role_student_without_main_teacher(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_without_cohort_user(self): """ No cohort user""" self.headers(academy=1) @@ -163,14 +166,14 @@ def test_generate_certificate_without_cohort_user(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_with_everything_but_schedule(self): """ Should be ok because cohorts dont need specialy mode to generate certificates """ self.headers(academy=1) @@ -204,7 +207,7 @@ def test_generate_certificate_with_everything_but_schedule(self): user_specialty = self.bc.database.get('certificate.UserSpecialty', 1, dict=False) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Action call(instance=user_specialty, sender=user_specialty.__class__), @@ -213,9 +216,9 @@ def test_generate_certificate_with_everything_but_schedule(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_with_role_student_with_syllabus_without_specialty(self): """ No specialty """ self.headers(academy=1) @@ -240,14 +243,14 @@ def test_generate_certificate_with_role_student_with_syllabus_without_specialty( self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_test_without_layout(self): """ No specialty """ self.headers(academy=1) @@ -274,14 +277,14 @@ def test_generate_certificate_test_without_layout(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_test_with_cohort_stage_no_ended(self): """ No specialty """ self.headers(academy=1) @@ -305,14 +308,14 @@ def test_generate_certificate_test_with_cohort_stage_no_ended(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_test_without_cohort_user_finantial_status(self): self.headers(academy=1) cohort_kwargs = {'stage': 'ENDED'} @@ -446,7 +449,7 @@ def test_generate_certificate_test_without_cohort_user_finantial_status(self): }]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -457,9 +460,9 @@ def test_generate_certificate_test_without_cohort_user_finantial_status(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_test_without_cohort_user_educational_status(self): self.headers(academy=1) cohort_kwargs = {'stage': 'ENDED'} @@ -593,13 +596,13 @@ def test_generate_certificate_test_without_cohort_user_educational_status(self): 'update_hash': user_specialty.update_hash, }]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_test_with_final_cohort(self): self.headers(academy=1) cohort_kwargs = {'stage': 'ENDED'} @@ -734,7 +737,7 @@ def test_generate_certificate_test_with_final_cohort(self): }]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -742,13 +745,13 @@ def test_generate_certificate_test_with_final_cohort(self): call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_good_request(self): """Test /certificate/cohort/id status: 201""" @@ -895,7 +898,7 @@ def test_generate_certificate_good_request(self): }]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), diff --git a/breathecode/certificate/tests/urls/tests_cohort_id_student_id.py b/breathecode/certificate/tests/urls/tests_cohort_id_student_id.py index 62b5d19a9..097de1b7a 100644 --- a/breathecode/certificate/tests/urls/tests_cohort_id_student_id.py +++ b/breathecode/certificate/tests/urls/tests_cohort_id_student_id.py @@ -2,17 +2,20 @@ Test /certificate """ from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy from django.utils import timezone from rest_framework import status + +import breathecode.certificate.signals as signals from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import CertificateTestCase -import breathecode.certificate.signals as signals class CertificateTestSuite(CertificateTestCase): @@ -24,9 +27,9 @@ class CertificateTestSuite(CertificateTestCase): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_no_default_layout(self): """ No main teacher in cohort """ self.headers(academy=1) @@ -61,14 +64,14 @@ def test_generate_certificate_no_default_layout(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate_no_cohort_user(self): """ No main teacher in cohort """ self.headers(academy=1) @@ -98,15 +101,15 @@ def test_generate_certificate_no_cohort_user(self): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_generate_certificate(self): """ No main teacher in cohort """ self.headers(academy=1) @@ -252,7 +255,7 @@ def test_generate_certificate(self): }]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), diff --git a/breathecode/certificate/tests/urls/tests_me.py b/breathecode/certificate/tests/urls/tests_me.py index 8ee3c2e26..3a4e9a53b 100644 --- a/breathecode/certificate/tests/urls/tests_me.py +++ b/breathecode/certificate/tests/urls/tests_me.py @@ -57,7 +57,7 @@ class CertificateTestSuite(CertificateTestCase): 🔽🔽🔽 Auth """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test_without_auth(self): url = reverse_lazy('certificate:me') response = self.client.get(url) @@ -75,7 +75,7 @@ def test_without_auth(self): 🔽🔽🔽 GET without permission """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__without_permission(self): model = self.bc.database.create(user=1) @@ -93,7 +93,7 @@ def test__get__without_permission(self): 🔽🔽🔽 GET with zero UserSpecialty """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__with_zero_user_specialties(self): permission = {'codename': 'get_my_certificate'} model = self.bc.database.create(user=1, permission=permission) @@ -112,7 +112,7 @@ def test__get__with_zero_user_specialties(self): 🔽🔽🔽 GET with one UserSpecialty and status 'PENDING' """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__with_one_user_specialty_status_pending(self): permission = {'codename': 'get_my_certificate'} model = self.bc.database.create(user=1, permission=permission, user_specialty=1) @@ -132,7 +132,7 @@ def test__get__with_one_user_specialty_status_pending(self): 🔽🔽🔽 GET with one UserSpecialty and status 'PERSISTED' """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__with_one_user_specialty_status_persisted(self): permission = {'codename': 'get_my_certificate'} model = self.bc.database.create(user=1, @@ -157,7 +157,7 @@ def test__get__with_one_user_specialty_status_persisted(self): 🔽🔽🔽 GET with two UserSpecialty """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__with_two_user_specialty(self): permission = {'codename': 'get_my_certificate'} user_specialties = [{'token': 'xyz1', 'status': 'PERSISTED'}, {'token': 'xyz2'}] @@ -181,7 +181,7 @@ def test__get__with_two_user_specialty(self): 🔽🔽🔽 GET with two UserSpecialty from another user """ - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__with_two_user_specialty__from_another_user(self): permission = {'codename': 'get_my_certificate'} user_specialties = [{'token': 'xyz1', 'user_id': 2}, {'token': 'xyz2', 'user_id': 2}] @@ -203,7 +203,7 @@ def test__get__with_two_user_specialty__from_another_user(self): @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) def test__get__spy_the_extensions(self): permission = {'codename': 'get_my_certificate'} model = self.bc.database.create(user=1, permission=permission, user_specialty=1) diff --git a/breathecode/certificate/tests/urls/tests_root.py b/breathecode/certificate/tests/urls/tests_root.py index 845c07f44..fde9d35e9 100644 --- a/breathecode/certificate/tests/urls/tests_root.py +++ b/breathecode/certificate/tests/urls/tests_root.py @@ -2,16 +2,19 @@ Test /certificate """ from unittest.mock import MagicMock, call, patch + from django.urls.base import reverse_lazy from rest_framework import status + +import breathecode.certificate.signals as signals from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import CertificateTestCase -import breathecode.certificate.signals as signals class CertificateTestSuite(CertificateTestCase): @@ -23,9 +26,9 @@ class CertificateTestSuite(CertificateTestCase): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_cohort_user__without_auth(self): """Test /root without auth""" self.headers(academy=1) @@ -39,7 +42,7 @@ def test_certificate_cohort_user__without_auth(self): }) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) """ 🔽🔽🔽 Post method @@ -48,9 +51,9 @@ def test_certificate_cohort_user__without_auth(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_re_attempts_without_capability(self): """Test /root with auth""" """ No capability for the request""" @@ -72,14 +75,14 @@ def test_certificate_re_attempts_without_capability(self): self.assertEqual(response.status_code, 403) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_re_attempts_without_cohort_user(self): """Test /root with auth""" """ No cohort_user for the request""" @@ -103,14 +106,14 @@ def test_certificate_re_attempts_without_cohort_user(self): self.assertEqual(response.status_code, 404) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_re_attempts_without_user_specialty(self): """Test /root with auth""" """ No user_specialty for the request""" @@ -135,15 +138,15 @@ def test_certificate_re_attempts_without_user_specialty(self): self.assertEqual(response.status_code, 404) self.assertEqual(self.all_user_specialty_dict(), []) - self.assertEqual(signals.user_specialty_saved.send.call_args_list, []) + self.assertEqual(signals.user_specialty_saved.send_robust.call_args_list, []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_re_attempts(self): """Test /root with auth""" """ Good Request """ @@ -295,7 +298,7 @@ def test_certificate_re_attempts(self): }]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=model.user_specialty, sender=model.user_specialty.__class__), @@ -305,13 +308,13 @@ def test_certificate_re_attempts(self): call(instance=model.user_specialty, sender=model.user_specialty.__class__), ]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('breathecode.certificate.signals.user_specialty_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.certificate.signals.user_specialty_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate_re_attempts_two_certificates(self): """Test /root with auth""" """ Good Request """ @@ -553,7 +556,7 @@ def test_certificate_re_attempts_two_certificates(self): ]) self.assertEqual( - signals.user_specialty_saved.send.call_args_list, + signals.user_specialty_saved.send_robust.call_args_list, [ # Mixer call(instance=models[0].user_specialty, sender=models[0].user_specialty.__class__), @@ -571,8 +574,8 @@ def test_certificate_re_attempts_two_certificates(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate__with_full_name_in_querystring(self): """Test /root """ self.headers(academy=1) @@ -687,8 +690,8 @@ def test_certificate__with_full_name_in_querystring(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate__with_first_name_in_querystring(self): """Test /root """ self.headers(academy=1) @@ -798,8 +801,8 @@ def test_certificate__with_first_name_in_querystring(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate__with_last_name_in_querystring(self): """Test /root """ self.headers(academy=1) @@ -909,8 +912,8 @@ def test_certificate__with_last_name_in_querystring(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_certificate__with_email_in_querystring(self): """Test /root """ self.headers(academy=1) @@ -1026,8 +1029,8 @@ def test_certificate__with_email_in_querystring(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_certificate_in_bulk_with_two_ids(self): """Test / with two certificates""" self.headers(academy=1) @@ -1064,8 +1067,8 @@ def test_delete_certificate_in_bulk_with_two_ids(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_certificate_in_bulk_not_found(self): """Test / with two certificates""" self.headers(academy=1) @@ -1101,8 +1104,8 @@ def test_delete_certificate_in_bulk_not_found(self): @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_delete_certificate_in_bulk_without_passing_ids(self): """Test / with two certificates""" self.headers(academy=1) diff --git a/breathecode/commons/receivers.py b/breathecode/commons/receivers.py index c2684d29a..042b8d7c8 100644 --- a/breathecode/commons/receivers.py +++ b/breathecode/commons/receivers.py @@ -24,13 +24,13 @@ def is_cache_enabled(): @receiver(post_save) def on_save(*args: Any, **kwargs: Any): del kwargs['signal'] - update_cache.send(*args, **kwargs) + update_cache.send_robust(*args, **kwargs) @receiver(post_delete) def on_delete(*args: Any, **kwargs: Any): del kwargs['signal'] - update_cache.send(*args, **kwargs) + update_cache.send_robust(*args, **kwargs) @receiver(update_cache) diff --git a/breathecode/events/models.py b/breathecode/events/models.py index cfededbb7..a90c12901 100644 --- a/breathecode/events/models.py +++ b/breathecode/events/models.py @@ -1,12 +1,15 @@ import binascii import os -from django.db import models +import uuid as uuid_lib + from django.contrib.auth.models import User -from .signals import event_status_updated, new_event_order, new_event_attendee +from django.db import models +from slugify import slugify + from breathecode.admissions.models import Academy, Cohort, CohortTimeSlot, Syllabus from breathecode.utils.validators.language import validate_language_code -from slugify import slugify -import uuid as uuid_lib + +from .signals import event_status_updated, new_event_attendee, new_event_order PENDING = 'PENDING' PERSISTED = 'PERSISTED' @@ -279,9 +282,9 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) - event_saved.send(instance=self, sender=self.__class__, created=created) + event_saved.send_robust(instance=self, sender=self.__class__, created=created) - if status_updated: event_status_updated.send(instance=self, sender=Event) + if status_updated: event_status_updated.send_robust(instance=self, sender=Event) PENDING = 'PENDING' @@ -328,9 +331,9 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) - if creating: new_event_order.send(instance=self, sender=EventCheckin) + if creating: new_event_order.send_robust(instance=self, sender=EventCheckin) elif status_updated and self.status == 'DONE': - new_event_attendee.send(instance=self, sender=EventCheckin) + new_event_attendee.send_robust(instance=self, sender=EventCheckin) # PENDING = 'PENDING' diff --git a/breathecode/events/tests/actions/tests_export_event_to_eventbrite.py b/breathecode/events/tests/actions/tests_export_event_to_eventbrite.py index 7ecf490dd..95e3b46c8 100644 --- a/breathecode/events/tests/actions/tests_export_event_to_eventbrite.py +++ b/breathecode/events/tests/actions/tests_export_event_to_eventbrite.py @@ -1,9 +1,10 @@ import logging -import breathecode.events.actions as actions from unittest.mock import MagicMock, call, patch -from breathecode.events.utils import Eventbrite +import breathecode.events.actions as actions +from breathecode.events.utils import Eventbrite from breathecode.tests.mocks.requests import REQUESTS_PATH, apply_requests_request_mock + from ..mixins import EventTestCase export_event_to_eventbrite = actions.export_event_to_eventbrite @@ -76,7 +77,7 @@ def test_export_event_to_eventbrite__without_academy(self): @patch.object(logging.Logger, 'error', log_mock()) @patch.object(actions, 'get_current_iso_string', get_current_iso_string_mock()) @patch.object(actions, 'export_event_description_to_eventbrite', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch( REQUESTS_PATH['request'], apply_requests_request_mock([ @@ -117,7 +118,7 @@ def test_export_event_to_eventbrite__with_event(self): @patch.object(actions, 'get_current_iso_string', get_current_iso_string_mock()) @patch.object(actions, 'export_event_description_to_eventbrite', MagicMock()) @patch.object(Eventbrite, 'request', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch( REQUESTS_PATH['request'], apply_requests_request_mock([ @@ -126,6 +127,7 @@ def test_export_event_to_eventbrite__with_event(self): ])) def test_export_event_to_eventbrite__check_the_payload__without_eventbrite_id(self): import logging + from breathecode.events.utils import Eventbrite organization_kwargs = {'eventbrite_id': '1'} @@ -178,7 +180,7 @@ def test_export_event_to_eventbrite__check_the_payload__without_eventbrite_id(se @patch.object(actions, 'get_current_iso_string', get_current_iso_string_mock()) @patch.object(actions, 'export_event_description_to_eventbrite', MagicMock()) @patch.object(Eventbrite, 'request', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch( REQUESTS_PATH['request'], apply_requests_request_mock([ @@ -187,6 +189,7 @@ def test_export_event_to_eventbrite__check_the_payload__without_eventbrite_id(se ])) def test_export_event_to_eventbrite__check_the_payload__with_eventbrite_id(self): import logging + from breathecode.events.utils import Eventbrite organization_kwargs = {'eventbrite_id': '1'} @@ -239,7 +242,7 @@ def test_export_event_to_eventbrite__check_the_payload__with_eventbrite_id(self) @patch.object(actions, 'get_current_iso_string', get_current_iso_string_mock()) @patch.object(actions, 'export_event_description_to_eventbrite', MagicMock()) @patch.object(Eventbrite, 'request', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch( REQUESTS_PATH['request'], apply_requests_request_mock([ @@ -248,6 +251,7 @@ def test_export_event_to_eventbrite__check_the_payload__with_eventbrite_id(self) ])) def test_export_event_to_eventbrite__check_the_payload__with_organizer_id(self): import logging + from breathecode.events.utils import Eventbrite organization_kwargs = {'eventbrite_id': '1'} diff --git a/breathecode/events/tests/actions/tests_publish_event_from_eventbrite.py b/breathecode/events/tests/actions/tests_publish_event_from_eventbrite.py index c86ec1096..b3e0e52bf 100644 --- a/breathecode/events/tests/actions/tests_publish_event_from_eventbrite.py +++ b/breathecode/events/tests/actions/tests_publish_event_from_eventbrite.py @@ -1,6 +1,9 @@ -from breathecode.events.actions import publish_event_from_eventbrite from unittest.mock import MagicMock, call, patch + from django.utils import timezone + +from breathecode.events.actions import publish_event_from_eventbrite + from ..mixins import EventTestCase now = timezone.now() @@ -14,7 +17,7 @@ class SyncOrgVenuesTestSuite(EventTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=now)) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_publish_event_from_eventbrite__empty_data(self): """ @@ -46,7 +49,7 @@ def test_publish_event_from_eventbrite__empty_data(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=now)) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_publish_event_from_eventbrite__bad_data(self): """ @@ -80,7 +83,7 @@ def test_publish_event_from_eventbrite__bad_data(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=now)) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_publish_event_from_eventbrite__event_not_found(self): """ @@ -109,7 +112,7 @@ def test_publish_event_from_eventbrite__event_not_found(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=now)) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_publish_event_from_eventbrite__event_not_found__with_one_event(self): """ @@ -147,7 +150,7 @@ def test_publish_event_from_eventbrite__event_not_found__with_one_event(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=now)) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_publish_event_from_eventbrite__event_not_found__with_one_event(self): """ diff --git a/breathecode/events/tests/actions/tests_update_or_create_event.py b/breathecode/events/tests/actions/tests_update_or_create_event.py index 547397f6e..a8e7b5eb6 100644 --- a/breathecode/events/tests/actions/tests_update_or_create_event.py +++ b/breathecode/events/tests/actions/tests_update_or_create_event.py @@ -1,11 +1,14 @@ import logging import os import random +from unittest.mock import MagicMock, PropertyMock, call, patch from uuid import UUID + +from django.utils import timezone + import breathecode.events.actions as actions -from unittest.mock import MagicMock, PropertyMock, call, patch from breathecode.tests.mocks.eventbrite.constants.events import EVENTBRITE_EVENTS -from django.utils import timezone + from ..mixins import EventTestCase update_or_create_event = actions.update_or_create_event @@ -67,6 +70,7 @@ class SyncOrgVenuesTestSuite(EventTestCase): @patch.object(actions, 'update_event_description_from_eventbrite', MagicMock()) def test_update_or_create_event__data_is_none(self): import logging + import breathecode.events.actions as actions organization_kwargs = {'eventbrite_id': '1'} @@ -95,6 +99,7 @@ def test_update_or_create_event__data_is_none(self): @patch.object(actions, 'update_event_description_from_eventbrite', MagicMock()) def test_update_or_create_event__without_academy(self): import logging + import breathecode.events.actions as actions organization_kwargs = {'eventbrite_id': '1'} @@ -123,11 +128,12 @@ def test_update_or_create_event__without_academy(self): @patch.object(actions, 'create_or_update_venue', create_or_update_venue_mock()) @patch.object(actions, 'create_or_update_organizer', create_or_update_organizer_mock()) @patch.object(actions, 'update_event_description_from_eventbrite', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) @patch('os.urandom', MagicMock(return_value=seed)) def test_update_or_create_event__with_academy(self): import logging + import breathecode.events.actions as actions organization_kwargs = {'eventbrite_id': '1'} @@ -206,6 +212,7 @@ def test_update_or_create_event__with_academy(self): @patch('os.urandom', MagicMock(return_value=seed)) def test_update_or_create_event__with_event(self): import logging + import breathecode.events.actions as actions organization_kwargs = {'eventbrite_id': '1'} diff --git a/breathecode/events/tests/management/commands/tests_fix_live_class_dates.py b/breathecode/events/tests/management/commands/tests_fix_live_class_dates.py index abd853a95..41deff65b 100644 --- a/breathecode/events/tests/management/commands/tests_fix_live_class_dates.py +++ b/breathecode/events/tests/management/commands/tests_fix_live_class_dates.py @@ -1,13 +1,14 @@ -from datetime import timedelta import random import sys +from datetime import timedelta from unittest.mock import MagicMock, call, patch -from breathecode.tests.mixins.legacy import LegacyAPITestCase -import breathecode.events.tasks as tasks -from breathecode.events.management.commands.fix_live_class_dates import Command from django.utils import timezone + +import breathecode.events.tasks as tasks from breathecode.events import tasks +from breathecode.events.management.commands.fix_live_class_dates import Command +from breathecode.tests.mixins.legacy import LegacyAPITestCase UTC_NOW = timezone.now() DELTA = timedelta(seconds=60 * random.randint(0, 61), minutes=random.randint(31, 61)) @@ -18,7 +19,7 @@ class TestSyncOrgVenues(LegacyAPITestCase): # Then: nothing should happen @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.tasks.fix_live_class_dates.delay', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) @patch.object(sys.stdout, 'write', MagicMock()) @patch.object(sys.stderr, 'write', MagicMock()) def test_0_live_classes(self): @@ -38,7 +39,7 @@ def test_0_live_classes(self): # Then: nothing should happen @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.tasks.fix_live_class_dates.delay', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) @patch.object(sys.stdout, 'write', MagicMock()) @patch.object(sys.stderr, 'write', MagicMock()) def test_2_cohorts__in_the_past(self): @@ -64,7 +65,7 @@ def test_2_cohorts__in_the_past(self): # Then: found 2 cohorts without timeslots @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.tasks.fix_live_class_dates.delay', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) @patch.object(sys.stdout, 'write', MagicMock()) @patch.object(sys.stderr, 'write', MagicMock()) def test_2_cohorts__in_the_future(self): @@ -90,7 +91,7 @@ def test_2_cohorts__in_the_future(self): # Then: nothing should happen @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.tasks.fix_live_class_dates.delay', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) @patch.object(sys.stdout, 'write', MagicMock()) @patch.object(sys.stderr, 'write', MagicMock()) def test_2_live_classes(self): diff --git a/breathecode/events/tests/tasks/tests_fix_live_class_dates.py b/breathecode/events/tests/tasks/tests_fix_live_class_dates.py index 2ededae3c..42e0254b3 100644 --- a/breathecode/events/tests/tasks/tests_fix_live_class_dates.py +++ b/breathecode/events/tests/tasks/tests_fix_live_class_dates.py @@ -1,16 +1,18 @@ import binascii -from datetime import timedelta, datetime import logging -import random import os -import pytz +import random +from datetime import datetime, timedelta from unittest.mock import MagicMock, call, patch +import pytz +from django.utils import timezone + +import breathecode.events.actions as actions from breathecode.events.tasks import fix_live_class_dates -from ..mixins.new_events_tests_case import EventTestCase + from ...signals import event_saved -import breathecode.events.actions as actions -from django.utils import timezone +from ..mixins.new_events_tests_case import EventTestCase UTC_NOW = datetime(year=2022, month=12, day=30, hour=9, minute=24, second=0, microsecond=0, tzinfo=pytz.UTC) URANDOM = os.urandom(20) @@ -37,7 +39,7 @@ class AcademyEventTestSuite(EventTestCase): @patch.object(actions, 'export_event_to_eventbrite', MagicMock()) @patch.object(logging.Logger, 'error', MagicMock()) @patch.object(logging.Logger, 'debug', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) def test_0_items(self): fix_live_class_dates.delay(1) @@ -50,7 +52,7 @@ def test_0_items(self): @patch.object(logging.Logger, 'error', MagicMock()) @patch.object(logging.Logger, 'debug', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) def test_cohort_in_the_past(self): cohort = { 'never_ends': False, @@ -95,7 +97,7 @@ def test_cohort_in_the_past(self): @patch.object(logging.Logger, 'error', MagicMock()) @patch.object(logging.Logger, 'debug', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) def test_upcoming_cohort(self): cohort = { 'never_ends': False, diff --git a/breathecode/events/tests/urls/tests_academy_event.py b/breathecode/events/tests/urls/tests_academy_event.py index f6be2793c..8da3e4f8c 100644 --- a/breathecode/events/tests/urls/tests_academy_event.py +++ b/breathecode/events/tests/urls/tests_academy_event.py @@ -627,7 +627,7 @@ def test_all_academy_events__post__bad_tags__one_of_two_tags_not_exists(self): 🔽🔽🔽 Post bad slug """ - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) @patch('os.urandom', MagicMock(return_value=seed)) def test_all_academy_events__post__bad_slug(self): @@ -743,7 +743,7 @@ def test_all_academy_events__post__tags_is_blank(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), []) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) # @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) # @patch('os.urandom', MagicMock(return_value=seed)) def test_all_academy_events__post__event_exist_with_the_same_eventbrite_id_as_null(self): @@ -1129,7 +1129,7 @@ def test_all_academy_events__post__with_duplicate_tags(self): 🔽🔽🔽 Post bad slug """ - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) @patch('os.urandom', MagicMock(return_value=seed)) def test_all_academy_events__post__bad_slug____(self): diff --git a/breathecode/events/tests/urls/tests_academy_event_id.py b/breathecode/events/tests/urls/tests_academy_event_id.py index 265970ba2..ca6144f12 100644 --- a/breathecode/events/tests/urls/tests_academy_event_id.py +++ b/breathecode/events/tests/urls/tests_academy_event_id.py @@ -84,7 +84,7 @@ def get_serializer(event, academy, asset=None, data={}): class AcademyEventIdTestSuite(EventTestCase): cache = EventCache() - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_event_id_no_auth(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id', kwargs={'event_id': 1}) @@ -96,7 +96,7 @@ def test_academy_event_id_no_auth(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 401) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_all_academy_events_without_capability(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id', kwargs={'event_id': 1}) @@ -109,7 +109,7 @@ def test_all_academy_events_without_capability(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 403) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_event_id_invalid_id(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id', kwargs={'event_id': 1}) @@ -126,7 +126,7 @@ def test_academy_event_id_invalid_id(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 404) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_event_id_valid_id(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id', kwargs={'event_id': 1}) @@ -154,7 +154,7 @@ def test_academy_event_id_valid_id(self): 🔽🔽🔽 Put - bad tags """ - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__two_commas(self): """Test /cohort without auth""" self.headers(academy=1) @@ -187,7 +187,7 @@ def test_academy_cohort_id__put__two_commas(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__with_spaces(self): """Test /cohort without auth""" self.headers(academy=1) @@ -220,7 +220,7 @@ def test_academy_cohort_id__put__with_spaces(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__starts_with_comma(self): """Test /cohort without auth""" self.headers(academy=1) @@ -253,7 +253,7 @@ def test_academy_cohort_id__put__starts_with_comma(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__ends_with_comma(self): """Test /cohort without auth""" self.headers(academy=1) @@ -286,7 +286,7 @@ def test_academy_cohort_id__put__ends_with_comma(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__one_tag_not_exists(self): """Test /cohort without auth""" self.headers(academy=1) @@ -319,7 +319,7 @@ def test_academy_cohort_id__put__one_tag_not_exists(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__two_tags_not_exists(self): """Test /cohort without auth""" self.headers(academy=1) @@ -352,7 +352,7 @@ def test_academy_cohort_id__put__two_tags_not_exists(self): self.assertEqual(response.status_code, 400) self.assertEqual(self.bc.database.list_of('events.Event'), [self.model_to_dict(model, 'event')]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__one_of_two_tags_not_exists(self): """Test /cohort without auth""" self.headers(academy=1) @@ -484,7 +484,7 @@ def test_academy_cohort_id__put(self): 🔽🔽🔽 Put, tags empty """ - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__tags_is_blank(self): """Test /cohort without auth""" self.headers(academy=1) @@ -524,7 +524,7 @@ def test_academy_cohort_id__put__tags_is_blank(self): 🔽🔽🔽 Try to update the slug """ - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__tags_is_blank__try_to_update_the_slug(self): """Test /cohort without auth""" self.headers(academy=1) @@ -564,7 +564,7 @@ def test_academy_cohort_id__put__tags_is_blank__try_to_update_the_slug(self): **self.model_to_dict(model, 'event'), }]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) def test_academy_cohort_id__put__with_tags__without_acp(self): """Test /cohort without auth""" self.headers(academy=1) @@ -603,7 +603,7 @@ def test_academy_cohort_id__put__with_tags__without_acp(self): **self.model_to_dict(model, 'event'), }]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) @patch('os.urandom', MagicMock(return_value=seed)) def test_academy_cohort_id__put__with_tags(self): @@ -694,7 +694,7 @@ def test_academy_cohort_id__put__with_tags(self): 🔽🔽🔽 Put with duplicate tags """ - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('uuid.uuid4', PropertyMock(MagicMock=uuid)) @patch('os.urandom', MagicMock(return_value=seed)) def test_academy_cohort_id__put__with_duplicate_tags(self): @@ -790,7 +790,7 @@ def test_academy_cohort_id__put__with_duplicate_tags(self): 'free_for_bootcamps': True, }]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extensions', MagicMock()) def test_academy_event_id__spy_extensions(self): self.headers(academy=1) @@ -808,7 +808,7 @@ def test_academy_event_id__spy_extensions(self): call(['CacheExtension', 'LanguageExtension', 'LookupExtension', 'PaginationExtension', 'SortExtension']), ]) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch.object(APIViewExtensionHandlers, '_spy_extension_arguments', MagicMock()) def test_academy_event_id__spy_extension_arguments(self): self.headers(academy=1) diff --git a/breathecode/events/tests/urls/tests_academy_event_id_join.py b/breathecode/events/tests/urls/tests_academy_event_id_join.py index d55ae0523..518bf16a3 100644 --- a/breathecode/events/tests/urls/tests_academy_event_id_join.py +++ b/breathecode/events/tests/urls/tests_academy_event_id_join.py @@ -27,8 +27,8 @@ class AcademyVenueTestSuite(EventTestCase): # When: no auth # Then: return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id_join', kwargs={'event_id': 1}) @@ -43,8 +43,8 @@ def test_no_auth(self): # When: no capability # Then: return 403 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_no_capability(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id_join', kwargs={'event_id': 1}) @@ -65,8 +65,8 @@ def test_with_no_capability(self): # When: no Event # Then: return 404 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_live_classes(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_id_join', kwargs={'event_id': 1}) @@ -84,8 +84,8 @@ def test_no_live_classes(self): # When: have a Event with no url # Then: return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_url(self): self.headers(academy=1) model = self.bc.database.create(user=1, @@ -118,8 +118,8 @@ def test_no_url(self): # When: have a Event with url # Then: redirect to the liveclass - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_a_live_class(self): self.headers(academy=1) event = {'live_stream_url': self.bc.fake.url()} diff --git a/breathecode/events/tests/urls/tests_academy_event_liveclass.py b/breathecode/events/tests/urls/tests_academy_event_liveclass.py index 4e1f4eb42..61ed32420 100644 --- a/breathecode/events/tests/urls/tests_academy_event_liveclass.py +++ b/breathecode/events/tests/urls/tests_academy_event_liveclass.py @@ -41,9 +41,9 @@ class AcademyEventTestSuite(EventTestCase): # When: I call the API without authentication # Then: I should get a 401 error @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): url = reverse_lazy('events:academy_event_liveclass') @@ -58,9 +58,9 @@ def test_no_auth(self): # When: User is authenticated and has no LiveClass # Then: I should get a 200 status code with no data @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_live_classes(self): model = self.bc.database.create(user=1, profile_academy=1, role=1, capability='start_or_end_class') @@ -81,9 +81,9 @@ def test_zero_live_classes(self): # When: User is authenticated, has LiveClass and CohortUser belongs to this LiveClass # Then: I should get a 200 status code with the LiveClass data @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_live_class(self): model = self.bc.database.create(user=1, live_class=1, @@ -114,9 +114,9 @@ def test_one_live_class(self): @patch('breathecode.utils.api_view_extensions.extensions.lookup_extension.compile_lookup', MagicMock(wraps=lookup_extension.compile_lookup)) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.admissions.signals.timeslot_saved.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.timeslot_saved.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_lookup_extension(self): model = self.bc.database.create(user=1, diff --git a/breathecode/events/tests/urls/tests_academy_event_liveclass_join_hash.py b/breathecode/events/tests/urls/tests_academy_event_liveclass_join_hash.py index f7df5e326..15e11996d 100644 --- a/breathecode/events/tests/urls/tests_academy_event_liveclass_join_hash.py +++ b/breathecode/events/tests/urls/tests_academy_event_liveclass_join_hash.py @@ -27,8 +27,8 @@ class AcademyVenueTestSuite(EventTestCase): # When: no auth # Then: return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_liveclass_join_hash', kwargs={'hash': '1234'}) @@ -43,8 +43,8 @@ def test_no_auth(self): # When: no capability # Then: return 403 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_no_capability(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_liveclass_join_hash', kwargs={'hash': '1234'}) @@ -65,8 +65,8 @@ def test_with_no_capability(self): # When: no LiveClass # Then: return 404 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_live_classes(self): self.headers(academy=1) url = reverse_lazy('events:academy_event_liveclass_join_hash', kwargs={'hash': '1234'}) @@ -84,8 +84,8 @@ def test_no_live_classes(self): # When: have a LiveClass with no url # Then: return 400 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_url(self): self.headers(academy=1) model = self.bc.database.create(user=1, @@ -120,8 +120,8 @@ def test_no_url(self): # When: have a LiveClass # Then: redirect to the liveclass - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_a_live_class(self): self.headers(academy=1) cohort = {'online_meeting_url': self.bc.fake.url()} diff --git a/breathecode/events/tests/urls/tests_ical_cohorts.py b/breathecode/events/tests/urls/tests_ical_cohorts.py index 7ad2d0ba6..533bb53de 100644 --- a/breathecode/events/tests/urls/tests_ical_cohorts.py +++ b/breathecode/events/tests/urls/tests_ical_cohorts.py @@ -21,8 +21,8 @@ class AcademyCohortTestSuite(EventTestCase): """Test /academy/cohort""" @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__without_academy(self): """Test /academy/cohort without auth""" url = reverse_lazy('events:ical_cohorts') @@ -36,8 +36,8 @@ def test_ical_cohorts__without_academy(self): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__without_events(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -65,8 +65,8 @@ def test_ical_cohorts__without_events(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__dont_get_status_deleted(self): """Test /academy/cohort without auth""" cohort_kwargs = {'stage': 'DELETED'} @@ -100,8 +100,8 @@ def test_ical_cohorts__dont_get_status_deleted(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -145,8 +145,8 @@ def test_ical_cohorts__with_one(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__ending_date_is_none(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -174,8 +174,8 @@ def test_ical_cohorts__with_one__ending_date_is_none(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__never_ends_true(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -204,8 +204,8 @@ def test_ical_cohorts__with_one__never_ends_true(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_incoming_true__return_zero_cohorts(self): """Test /academy/cohort without auth""" cohort_kwargs = {'kickoff_date': timezone.now() - timedelta(days=1)} @@ -238,8 +238,8 @@ def test_ical_cohorts__with_one__with_incoming_true__return_zero_cohorts(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_incoming_true(self): """Test /academy/cohort without auth""" cohort_kwargs = { @@ -288,8 +288,8 @@ def test_ical_cohorts__with_one__with_incoming_true(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_teacher__with_ending_date(self): """Test /academy/cohort without auth""" cohort_user_kwargs = {'role': 'TEACHER'} @@ -340,8 +340,8 @@ def test_ical_cohorts__with_one__with_teacher__with_ending_date(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -404,8 +404,8 @@ def test_ical_cohorts__with_two(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two__with_teacher__with_ending_date(self): """Test /academy/cohort without auth""" cohort_user_kwargs = {'role': 'TEACHER'} @@ -481,8 +481,8 @@ def test_ical_cohorts__with_two__with_teacher__with_ending_date(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two__with_teacher__with_ending_date__with_two_academies_id(self): """Test /academy/cohort without auth""" cohort_user_kwargs = {'role': 'TEACHER'} @@ -608,8 +608,8 @@ def test_ical_cohorts__with_two__with_teacher__with_ending_date__with_two_academ self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two__with_teacher__with_ending_date__with_two_academies_slug(self): """Test /academy/cohort without auth""" cohort_user_kwargs = {'role': 'TEACHER'} @@ -742,8 +742,8 @@ def test_ical_cohorts__with_two__with_teacher__with_ending_date__with_two_academ """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__first_day__last_day(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -845,8 +845,8 @@ def test_ical_cohorts__with_one__first_day__last_day(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__first_day__last_day__timeslot_not_recurrent(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -939,8 +939,8 @@ def test_ical_cohorts__with_one__first_day__last_day__timeslot_not_recurrent(sel self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two__first_day__last_day__two_timeslots(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} @@ -1115,8 +1115,8 @@ def test_ical_cohorts__with_two__first_day__last_day__two_timeslots(self): self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_two__first_day__last_day__two_timeslots__cohort_with_meeting_url(self): """Test /academy/cohort without auth""" device_id_kwargs = {'name': 'server'} diff --git a/breathecode/events/tests/urls/tests_ical_student_id.py b/breathecode/events/tests/urls/tests_ical_student_id.py index 322480f31..35fc3f94f 100644 --- a/breathecode/events/tests/urls/tests_ical_student_id.py +++ b/breathecode/events/tests/urls/tests_ical_student_id.py @@ -1,16 +1,18 @@ """ Test /academy/cohort """ +import urllib from datetime import datetime, timedelta from unittest.mock import MagicMock, patch -import urllib -from django.urls.base import reverse_lazy + import pytz -from rest_framework import status -from breathecode.events.actions import fix_datetime_weekday +from django.urls.base import reverse_lazy from django.utils import timezone +from rest_framework import status +from breathecode.events.actions import fix_datetime_weekday from breathecode.utils.datetime_integer import DatetimeInteger + from ..mixins.new_events_tests_case import EventTestCase @@ -21,8 +23,8 @@ class AcademyCohortTestSuite(EventTestCase): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__without_student(self): url = reverse_lazy('events:ical_student_id', kwargs={'user_id': 1}) args = {'academy': '1'} @@ -42,8 +44,8 @@ def test_ical_cohorts__without_student(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__without_cohort_time_slot(self): device_id_kwargs = {'name': 'server'} model = self.generate_models(academy=True, device_id=True, device_id_kwargs=device_id_kwargs, cohort_user=True) @@ -73,8 +75,8 @@ def test_ical_cohorts__without_cohort_time_slot(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__cohort_never_ends(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -122,8 +124,8 @@ def test_ical_cohorts__with_one__cohort_never_ends(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__cohort_without_ending_date(self): device_id_kwargs = {'name': 'server'} @@ -166,8 +168,8 @@ def test_ical_cohorts__with_one__cohort_without_ending_date(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_ending_date(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -244,8 +246,8 @@ def test_ical_cohorts__with_one__with_ending_date(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__not_recurrent(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -321,8 +323,8 @@ def test_ical_cohorts__with_one__not_recurrent(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__without_ending_date(self): device_id_kwargs = {'name': 'server'} @@ -384,8 +386,8 @@ def test_ical_cohorts__with_one__without_ending_date(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__stage_deleted(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = {'stage': 'DELETED'} @@ -431,8 +433,8 @@ def test_ical_cohorts__with_one__stage_deleted(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_incoming_true__return_zero_time_slots(self): device_id_kwargs = {'name': 'server'} @@ -473,8 +475,8 @@ def test_ical_cohorts__with_one__with_incoming_true__return_zero_time_slots(self self.assertEqual(response.status_code, status.HTTP_200_OK) @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_incoming_true(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -558,8 +560,8 @@ def test_ical_cohorts__with_one__with_incoming_true(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohorts__with_one__with_teacher(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -651,8 +653,8 @@ def test_ical_cohorts__with_one__with_teacher(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohort__with_two__with_teacher(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { @@ -778,8 +780,8 @@ def test_ical_cohort__with_two__with_teacher(self): """ @patch('breathecode.events.tasks.build_live_classes_from_timeslot.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_ical_cohort__with_two__with_teacher__cohort_with_meeting_url(self): device_id_kwargs = {'name': 'server'} cohort_kwargs = { diff --git a/breathecode/events/tests/urls/tests_me.py b/breathecode/events/tests/urls/tests_me.py index a98bec39e..3eb4bc804 100644 --- a/breathecode/events/tests/urls/tests_me.py +++ b/breathecode/events/tests/urls/tests_me.py @@ -149,8 +149,8 @@ def extract_starting_at(d): class AcademyEventTestSuite(EventTestCase): cache = EventCache() - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): self.headers(academy=1) url = reverse_lazy('events:me') @@ -162,8 +162,8 @@ def test_no_auth(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 401) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_items(self): self.headers(academy=1) url = reverse_lazy('events:me') @@ -178,8 +178,8 @@ def test_zero_items(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__non_visible(self): self.headers(academy=1) url = reverse_lazy('events:me') @@ -198,8 +198,8 @@ def test_one_item__non_visible(self): 🥆🥆🥆 Academy hunter """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__academy_non_visible__because_owner_dont_allow_share_the_event_type(self): event_type_visibility_setting = { 'academy_id': 2, @@ -232,8 +232,8 @@ def test_one_item__academy_non_visible__because_owner_dont_allow_share_the_event self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__academy_visible(self): cases = [ ( @@ -296,8 +296,8 @@ def test_one_item__academy_visible(self): 🥆🥆🥆 Cohort hunter """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__cohort_non_visible__because_owner_dont_allow_share_the_event_type(self): event_type_visibility_setting = { 'academy_id': 2, @@ -330,8 +330,8 @@ def test_one_item__cohort_non_visible__because_owner_dont_allow_share_the_event_ self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__cohort_visible(self): cases = [ ( @@ -395,8 +395,8 @@ def test_one_item__cohort_visible(self): 🥆🥆🥆 Syllabus hunter """ - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__syllabus_non_visible__because_owner_dont_allow_share_the_event_type(self): event_type_visibility_setting = { 'academy_id': 2, @@ -427,8 +427,8 @@ def test_one_item__syllabus_non_visible__because_owner_dont_allow_share_the_even self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__syllabus_visible(self): cases = [ ( @@ -500,8 +500,8 @@ def test_one_item__syllabus_visible(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_item__status_not_active(self): cases = [ ( diff --git a/breathecode/events/tests/urls/tests_me_event_id.py b/breathecode/events/tests/urls/tests_me_event_id.py index da03d5c10..c8af61f9d 100644 --- a/breathecode/events/tests/urls/tests_me_event_id.py +++ b/breathecode/events/tests/urls/tests_me_event_id.py @@ -152,8 +152,8 @@ class AcademyEventTestSuite(EventTestCase): # When: no auth # Then: return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -168,8 +168,8 @@ def test_no_auth(self): # When: zero Event # Then: return 404 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_items(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -188,8 +188,8 @@ def test_zero_items(self): # Given: 1 Event, 1 EventType and 1 User # When: No EventTypeVisibilitySetting # Then: return 404 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_visible(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -210,8 +210,8 @@ def test_no_visible(self): # Given: 1 Event, 1 EventType, 1 User, 1 Academy and 1 CohortUser # When: visible in this cohort # Then: return 200 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_visible_in_this_cohort(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -245,8 +245,8 @@ def test_visible_in_this_cohort(self): # Given: 1 Event, 1 EventType, 1 User, 1 Academy and 1 CohortUser # When: visible in this academy # Then: return 200 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_visible_in_this_academy(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -279,8 +279,8 @@ def test_visible_in_this_academy(self): # Given: 1 Event, 1 EventType, 1 User, 1 Academy and 1 CohortUser # When: visible in this academy # Then: return 200 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_visible_in_this_syllabus(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -316,8 +316,8 @@ def test_visible_in_this_syllabus(self): # Given: 1 Event, 1 EventType, 1 EventTypeSet, 1 User, 1 Academy and 1 Subscription # When: visible in this subscription # Then: return 200 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_visible_in_this_subscription(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) @@ -350,8 +350,8 @@ def test_visible_in_this_subscription(self): # -> 1 Profile and 2 ProfileTranslation # When: visible in this plan financing # Then: return 200 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_visible_in_this_plan_financing(self): self.headers(academy=1) url = reverse_lazy('events:me_event_id', kwargs={'event_id': 1}) diff --git a/breathecode/events/tests/urls/tests_me_event_id_join.py b/breathecode/events/tests/urls/tests_me_event_id_join.py index ee8812cfc..0c932ecad 100644 --- a/breathecode/events/tests/urls/tests_me_event_id_join.py +++ b/breathecode/events/tests/urls/tests_me_event_id_join.py @@ -106,8 +106,8 @@ class AcademyEventTestSuite(EventTestCase): # When: no auth # Then: return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_auth(self): @@ -134,8 +134,8 @@ def test_no_auth(self): # When: no consumables # Then: return 402 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables(self): event_type_model = model = self.bc.database.create(event_type_set=1) @@ -187,8 +187,8 @@ def test_no_consumables(self): # Then: return 404 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__live_event_not_found(self): permission = {'codename': 'event_join'} @@ -224,8 +224,8 @@ def test_no_consumables__bypass_with_feature_flag__live_event_not_found(self): # Then: return 400 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__with_live_event__cohort_without_url(self): permission = {'codename': 'event_join'} @@ -284,8 +284,8 @@ def test_no_consumables__bypass_with_feature_flag__with_live_event__cohort_witho # Then: return 302 to cohort.online_meeting_url and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__with_live_event__cohort_with_url(self): permission = {'codename': 'event_join'} @@ -353,8 +353,8 @@ def test_no_consumables__bypass_with_feature_flag__with_live_event__cohort_with_ # Then: return 404 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__live_event_not_found(self): permission = {'codename': 'event_join'} @@ -390,8 +390,8 @@ def test_no_consumables__it_try_to_consume__live_event_not_found(self): # Then: return 400 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__with_live_event__cohort_without_url(self): permission = {'codename': 'event_join'} @@ -450,8 +450,8 @@ def test_no_consumables__it_try_to_consume__with_live_event__cohort_without_url( # Then: return 402 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__with_live_event__cohort_with_url(self): permission = {'codename': 'event_join'} @@ -536,8 +536,8 @@ def test_no_consumables__it_try_to_consume__with_live_event__cohort_with_url(sel # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_past(self): permission = {'codename': 'event_join'} @@ -605,8 +605,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_past(self): # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_future(self): permission = {'codename': 'event_join'} @@ -695,8 +695,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_future(self # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__academy_no_saas__non_free1(self): permission = {'codename': 'event_join'} @@ -789,8 +789,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__aca # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__academy_no_saas__non_free2(self): permission = {'codename': 'event_join'} @@ -885,8 +885,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__aca # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_is_free_with_cohort_users_saas__cohort(self): permission = {'codename': 'event_join'} @@ -980,8 +980,8 @@ def test_is_free_with_cohort_users_saas__cohort(self): # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_is_free_with_cohort_users_saas__academy(self): permission = {'codename': 'event_join'} @@ -1075,8 +1075,8 @@ def test_is_free_with_cohort_users_saas__academy(self): # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_is_free_with_cohort_users_no_saas__cohort(self): permission = {'codename': 'event_join'} @@ -1160,8 +1160,8 @@ def test_is_free_with_cohort_users_no_saas__cohort(self): # Then: return 200 and create a ConsumptionSession and create a EventCheckin with status DONE @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_is_free_with_cohort_users_no_saas__academy(self): permission = {'codename': 'event_join'} @@ -1241,8 +1241,8 @@ def test_is_free_with_cohort_users_no_saas__academy(self): # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__show_countdown(self): permission = {'codename': 'event_join'} @@ -1327,8 +1327,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__sho # Then: return 200 and avoid to create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__show_countdown(self): permission = {'codename': 'event_join'} @@ -1436,8 +1436,8 @@ def test_with_consumable__it_try_to_consume__with_live_event__in_the_future__sho ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) -@patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) -@patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) +@patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) +@patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test__post__auth__no_saas__finantial_status_no_late(bc: Breathecode, client: fx.Client, academy, cohort, cohort_user): @@ -1526,8 +1526,8 @@ def test__post__auth__no_saas__finantial_status_no_late(bc: Breathecode, client: ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_events', MagicMock(return_value=True)) -@patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) -@patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) +@patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) +@patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test__post__auth__no_saas__finantial_status_late(bc: Breathecode, client: fx.Client, academy, cohort): permission = {'codename': 'event_join'} diff --git a/breathecode/events/tests/urls/tests_me_event_liveclass.py b/breathecode/events/tests/urls/tests_me_event_liveclass.py index 838421aa6..5d94c8a37 100644 --- a/breathecode/events/tests/urls/tests_me_event_liveclass.py +++ b/breathecode/events/tests/urls/tests_me_event_liveclass.py @@ -40,8 +40,8 @@ class AcademyEventTestSuite(EventTestCase): # When: I call the API without authentication # Then: I should get a 401 error - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_no_auth(self): url = reverse_lazy('events:me_event_liveclass') @@ -55,8 +55,8 @@ def test_no_auth(self): # Given: User # When: User is authenticated and has no LiveClass # Then: I should get a 200 status code with no data - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_zero_live_classes(self): self.bc.request.set_headers(academy=1) @@ -76,8 +76,8 @@ def test_zero_live_classes(self): # Given: a User, LiveClass, Cohort and CohortTimeSlot # When: User is authenticated, has LiveClass and CohortUser belongs to this LiveClass # Then: I should get a 200 status code with the LiveClass data - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_one_live_class(self): self.bc.request.set_headers(academy=1) @@ -101,8 +101,8 @@ def test_one_live_class(self): # Then: the mock should be called with the correct arguments and does not raise an exception @patch('breathecode.utils.api_view_extensions.extensions.lookup_extension.compile_lookup', MagicMock(wraps=lookup_extension.compile_lookup)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_lookup_extension(self): self.bc.request.set_headers(academy=1) diff --git a/breathecode/events/tests/urls/tests_me_event_liveclass_join_hash.py b/breathecode/events/tests/urls/tests_me_event_liveclass_join_hash.py index 3674f6191..adf87f96c 100644 --- a/breathecode/events/tests/urls/tests_me_event_liveclass_join_hash.py +++ b/breathecode/events/tests/urls/tests_me_event_liveclass_join_hash.py @@ -7,9 +7,9 @@ from django.urls.base import reverse_lazy from django.utils import timezone +from breathecode.events import tasks as tasks_events from breathecode.events.caches import EventCache from breathecode.payments import tasks -from breathecode.events import tasks as tasks_events from ..mixins.new_events_tests_case import EventTestCase @@ -89,8 +89,8 @@ class AcademyEventTestSuite(EventTestCase): # When: no auth # Then: return 401 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_auth(self): @@ -117,8 +117,8 @@ def test_no_auth(self): # When: no consumables # Then: return 402 - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables(self): model = self.bc.database.create(user=1, token=1) @@ -157,8 +157,8 @@ def test_no_consumables(self): # Then: return 404 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__live_class_not_found(self): permission = {'codename': 'live_class_join'} @@ -193,8 +193,8 @@ def test_no_consumables__bypass_with_feature_flag__live_class_not_found(self): # Then: return 400 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__with_live_class__cohort_without_url(self): permission = {'codename': 'live_class_join'} @@ -239,8 +239,8 @@ def test_no_consumables__bypass_with_feature_flag__with_live_class__cohort_witho # Then: return 302 to cohort.online_meeting_url @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=False)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__bypass_with_feature_flag__with_live_class__cohort_with_url(self): permission = {'codename': 'live_class_join'} @@ -289,8 +289,8 @@ def test_no_consumables__bypass_with_feature_flag__with_live_class__cohort_with_ # Then: return 404 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__live_class_not_found(self): permission = {'codename': 'live_class_join'} @@ -325,8 +325,8 @@ def test_no_consumables__it_try_to_consume__live_class_not_found(self): # Then: return 400 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__with_live_class__cohort_without_url(self): permission = {'codename': 'live_class_join'} @@ -372,8 +372,8 @@ def test_no_consumables__it_try_to_consume__with_live_class__cohort_without_url( # Then: return 402 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_no_consumables__it_try_to_consume__with_live_class__cohort_with_url(self): permission = {'codename': 'live_class_join'} @@ -425,8 +425,8 @@ def test_no_consumables__it_try_to_consume__with_live_class__cohort_with_url(sel # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_class__in_the_past(self): permission = {'codename': 'live_class_join'} @@ -478,8 +478,8 @@ def test_with_consumable__it_try_to_consume__with_live_class__in_the_past(self): # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_class__in_the_future(self): permission = {'codename': 'live_class_join'} @@ -549,8 +549,8 @@ def test_with_consumable__it_try_to_consume__with_live_class__in_the_future(self # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_class__in_the_future__show_countdown(self): @@ -620,8 +620,8 @@ def test_with_consumable__it_try_to_consume__with_live_class__in_the_future__sho # Then: return 200 and create a ConsumptionSession @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) @patch('breathecode.events.tasks.mark_live_class_as_started.delay', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_class__on_starting_time(self): @@ -682,8 +682,8 @@ def test_with_consumable__it_try_to_consume__with_live_class__on_starting_time(s # Then: return a redirection status 302 @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('breathecode.events.permissions.flags.Release.enable_consume_live_classes', MagicMock(return_value=True)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) @patch('breathecode.payments.tasks.end_the_consumption_session.apply_async', MagicMock(return_value=None)) @patch('breathecode.events.tasks.mark_live_class_as_started.delay', MagicMock(return_value=None)) def test_with_consumable__it_try_to_consume__with_live_class__on_starting_time_is_teacher(self): diff --git a/breathecode/feedback/models.py b/breathecode/feedback/models.py index c6dbc5edf..455c4a0f0 100644 --- a/breathecode/feedback/models.py +++ b/breathecode/feedback/models.py @@ -1,11 +1,13 @@ import datetime -from django.db import models + from django.contrib.auth.models import User +from django.db import models + +import breathecode.feedback.signals as signals from breathecode.admissions.models import Academy, Cohort, CohortUser +from breathecode.authenticate.models import Token from breathecode.events.models import Event from breathecode.mentorship.models import MentorshipSession -import breathecode.feedback.signals as signals -from breathecode.authenticate.models import Token __all__ = ['UserProxy', 'CohortUserProxy', 'CohortProxy', 'Survey', 'Answer'] @@ -141,7 +143,7 @@ def save(self, *args, **kwargs): if self.__old_status != self.status and self.status == 'ANSWERED': # signal the updated answer - signals.survey_answered.send(instance=self, sender=Answer) + signals.survey_answered.send_robust(instance=self, sender=Answer) class ReviewPlatform(models.Model): diff --git a/breathecode/feedback/tests/actions/tests_calculate_survey_scores.py b/breathecode/feedback/tests/actions/tests_calculate_survey_scores.py index 03d48c0c8..51ff6ea26 100644 --- a/breathecode/feedback/tests/actions/tests_calculate_survey_scores.py +++ b/breathecode/feedback/tests/actions/tests_calculate_survey_scores.py @@ -19,7 +19,7 @@ class SurveyTestSuite(FeedbackTestCase): 🔽🔽🔽 GET without Survey """ - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test__without_survey(self): self.headers(academy=1) model = self.generate_models(authenticate=True, profile_academy=True, capability='read_survey', role=1) @@ -34,7 +34,7 @@ def test__without_survey(self): 🔽🔽🔽 GET with one Survey """ - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test__with_survey(self): self.headers(academy=1) model = self.generate_models(authenticate=True, @@ -56,7 +56,7 @@ def test__with_survey(self): 🔽🔽🔽 GET with one Survey and many Answer with bad statuses """ - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test__with_survey__answers_with_bad_statuses(self): self.headers(academy=1) @@ -85,7 +85,7 @@ def test__with_survey__answers_with_bad_statuses(self): 🔽🔽🔽 GET with one Survey and many Answer with right status, score not set """ - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test__with_survey__answers_with_right_status__score_not_set(self): self.headers(academy=1) @@ -113,7 +113,7 @@ def test__with_survey__answers_with_right_status__score_not_set(self): 🔽🔽🔽 GET with one Survey and many Answer with right status, score set """ - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test__with_survey__answers_with_right_status__score_set(self): self.headers(academy=1) diff --git a/breathecode/feedback/tests/actions/tests_send_question.py b/breathecode/feedback/tests/actions/tests_send_question.py index 0f6543004..ec4ba3740 100644 --- a/breathecode/feedback/tests/actions/tests_send_question.py +++ b/breathecode/feedback/tests/actions/tests_send_question.py @@ -2,17 +2,19 @@ Test /answer """ import random -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch + from breathecode.tests.mocks import ( - MAILGUN_PATH, MAILGUN_INSTANCES, - apply_mailgun_requests_post_mock, - SLACK_PATH, + MAILGUN_PATH, SLACK_INSTANCES, + SLACK_PATH, + apply_mailgun_requests_post_mock, apply_slack_requests_request_mock, ) -from ..mixins import FeedbackTestCase + from ...actions import send_question, strings +from ..mixins import FeedbackTestCase class SendSurveyTestSuite(FeedbackTestCase): @@ -22,8 +24,8 @@ class SendSurveyTestSuite(FeedbackTestCase): @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__without_cohort(self): mock_mailgun = MAILGUN_INSTANCES['post'] mock_mailgun.call_args_list = [] @@ -51,8 +53,8 @@ def test_send_question__without_cohort(self): @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__with_same_user_in_two_cohort(self): mock_mailgun = MAILGUN_INSTANCES['post'] mock_mailgun.call_args_list = [] @@ -85,11 +87,11 @@ def test_send_question__with_same_user_in_two_cohort(self): 🔽🔽🔽 Cohort without SyllabusVersion """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__cohort_without_syllabus_version(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -145,11 +147,11 @@ def test_send_question__cohort_without_syllabus_version(self): 🔽🔽🔽 Cohort without SyllabusSchedule """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__cohort_without_syllabus_schedule(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -205,11 +207,11 @@ def test_send_question__cohort_without_syllabus_schedule(self): 🔽🔽🔽 Answer are generate and send in a email """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__just_send_by_email(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -268,11 +270,11 @@ def test_send_question__just_send_by_email(self): 🔽🔽🔽 Answer are generate and send in a email, passing cohort """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__just_send_by_email__passing_cohort(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -331,11 +333,11 @@ def test_send_question__just_send_by_email__passing_cohort(self): 🔽🔽🔽 Answer are generate and send in a email and slack """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__send_by_email_and_slack(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -400,11 +402,11 @@ def test_send_question__send_by_email_and_slack(self): 🔽🔽🔽 Send question in english """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__with_cohort_lang_en(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -470,11 +472,11 @@ def test_send_question__with_cohort_lang_en(self): 🔽🔽🔽 Send question in spanish """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(MAILGUN_PATH['post'], apply_mailgun_requests_post_mock()) @patch(SLACK_PATH['request'], apply_slack_requests_request_mock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_question__with_cohort_lang_es(self): statuses = ['ACTIVE', 'GRADUATED'] diff --git a/breathecode/feedback/tests/actions/tests_send_survey_group.py b/breathecode/feedback/tests/actions/tests_send_survey_group.py index 91b198a73..670d9900f 100644 --- a/breathecode/feedback/tests/actions/tests_send_survey_group.py +++ b/breathecode/feedback/tests/actions/tests_send_survey_group.py @@ -18,8 +18,8 @@ class AnswerTestSuite(FeedbackTestCase): @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_survey_group(self): with self.assertRaisesMessage(ValidationException, 'missing-survey-or-cohort'): @@ -28,8 +28,8 @@ def test_send_survey_group(self): self.assertEqual(tasks.send_cohort_survey.delay.call_args_list, []) @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_survey_and_cohort_do_not_match(self): model = self.generate_models(cohort=2, survey=1) @@ -40,8 +40,8 @@ def test_when_survey_and_cohort_do_not_match(self): self.assertEqual(tasks.send_cohort_survey.delay.call_args_list, []) @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_cohort_does_not_have_teacher_assigned_to_survey(self): wrong_roles = ['ASSISTANT', 'REVIEWER', 'STUDENT'] @@ -54,11 +54,11 @@ def test_when_cohort_does_not_have_teacher_assigned_to_survey(self): send_survey_group(model.survey, model.cohort) self.assertEqual(tasks.send_cohort_survey.delay.call_args_list, []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_educational_status_is_active_or_graduated(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -90,11 +90,11 @@ def test_when_educational_status_is_active_or_graduated(self): self.assertEqual(tasks.send_cohort_survey.delay.call_args_list, [call(model.user.id, model.survey.id)]) tasks.send_cohort_survey.delay.call_args_list = [] - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_educational_status_is_all_of_the_others_error(self): statuses = ['POSTPONED', 'SUSPENDED', 'DROPPED'] @@ -131,8 +131,8 @@ def test_when_educational_status_is_all_of_the_others_error(self): @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_some_cases_are_successful_and_some_are_error(self): cohort_users = [{ @@ -176,8 +176,8 @@ def test_when_some_cases_are_successful_and_some_are_error(self): @patch('breathecode.feedback.tasks.send_cohort_survey.delay', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_survey_is_none(self): model = self.generate_models(cohort=1, diff --git a/breathecode/feedback/tests/admin/tests_send_bulk_cohort_user_survey.py b/breathecode/feedback/tests/admin/tests_send_bulk_cohort_user_survey.py index 5db01d584..7454d16e6 100644 --- a/breathecode/feedback/tests/admin/tests_send_bulk_cohort_user_survey.py +++ b/breathecode/feedback/tests/admin/tests_send_bulk_cohort_user_survey.py @@ -3,15 +3,14 @@ """ import logging from unittest.mock import MagicMock, call, patch -from django.http.request import HttpRequest + from django.contrib.auth.models import User -from ..mixins import FeedbackTestCase -from ...admin import send_bulk_cohort_user_survey +from django.contrib.messages import api +from django.http.request import HttpRequest -from ..mixins import FeedbackTestCase from ... import actions - -from django.contrib.messages import api +from ...admin import send_bulk_cohort_user_survey +from ..mixins import FeedbackTestCase class SendSurveyTestSuite(FeedbackTestCase): @@ -21,8 +20,8 @@ class SendSurveyTestSuite(FeedbackTestCase): @patch('django.contrib.messages.api.add_message', MagicMock()) @patch('breathecode.feedback.actions.send_question', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_zero_cohort_users(self): request = HttpRequest() @@ -43,8 +42,8 @@ def test_with_zero_cohort_users(self): @patch('django.contrib.messages.api.add_message', MagicMock()) @patch('breathecode.feedback.actions.send_question', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_two_cohort_users(self): request = HttpRequest() CohortUser = self.bc.database.get_model('admissions.CohortUser') @@ -74,8 +73,8 @@ def test_with_two_cohort_users(self): @patch('django.contrib.messages.api.add_message', MagicMock()) @patch('breathecode.feedback.actions.send_question', MagicMock(side_effect=Exception('qwerty'))) @patch('logging.Logger.fatal', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_two_cohort_users__raises_exceptions__same_exception(self): request = HttpRequest() CohortUser = self.bc.database.get_model('admissions.CohortUser') @@ -102,8 +101,8 @@ def test_with_two_cohort_users__raises_exceptions__same_exception(self): @patch('breathecode.feedback.actions.send_question', MagicMock(side_effect=[Exception('qwerty1'), Exception('qwerty2')])) @patch('logging.Logger.fatal', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_with_two_cohort_users__raises_exceptions__different_exceptions(self): request = HttpRequest() CohortUser = self.bc.database.get_model('admissions.CohortUser') diff --git a/breathecode/feedback/tests/tasks/tests_generate_user_cohort_survey_answers.py b/breathecode/feedback/tests/tasks/tests_generate_user_cohort_survey_answers.py index 2651a79bb..53903a67c 100644 --- a/breathecode/feedback/tests/tasks/tests_generate_user_cohort_survey_answers.py +++ b/breathecode/feedback/tests/tasks/tests_generate_user_cohort_survey_answers.py @@ -49,7 +49,7 @@ def test_when_student_is_not_assigned(self): self.assertEqual(self.bc.database.list_of('feedback.Answer'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test_when_teacher_is_not_assigned(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -63,7 +63,7 @@ def test_when_teacher_is_not_assigned(self): self.assertEqual(self.bc.database.list_of('feedback.Answer'), []) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test_when_teacher_is_assigned(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -121,7 +121,7 @@ def test_when_teacher_is_assigned(self): # teardown self.bc.database.delete('feedback.Answer') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test_when_cohort_has_syllabus(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -179,7 +179,7 @@ def test_when_cohort_has_syllabus(self): # teardown self.bc.database.delete('feedback.Answer') - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test_role_assistant(self): statuses = ['ACTIVE', 'GRADUATED'] diff --git a/breathecode/feedback/tests/tasks/tests_process_answer_received.py b/breathecode/feedback/tests/tasks/tests_process_answer_received.py index 221bffbd5..48bef983c 100644 --- a/breathecode/feedback/tests/tasks/tests_process_answer_received.py +++ b/breathecode/feedback/tests/tasks/tests_process_answer_received.py @@ -22,7 +22,7 @@ class SurveyAnsweredTestSuite(FeedbackTestCase): @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', MagicMock(wraps=actions.calculate_survey_response_rate)) @@ -44,7 +44,7 @@ def test_survey_answered_task_without_answer(self): @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', MagicMock(wraps=actions.calculate_survey_response_rate)) @@ -71,7 +71,7 @@ def test_survey_answered_task_without_survey(self): @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', MagicMock(wraps=actions.calculate_survey_response_rate)) @@ -102,7 +102,7 @@ def test_survey_answered_task_with_survey(self): @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -138,7 +138,7 @@ def test_survey_answered_task_with_survey_score_seven(self): @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -174,7 +174,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy(self): @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(return_value=None)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -213,7 +213,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy__with_user__ }]) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -271,7 +271,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy__with_user__ 'SYSTEM_EMAIL': None, 'ADMIN_URL': 'https://www.whatever.com' }))) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -325,7 +325,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy__with_user__ 'SYSTEM_EMAIL': 'test@email.com', 'ADMIN_URL': 'https://www.whatever.com' }))) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -378,7 +378,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy__with_user__ 'SYSTEM_EMAIL': 'test@email.com', 'ADMIN_URL': 'https://www.whatever.com' }))) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', @@ -428,7 +428,7 @@ def test_survey_answered_task_with_survey_score_seven__with_academy__with_user__ @patch('logging.Logger.warning', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(wraps=actions.calculate_survey_scores)) @patch('breathecode.feedback.actions.calculate_survey_response_rate', diff --git a/breathecode/feedback/tests/tasks/tests_recalculate_survey_scores.py b/breathecode/feedback/tests/tasks/tests_recalculate_survey_scores.py index c8aa6c029..155581dff 100644 --- a/breathecode/feedback/tests/tasks/tests_recalculate_survey_scores.py +++ b/breathecode/feedback/tests/tasks/tests_recalculate_survey_scores.py @@ -44,7 +44,7 @@ class SurveyAnsweredTestSuite(FeedbackTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(return_value=get_scores())) @patch('breathecode.feedback.actions.calculate_survey_response_rate', MagicMock(return_value=RESPONSE_RATE)) def test_with_zero_surveys(self): @@ -67,7 +67,7 @@ def test_with_zero_surveys(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) @patch('breathecode.feedback.actions.calculate_survey_scores', MagicMock(return_value=get_scores())) @patch('breathecode.feedback.actions.calculate_survey_response_rate', MagicMock(return_value=RESPONSE_RATE)) def test_with_one_surveys(self): diff --git a/breathecode/feedback/tests/tasks/tests_send_cohort_survey.py b/breathecode/feedback/tests/tasks/tests_send_cohort_survey.py index 24a6573a6..c46898a59 100644 --- a/breathecode/feedback/tests/tasks/tests_send_cohort_survey.py +++ b/breathecode/feedback/tests/tasks/tests_send_cohort_survey.py @@ -31,8 +31,8 @@ class SendCohortSurvey(FeedbackTestCase): @patch('breathecode.feedback.tasks.generate_user_cohort_survey_answers', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('logging.Logger.info', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_survey_is_none(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): @@ -54,8 +54,8 @@ def test_when_survey_is_none(self): @patch('breathecode.feedback.tasks.generate_user_cohort_survey_answers', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('logging.Logger.info', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_user_is_none(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): @@ -74,8 +74,8 @@ def test_when_user_is_none(self): @patch('breathecode.feedback.tasks.generate_user_cohort_survey_answers', MagicMock()) @patch('logging.Logger.error', MagicMock()) @patch('logging.Logger.info', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_survey_has_expired(self): created = timezone.now() - timedelta(hours=48, minutes=1) @@ -104,8 +104,8 @@ def test_when_survey_has_expired(self): @patch('logging.Logger.error', MagicMock()) @patch('logging.Logger.info', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_send_cohort_when_student_does_not_belong_to_cohort(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): @@ -128,8 +128,8 @@ def test_send_cohort_when_student_does_not_belong_to_cohort(self): @patch('logging.Logger.info', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_student_not_found(self): with patch('breathecode.activity.tasks.get_attendancy_log.delay', MagicMock()): @@ -162,10 +162,10 @@ def test_when_student_not_found(self): @patch('logging.Logger.error', MagicMock()) @patch('logging.Logger.info', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_an_email_is_sent(self): statuses = ['ACTIVE', 'GRADUATED'] @@ -210,10 +210,10 @@ def test_when_an_email_is_sent(self): @patch('logging.Logger.info', MagicMock()) @patch('breathecode.notify.actions.send_email_message', MagicMock()) @patch('breathecode.notify.actions.send_slack', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_when_an_email_is_sent_with_slack_team_and_user(self): statuses = ['ACTIVE', 'GRADUATED'] diff --git a/breathecode/feedback/tests/tasks/tests_send_mentorship_session_survey.py b/breathecode/feedback/tests/tasks/tests_send_mentorship_session_survey.py index b25e56376..2a4e995f5 100644 --- a/breathecode/feedback/tests/tasks/tests_send_mentorship_session_survey.py +++ b/breathecode/feedback/tests/tasks/tests_send_mentorship_session_survey.py @@ -59,7 +59,7 @@ class ActionCertificateScreenshotTestCase(FeedbackTestCase): @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__without_mentorship_session(self): from logging import Logger @@ -84,7 +84,7 @@ def test_send_mentorship_session_survey__without_mentorship_session(self): @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session(self): from logging import Logger @@ -109,7 +109,7 @@ def test_send_mentorship_session_survey__with_mentorship_session(self): @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__session_started_not_finished(self): from logging import Logger @@ -139,7 +139,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__s @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__session_not_started_but_finished( self): from logging import Logger @@ -170,7 +170,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__s @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__session_started_and_finished(self): from logging import Logger @@ -201,7 +201,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__s @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee(self): from logging import Logger @@ -232,7 +232,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee(se @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__with_mentorship_service(self): from logging import Logger @@ -292,7 +292,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__w @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__with_answer(self): from logging import Logger @@ -343,7 +343,7 @@ def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__w @patch('logging.Logger.error', MagicMock()) @patch('os.getenv', MagicMock(side_effect=apply_get_env({'ENV': 'test', 'API_URL': API_URL}))) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_send_mentorship_session_survey__with_mentorship_session__with_mentee__with_answer_answered(self): from logging import Logger diff --git a/breathecode/feedback/tests/urls/tests_academy_survey.py b/breathecode/feedback/tests/urls/tests_academy_survey.py index ac88f5b71..38c6998b4 100644 --- a/breathecode/feedback/tests/urls/tests_academy_survey.py +++ b/breathecode/feedback/tests/urls/tests_academy_survey.py @@ -17,8 +17,8 @@ class SurveyTestSuite(FeedbackTestCase): """Test /academy/survey""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__without_auth(self): """Test /academy/survey without authorization""" url = reverse_lazy('feedback:academy_survey') @@ -28,8 +28,8 @@ def test_academy_survey__get__without_auth(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__without_academy(self): """Test /academy/survey without academy""" self.bc.database.create(authenticate=True) @@ -44,8 +44,8 @@ def test_academy_survey__get__without_academy(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__without_role(self): """Test /academy/survey without role""" self.headers(academy=1) @@ -58,8 +58,8 @@ def test_academy_survey__get__without_role(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__without_data(self): """Test /academy/survey without data""" @@ -79,8 +79,8 @@ def test_academy_survey__get__without_data(self): self.assertEqual(json, []) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_data(self): """Test /academy/survey with data""" @@ -118,8 +118,8 @@ def test_academy_survey__get__with_data(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_response_rate(self): """Test /academy/survey wiith response rate""" @@ -157,8 +157,8 @@ def test_academy_survey__get__with_response_rate(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_sent_status_query(self): """Test /academy/survey with sent status query""" @@ -180,8 +180,8 @@ def test_academy_survey__get__with_sent_status_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_pending_status_query(self): """Test /academy/survey with pending status query""" @@ -219,8 +219,8 @@ def test_academy_survey__get__with_pending_status_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_different_lang_query(self): """Test /academy/survey with different lang status query""" @@ -242,8 +242,8 @@ def test_academy_survey__get__with_different_lang_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_same_lang_query(self): """Test /academy/survey with same lang status query""" @@ -281,8 +281,8 @@ def test_academy_survey__get__with_same_lang_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_different_cohort_slug_cohort_query(self): """Test /academy/survey with different cohort slug than what is in the cohort query""" @@ -305,8 +305,8 @@ def test_academy_survey__get__with_different_cohort_slug_cohort_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__get__with_same_cohort_slug_cohort_query(self): """Test /academy/survey with same cohort slug as in the model""" @@ -346,8 +346,8 @@ def test_academy_survey__get__with_same_cohort_slug_cohort_query(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__without_auth(self): """Test /academy/survey without authorization""" url = reverse_lazy('feedback:academy_survey') @@ -357,8 +357,8 @@ def test_academy_survey__post__without_auth(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__without_academy(self): """Test /academy/survey without authorization""" self.bc.database.create(authenticate=True) @@ -373,8 +373,8 @@ def test_academy_survey__post__without_academy(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__without_role(self): """Test /academy/survey without role""" self.headers(academy=1) @@ -387,8 +387,8 @@ def test_academy_survey__post__without_role(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__without_cohort(self): """Test /academy/survey post without cohort""" @@ -408,8 +408,8 @@ def test_academy_survey__post__without_cohort(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__with_cohort_needs_rights(self): """Test /academy/survey post with cohort needs rights""" @@ -431,8 +431,8 @@ def test_academy_survey__post__with_cohort_needs_rights(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__with_cohort_shorter_than_hour(self): """Test /academy/survey post with cohort shorter than hour""" @@ -453,8 +453,8 @@ def test_academy_survey__post__with_cohort_shorter_than_hour(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__without_cohort_teacher_assigned(self): """Test /academy/survey post without cohort teacher assigned""" @@ -476,8 +476,8 @@ def test_academy_survey__post__without_cohort_teacher_assigned(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__with_cohort_teacher_assigned(self): """Test /academy/survey post with cohort teacher assigned""" @@ -513,8 +513,8 @@ def test_academy_survey__post__with_cohort_teacher_assigned(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, status.HTTP_201_CREATED) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__with_cohort_teacher_assigned_with_longer_than_hour(self): """Test /academy/survey post with cohort teacher assigned with longer than hour.""" @@ -551,8 +551,8 @@ def test_academy_survey__post__with_cohort_teacher_assigned_with_longer_than_hou self.assertEqual(response.status_code, status.HTTP_201_CREATED) @patch('breathecode.feedback.actions.send_survey_group', MagicMock(return_value={'success': [], 'error': []})) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__post__when_send_survey_group_is_called(self): """Test /academy/sur.""" @@ -592,8 +592,8 @@ def test_academy_survey__post__when_send_survey_group_is_called(self): """DELETE Auth""" - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__delete__in_bulk_without_capability(self): """Test /academy/survey delete in bulk without capability.""" self.headers(academy=1) @@ -607,8 +607,8 @@ def test_academy_survey__delete__in_bulk_without_capability(self): }) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey_delete_in_bulk_with_two_surveys(self): """Test /academy/survey/ delete in bulk with two surveys.""" self.headers(academy=1) @@ -625,8 +625,8 @@ def test_academy_survey_delete_in_bulk_with_two_surveys(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('feedback.Survey'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey__delete__without_passing_ids(self): """Test /academy/survey/ delete without passing ids.""" self.headers(academy=1) @@ -644,8 +644,8 @@ def test_academy_survey__delete__without_passing_ids(self): self.assertEqual(response.json()['detail'], slug) self.assertEqual(self.bc.database.list_of('feedback.Survey'), self.bc.format.to_dict(model.survey)) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey_id__delete__not_answered(self): """Test /academy/survey/ id delete not answered.""" @@ -669,9 +669,9 @@ def test_academy_survey_id__delete__not_answered(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('feedback.Survey'), []) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_academy_survey_id__delete__answered(self): """Test /academy/survey/ id delete answered.""" self.headers(academy=1) diff --git a/breathecode/feedback/tests/urls/tests_academy_survey_id.py b/breathecode/feedback/tests/urls/tests_academy_survey_id.py index 18e8ee0e1..65ababcf7 100644 --- a/breathecode/feedback/tests/urls/tests_academy_survey_id.py +++ b/breathecode/feedback/tests/urls/tests_academy_survey_id.py @@ -136,7 +136,7 @@ def test_academy_survey_id__delete__not_answered(self): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(self.bc.database.list_of('feedback.Survey'), []) - @patch('breathecode.feedback.signals.survey_answered.send', MagicMock()) + @patch('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) def test_academy_survey_id__delete__answered(self): """Test /academy/survey_id delete answered(self).""" self.headers(academy=1) diff --git a/breathecode/feedback/tests/urls/tests_user_me_answer_answer_id.py b/breathecode/feedback/tests/urls/tests_user_me_answer_answer_id.py index e6212d651..a91ce90f0 100644 --- a/breathecode/feedback/tests/urls/tests_user_me_answer_answer_id.py +++ b/breathecode/feedback/tests/urls/tests_user_me_answer_answer_id.py @@ -3,14 +3,15 @@ """ import re from datetime import datetime -from unittest.mock import patch, MagicMock, call -from django.urls.base import reverse_lazy +from unittest.mock import MagicMock, call, patch + import pytest +from django.urls.base import reverse_lazy from rest_framework import status -from breathecode.services.datetime_to_iso_format import datetime_to_iso_format -import breathecode.activity.tasks as activity_tasks from rest_framework.test import APIClient +import breathecode.activity.tasks as activity_tasks +from breathecode.services.datetime_to_iso_format import datetime_to_iso_format from breathecode.tests.mixins.breathecode_mixin import Breathecode from ...signals import survey_answered @@ -18,7 +19,7 @@ @pytest.fixture(autouse=True) def setup(db, monkeypatch): - monkeypatch.setattr('breathecode.feedback.signals.survey_answered.send', MagicMock()) + monkeypatch.setattr('breathecode.feedback.signals.survey_answered.send_robust', MagicMock()) monkeypatch.setattr(activity_tasks.add_activity, 'delay', MagicMock()) yield @@ -126,7 +127,7 @@ def test_answer_id_put_with_bad_id(bc: Breathecode, client: APIClient): assert json == expected assert response.status_code == status.HTTP_404_NOT_FOUND - assert survey_answered.send.call_args_list == [] + assert survey_answered.send_robust.call_args_list == [] assert activity_tasks.add_activity.delay.call_args_list == [] @@ -146,7 +147,7 @@ def test_answer_id_put_without_score(bc: Breathecode, client: APIClient): assert json == {'non_field_errors': ['Score must be between 1 and 10']} assert response.status_code == status.HTTP_400_BAD_REQUEST assert bc.database.list_of('feedback.Answer') == [db] - assert survey_answered.send.call_args_list == [] + assert survey_answered.send_robust.call_args_list == [] assert activity_tasks.add_activity.delay.call_args_list == [] @@ -167,7 +168,7 @@ def test_answer_id_put_with_score_less_of_1(bc: Breathecode, client: APIClient): assert json == {'non_field_errors': ['Score must be between 1 and 10']} assert response.status_code == status.HTTP_400_BAD_REQUEST assert bc.database.list_of('feedback.Answer') == [db] - assert survey_answered.send.call_args_list == [] + assert survey_answered.send_robust.call_args_list == [] assert activity_tasks.add_activity.delay.call_args_list == [] @@ -188,7 +189,7 @@ def test_answer_id_put_with_score_more_of_10(bc: Breathecode, client: APIClient) assert json == {'non_field_errors': ['Score must be between 1 and 10']} assert response.status_code == status.HTTP_400_BAD_REQUEST assert bc.database.list_of('feedback.Answer') == [db] - assert survey_answered.send.call_args_list == [] + assert survey_answered.send_robust.call_args_list == [] assert activity_tasks.add_activity.delay.call_args_list == [] @@ -253,7 +254,7 @@ def test_answer_id_put_with_all_valid_scores(bc: Breathecode, client: APIClient, assert dicts == [db] - assert survey_answered.send.call_args_list == [ + assert survey_answered.send_robust.call_args_list == [ call(instance=model.answer, sender=model.answer.__class__), ] assert activity_tasks.add_activity.delay.call_args_list == [ @@ -308,7 +309,7 @@ def test_answer_id_put_twice_same_score(bc: Breathecode, client: APIClient): db['comment'] = data['comment'] assert bc.database.list_of('feedback.Answer') == [db] - assert survey_answered.send.call_args_list == [call(instance=model.answer, sender=model.answer.__class__)] + assert survey_answered.send_robust.call_args_list == [call(instance=model.answer, sender=model.answer.__class__)] assert activity_tasks.add_activity.delay.call_args_list == [ call(1, 'nps_answered', related_type='feedback.Answer', related_id=1), call(1, 'nps_answered', related_type='feedback.Answer', related_id=1), diff --git a/breathecode/marketing/models.py b/breathecode/marketing/models.py index 7ed6b4587..a03f7e444 100644 --- a/breathecode/marketing/models.py +++ b/breathecode/marketing/models.py @@ -493,8 +493,8 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) - if deal_status_modified: form_entry_won_or_lost.send(instance=self, sender=FormEntry) - if is_new_deal: new_form_entry_deal.send(instance=self, sender=FormEntry) + if deal_status_modified: form_entry_won_or_lost.send_robust(instance=self, sender=FormEntry) + if is_new_deal: new_form_entry_deal.send_robust(instance=self, sender=FormEntry) self.__old_deal_status = self.deal_status self.__old_deal_id = self.ac_deal_id @@ -714,7 +714,7 @@ def save(self, *args, **kwargs): if created: super().save(*args, **kwargs) - downloadable_saved.send(instance=self, sender=self.__class__, created=created) + downloadable_saved.send_robust(instance=self, sender=self.__class__, created=created) SOURCE = 'SOURCE' diff --git a/breathecode/marketing/tests/tasks/tests_add_cohort_slug_as_acp_tag.py b/breathecode/marketing/tests/tasks/tests_add_cohort_slug_as_acp_tag.py index 6ee33fb69..54f5cca35 100644 --- a/breathecode/marketing/tests/tasks/tests_add_cohort_slug_as_acp_tag.py +++ b/breathecode/marketing/tests/tasks/tests_add_cohort_slug_as_acp_tag.py @@ -3,8 +3,10 @@ """ import os from unittest.mock import MagicMock, call, patch + from breathecode.marketing.tasks import add_cohort_slug_as_acp_tag from breathecode.tests.mocks import apply_requests_request_mock + from ..mixins import MarketingTestCase GOOGLE_CLOUD_KEY = os.getenv('GOOGLE_CLOUD_KEY', None) @@ -29,7 +31,7 @@ class AnswerIdTestSuite(MarketingTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag__without_academy(self): import logging @@ -46,7 +48,7 @@ def test_add_cohort_slug_as_acp_tag__without_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag__without_active_campaign_academy(self): import logging @@ -70,7 +72,7 @@ def test_add_cohort_slug_as_acp_tag__without_active_campaign_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag__without_cohort(self): import logging @@ -96,7 +98,7 @@ def test_add_cohort_slug_as_acp_tag__without_cohort(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag(self): import logging @@ -133,7 +135,7 @@ def test_add_cohort_slug_as_acp_tag(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag_type_cohort(self): import logging @@ -163,7 +165,7 @@ def test_add_cohort_slug_as_acp_tag_type_cohort(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_cohort_slug_as_acp_tag__tag_exists(self): import logging @@ -199,7 +201,7 @@ def test_add_cohort_slug_as_acp_tag__tag_exists(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.cohort_saved.send', MagicMock()) + @patch('breathecode.admissions.signals.cohort_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(404, AC_URL, AC_ERROR_RESPONSE)])) def test_add_cohort_slug_as_acp_tag__status_404(self): import logging diff --git a/breathecode/marketing/tests/tasks/tests_add_cohort_task_to_student.py b/breathecode/marketing/tests/tasks/tests_add_cohort_task_to_student.py index bed43c1a6..d4843707b 100644 --- a/breathecode/marketing/tests/tasks/tests_add_cohort_task_to_student.py +++ b/breathecode/marketing/tests/tasks/tests_add_cohort_task_to_student.py @@ -3,9 +3,11 @@ """ import os from unittest.mock import MagicMock, call, patch + from breathecode.marketing.tasks import add_cohort_task_to_student from breathecode.tests.mocks import apply_requests_request_mock from breathecode.tests.mocks.requests import apply_requests_post_mock + from ..mixins import MarketingTestCase GOOGLE_CLOUD_KEY = os.getenv('GOOGLE_CLOUD_KEY', None) @@ -32,7 +34,7 @@ class AnswerIdTestSuite(MarketingTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__without_academy(self): @@ -49,7 +51,7 @@ def test_add_cohort_task_to_student__without_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__without_active_campaign_academy(self): @@ -71,7 +73,7 @@ def test_add_cohort_task_to_student__without_active_campaign_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__without_user(self): @@ -96,7 +98,7 @@ def test_add_cohort_task_to_student__without_user(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__without_cohort(self): @@ -122,7 +124,7 @@ def test_add_cohort_task_to_student__without_cohort(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student(self): @@ -156,7 +158,7 @@ def test_add_cohort_task_to_student(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__tag_exists(self): @@ -192,7 +194,7 @@ def test_add_cohort_task_to_student__tag_exists(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(404, AC_POST_URL, AC_POST_RESPONSE)])) def test_add_cohort_task_to_student__tag_exists__active_campaign_returns_404(self): @@ -231,7 +233,7 @@ def test_add_cohort_task_to_student__tag_exists__active_campaign_returns_404(sel @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_RESPONSE)])) @patch('requests.post', apply_requests_post_mock([(201, AC_POST_URL, {})])) def test_add_cohort_task_to_student__tag_exists__the_api_was_changed(self): @@ -269,7 +271,7 @@ def test_add_cohort_task_to_student__tag_exists__the_api_was_changed(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('requests.get', apply_requests_request_mock([(200, AC_URL, AC_EMPTY_RESPONSE)])) def test_add_cohort_task_to_student__status_404(self): import logging diff --git a/breathecode/marketing/tests/tasks/tests_add_downloadable_tags_as_acp_tag.py b/breathecode/marketing/tests/tasks/tests_add_downloadable_tags_as_acp_tag.py index 42f7d9179..3aa03099c 100644 --- a/breathecode/marketing/tests/tasks/tests_add_downloadable_tags_as_acp_tag.py +++ b/breathecode/marketing/tests/tasks/tests_add_downloadable_tags_as_acp_tag.py @@ -3,8 +3,10 @@ """ import os from unittest.mock import MagicMock, call, patch + from breathecode.marketing.tasks import add_downloadable_slug_as_acp_tag from breathecode.tests.mocks import apply_requests_request_mock + from ..mixins import MarketingTestCase GOOGLE_CLOUD_KEY = os.getenv('GOOGLE_CLOUD_KEY', None) @@ -29,7 +31,7 @@ class AnswerIdTestSuite(MarketingTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_downloadable_slug_as_acp_tag__without_academy(self): import logging @@ -46,7 +48,7 @@ def test_add_downloadable_slug_as_acp_tag__without_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_downloadable_slug_as_acp_tag__without_active_campaign_academy(self): import logging @@ -69,7 +71,7 @@ def test_add_downloadable_slug_as_acp_tag__without_active_campaign_academy(self) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_downloadable_slug_as_acp_tag__without_event(self): import logging @@ -94,7 +96,7 @@ def test_add_downloadable_slug_as_acp_tag__without_event(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_downloadable_slug_as_acp_tag(self): import logging @@ -135,7 +137,7 @@ def test_add_downloadable_slug_as_acp_tag(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.marketing.signals.downloadable_saved.send', MagicMock()) + @patch('breathecode.marketing.signals.downloadable_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__tag_exists(self): import logging diff --git a/breathecode/marketing/tests/tasks/tests_add_event_slug_as_acp_tag.py b/breathecode/marketing/tests/tasks/tests_add_event_slug_as_acp_tag.py index fdfc8d435..e461a7428 100644 --- a/breathecode/marketing/tests/tasks/tests_add_event_slug_as_acp_tag.py +++ b/breathecode/marketing/tests/tasks/tests_add_event_slug_as_acp_tag.py @@ -3,8 +3,10 @@ """ import os from unittest.mock import MagicMock, call, patch + from breathecode.marketing.tasks import add_event_slug_as_acp_tag from breathecode.tests.mocks import apply_requests_request_mock + from ..mixins import MarketingTestCase GOOGLE_CLOUD_KEY = os.getenv('GOOGLE_CLOUD_KEY', None) @@ -30,7 +32,7 @@ class AnswerIdTestSuite(MarketingTestCase): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__without_academy(self): import logging @@ -47,7 +49,7 @@ def test_add_event_slug_as_acp_tag__without_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__without_active_campaign_academy(self): import logging @@ -70,7 +72,7 @@ def test_add_event_slug_as_acp_tag__without_active_campaign_academy(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__without_event(self): import logging @@ -93,7 +95,7 @@ def test_add_event_slug_as_acp_tag__without_event(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__event_without_slug(self): import logging @@ -118,7 +120,7 @@ def test_add_event_slug_as_acp_tag__event_without_slug(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__event_slug_already_exists(self): import logging @@ -150,7 +152,7 @@ def test_add_event_slug_as_acp_tag__event_slug_already_exists(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__event_slug_already_exists__with_force_false(self): import logging @@ -182,7 +184,7 @@ def test_add_event_slug_as_acp_tag__event_slug_already_exists__with_force_false( @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag__event_slug_already_exists__with_force_true(self): import logging @@ -219,7 +221,7 @@ def test_add_event_slug_as_acp_tag__event_slug_already_exists__with_force_true(s @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(201, AC_URL, AC_RESPONSE)])) def test_add_event_slug_as_acp_tag(self): import logging @@ -259,7 +261,7 @@ def test_add_event_slug_as_acp_tag(self): @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.events.signals.event_saved.send', MagicMock()) + @patch('breathecode.events.signals.event_saved.send_robust', MagicMock()) @patch('requests.post', apply_requests_request_mock([(404, AC_URL, AC_ERROR_RESPONSE)])) def test_add_event_slug_as_acp_tag__status_404(self): import logging diff --git a/breathecode/mentorship/models.py b/breathecode/mentorship/models.py index 41c532011..50b7f4eeb 100644 --- a/breathecode/mentorship/models.py +++ b/breathecode/mentorship/models.py @@ -401,7 +401,7 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) # Call the "real" save() method. if is_creating or self.__old_status != self.status: - signals.mentorship_session_status.send(instance=self, sender=MentorshipSession) + signals.mentorship_session_status.send_robust(instance=self, sender=MentorshipSession) self.__old_status = self.status diff --git a/breathecode/mentorship/tests/actions/tests_get_pending_sessions_or_create.py b/breathecode/mentorship/tests/actions/tests_get_pending_sessions_or_create.py index 256070783..ac2035dcb 100644 --- a/breathecode/mentorship/tests/actions/tests_get_pending_sessions_or_create.py +++ b/breathecode/mentorship/tests/actions/tests_get_pending_sessions_or_create.py @@ -56,7 +56,7 @@ def format_mentorship_session_attrs(attrs={}): class GetOrCreateSessionTestSuite(MentorshipTestCase): @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentor_first_no_previous_nothing(self): @@ -92,7 +92,7 @@ def test_create_session_mentor_first_no_previous_nothing(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentor_first_previous_pending_without_mentee(self): @@ -128,7 +128,7 @@ def test_create_session_mentor_first_previous_pending_without_mentee(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentor_first_previous_pending_with_mentee(self): @@ -167,7 +167,7 @@ def test_create_session_mentor_first_previous_pending_with_mentee(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) #TODO: without mentee or with mentee? @@ -206,7 +206,7 @@ def test_create_session_mentor_first_started_without_mentee(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentee_first_no_previous_nothing(self): @@ -242,7 +242,7 @@ def test_create_session_mentee_first_no_previous_nothing(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentee_first_with_wihout_mentee(self): @@ -281,7 +281,7 @@ def test_create_session_mentee_first_with_wihout_mentee(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentee_first_with_another_mentee(self): @@ -341,7 +341,7 @@ def test_create_session_mentee_first_with_another_mentee(self): self.assertEqual(actions.close_older_sessions.call_args_list, [call()]) @patch(REQUESTS_PATH['request'], apply_requests_request_mock([(200, daily_url, daily_payload)])) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=ENDS_AT)) @patch('breathecode.mentorship.actions.close_older_sessions', MagicMock()) def test_create_session_mentee_first_with_another_same_mentee(self): diff --git a/breathecode/mentorship/tests/urls/tests_academy_bill.py b/breathecode/mentorship/tests/urls/tests_academy_bill.py index bf1ccfff6..3b310de7e 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_bill.py +++ b/breathecode/mentorship/tests/urls/tests_academy_bill.py @@ -391,7 +391,7 @@ def test__get__with_two_mentor_profile(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing status """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_status(self): statuses = ['DUE', 'APPROVED', 'PAID', 'IGNORED'] @@ -431,7 +431,7 @@ def test__get__with_two_mentor_profile__passing_bad_status(self): # teardown self.bc.database.delete('mentorship.MentorshipBill') - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_status(self): statuses = ['DUE', 'APPROVED', 'PAID', 'IGNORED'] @@ -487,7 +487,7 @@ def test__get__with_two_mentor_profile__passing_status(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing started_after """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test__get__with_two_mentor_profile__passing_bad_started_after(self): model = self.bc.database.create(user=1, @@ -515,7 +515,7 @@ def test__get__with_two_mentor_profile__passing_bad_started_after(self): self.bc.format.to_dict(model.mentorship_bill), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test__get__with_two_mentor_profile__passing_started_after(self): model = self.bc.database.create(user=1, @@ -554,7 +554,7 @@ def test__get__with_two_mentor_profile__passing_started_after(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing ended_before """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test__get__with_two_mentor_profile__passing_bad_ended_before(self): model = self.bc.database.create(user=1, @@ -582,7 +582,7 @@ def test__get__with_two_mentor_profile__passing_bad_ended_before(self): self.bc.format.to_dict(model.mentorship_bill), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) def test__get__with_two_mentor_profile__passing_ended_before(self): model = self.bc.database.create(user=1, diff --git a/breathecode/mentorship/tests/urls/tests_academy_mentor_id_session.py b/breathecode/mentorship/tests/urls/tests_academy_mentor_id_session.py index dca756794..ea8d308e1 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_mentor_id_session.py +++ b/breathecode/mentorship/tests/urls/tests_academy_mentor_id_session.py @@ -388,7 +388,7 @@ def test__get__with_two_mentor_profile(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing status """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -427,7 +427,7 @@ def test__get__with_two_mentor_profile__passing_bad_status(self): # teardown self.bc.database.delete('mentorship.MentorshipSession') - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -483,7 +483,7 @@ def test__get__with_two_mentor_profile__passing_status(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing billed """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -509,7 +509,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorsh self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -543,7 +543,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_ self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -570,7 +570,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -607,7 +607,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentors 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing started_after """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -635,7 +635,7 @@ def test__get__with_two_mentor_profile__passing_bad_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -670,7 +670,7 @@ def test__get__with_two_mentor_profile__passing_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after__without_started_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -713,7 +713,7 @@ def test__get__with_two_mentor_profile__passing_started_after__without_started_a 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing ended_before """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -741,7 +741,7 @@ def test__get__with_two_mentor_profile__passing_bad_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -776,7 +776,7 @@ def test__get__with_two_mentor_profile__passing_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before__without_ended_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, diff --git a/breathecode/mentorship/tests/urls/tests_academy_service_id_session.py b/breathecode/mentorship/tests/urls/tests_academy_service_id_session.py index d57ae8ecb..aad95d4d9 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_service_id_session.py +++ b/breathecode/mentorship/tests/urls/tests_academy_service_id_session.py @@ -388,7 +388,7 @@ def test__get__with_two_mentor_profile(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing status """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -427,7 +427,7 @@ def test__get__with_two_mentor_profile__passing_bad_status(self): # teardown self.bc.database.delete('mentorship.MentorshipSession') - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -484,7 +484,7 @@ def test__get__with_two_mentor_profile__passing_status(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing billed """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -510,7 +510,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorsh self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -544,7 +544,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_ self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -571,7 +571,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -608,7 +608,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentors 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing started_after """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -636,7 +636,7 @@ def test__get__with_two_mentor_profile__passing_bad_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -671,7 +671,7 @@ def test__get__with_two_mentor_profile__passing_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after__without_started_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -714,7 +714,7 @@ def test__get__with_two_mentor_profile__passing_started_after__without_started_a 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing ended_before """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -742,7 +742,7 @@ def test__get__with_two_mentor_profile__passing_bad_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -777,7 +777,7 @@ def test__get__with_two_mentor_profile__passing_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before__without_ended_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, diff --git a/breathecode/mentorship/tests/urls/tests_academy_session.py b/breathecode/mentorship/tests/urls/tests_academy_session.py index de5259a85..62c7d38fd 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_session.py +++ b/breathecode/mentorship/tests/urls/tests_academy_session.py @@ -362,7 +362,7 @@ def test__get__with_two_mentor_profile(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing status """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -401,7 +401,7 @@ def test__get__with_two_mentor_profile__passing_bad_status(self): # teardown self.bc.database.delete('mentorship.MentorshipSession') - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_status(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -458,7 +458,7 @@ def test__get__with_two_mentor_profile__passing_status(self): 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing billed """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -484,7 +484,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__without_mentorsh self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -519,7 +519,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_true__with_mentorship_ self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -546,7 +546,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__with_mentorship self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentorship_bill(self): model = self.bc.database.create(user=1, role=1, @@ -584,7 +584,7 @@ def test__get__with_two_mentor_profile__passing_billed_as_false__without_mentors 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing started_after """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -612,7 +612,7 @@ def test__get__with_two_mentor_profile__passing_bad_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after(self): utc_now = timezone.now() mentorship_session = {'started_at': utc_now} @@ -648,7 +648,7 @@ def test__get__with_two_mentor_profile__passing_started_after(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_started_after__without_started_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -692,7 +692,7 @@ def test__get__with_two_mentor_profile__passing_started_after__without_started_a 🔽🔽🔽 GET with two MentorshipSession, one MentorProfile and one MentorshipService, passing ended_before """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_bad_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -720,7 +720,7 @@ def test__get__with_two_mentor_profile__passing_bad_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before(self): utc_now = timezone.now() mentorship_session = {'ended_at': utc_now} @@ -756,7 +756,7 @@ def test__get__with_two_mentor_profile__passing_ended_before(self): self.bc.format.to_dict(model.mentorship_session), ]) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__get__with_two_mentor_profile__passing_ended_before__without_ended_at(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -1152,7 +1152,7 @@ def test__post__creating_a_element__passing_readonly_fields__is_online_as_false( 🔽🔽🔽 POST creating a element, no cohort user """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test__post__creating_a_element__no_cohort_user(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -1205,7 +1205,7 @@ def test__post__creating_a_element__no_cohort_user(self): 🔽🔽🔽 POST creating a element, mentor and mentee can be same person """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test__post__creating_a_element__mentor_and_mentee_can_be_same_person(self): utc_now = timezone.now() model = self.bc.database.create(user=1, @@ -1260,7 +1260,7 @@ def test__post__creating_a_element__mentor_and_mentee_can_be_same_person(self): 🔽🔽🔽 POST creating a element, passing all the fields """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) def test__post__creating_a_element__passing_all_the_fields(self): utc_now = timezone.now() consumable = {'user_id': 2} @@ -1380,7 +1380,7 @@ def test__put__without_capabilities(self): 🔽🔽🔽 PUT without id """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__without_id(self): model = self.bc.database.create(user=1, role=1, capability='crud_mentorship_session', profile_academy=1) @@ -1403,7 +1403,7 @@ def test__put__without_id(self): 🔽🔽🔽 PUT not found the MentorshipSession """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__not_found(self): cases = [ (1, {}, False), @@ -1442,7 +1442,7 @@ def test__put__not_found(self): 🔽🔽🔽 PUT found a MentorshipSession, with one MentorProfile and MentorshipService """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__without_required_fields(self): model = self.bc.database.create(user=1, role=1, @@ -1469,7 +1469,7 @@ def test__put__found__without_required_fields(self): ]) self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), []) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_required_fields(self): model = self.bc.database.create(user=1, role=1, @@ -1506,7 +1506,7 @@ def test__put__found__with_required_fields(self): 🔽🔽🔽 PUT with all required fields, is_online is False """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_false(self): mentorship_bill = {'status': random.choice(['RECALCULATE', 'DUE'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -1523,7 +1523,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -1592,7 +1592,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, [ + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, [ call(instance=model.mentorship_session, sender=model.mentorship_session.__class__), ]) @@ -1600,7 +1600,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): 🔽🔽🔽 PUT with all required fields, is_online is False, MentorshipBill finished """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_false__bill_finished(self): mentorship_bill = {'status': random.choice(['APPROVED', 'PAID', 'IGNORED'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -1617,7 +1617,7 @@ def test__put__found__with_all_required_fields__is_online_as_false__bill_finishe mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -1662,7 +1662,7 @@ def test__put__found__with_all_required_fields__is_online_as_false__bill_finishe **self.bc.format.to_dict(model.mentorship_session), }, ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, []) + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, []) self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) @@ -1671,7 +1671,7 @@ def test__put__found__with_all_required_fields__is_online_as_false__bill_finishe 🔽🔽🔽 PUT passing a MentorshipBill with some MentorshipSession without MentorshipService """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__passing_a_bill_with_some_session_without_service(self): mentorship_bill = {'status': 'DUE'} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -1696,7 +1696,7 @@ def test__put__found__passing_a_bill_with_some_session_without_service(self): mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -1765,6 +1765,6 @@ def test__put__found__passing_a_bill_with_some_session_without_service(self): 'status': 'RECALCULATE', }, ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, [ + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, [ call(instance=model.mentorship_session[0], sender=model.mentorship_session[0].__class__), ]) diff --git a/breathecode/mentorship/tests/urls/tests_academy_session_id.py b/breathecode/mentorship/tests/urls/tests_academy_session_id.py index 1db221101..edb5f3b8a 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_session_id.py +++ b/breathecode/mentorship/tests/urls/tests_academy_session_id.py @@ -238,7 +238,7 @@ def test__put__without_capabilities(self): 🔽🔽🔽 PUT not found the MentorshipSession """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__not_found(self): cases = [ (1, {}, False), @@ -276,7 +276,7 @@ def test__put__not_found(self): 🔽🔽🔽 PUT found a MentorshipSession, with one MentorProfile and MentorshipService """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__without_required_fields(self): model = self.bc.database.create(user=1, role=1, @@ -302,7 +302,7 @@ def test__put__found__without_required_fields(self): ]) self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), []) - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_required_fields(self): model = self.bc.database.create(user=1, role=1, @@ -338,7 +338,7 @@ def test__put__found__with_required_fields(self): 🔽🔽🔽 PUT with all required fields, is_online is False """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_false(self): mentorship_bill = {'status': random.choice(['RECALCULATE', 'DUE'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -355,7 +355,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -422,7 +422,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, [ + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, [ call(instance=model.mentorship_session, sender=model.mentorship_session.__class__), ]) @@ -430,7 +430,7 @@ def test__put__found__with_all_required_fields__is_online_as_false(self): 🔽🔽🔽 PUT with all required fields, is_online is False, MentorshipBill finished """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_false__bill_finished(self): mentorship_bill = {'status': random.choice(['APPROVED', 'PAID', 'IGNORED'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -447,7 +447,7 @@ def test__put__found__with_all_required_fields__is_online_as_false__bill_finishe mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -494,13 +494,13 @@ def test__put__found__with_all_required_fields__is_online_as_false__bill_finishe self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(str(signals.mentorship_session_status.send.call_args_list), str([])) + self.assertEqual(str(signals.mentorship_session_status.send_robust.call_args_list), str([])) """ 🔽🔽🔽 PUT with all required fields, is_online is True, trying to edit readonly fields """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_true__trying_to_edit_readonly_fields(self): statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -513,7 +513,7 @@ def test__put__found__with_all_required_fields__is_online_as_true__trying_to_edi mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -573,13 +573,13 @@ def test__put__found__with_all_required_fields__is_online_as_true__trying_to_edi self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(str(signals.mentorship_session_status.send.call_args_list), str([])) + self.assertEqual(str(signals.mentorship_session_status.send_robust.call_args_list), str([])) """ 🔽🔽🔽 PUT with all required fields, is_online is True """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_true(self): mentorship_bill = {'status': random.choice(['RECALCULATE', 'DUE'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -596,7 +596,7 @@ def test__put__found__with_all_required_fields__is_online_as_true(self): mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -655,7 +655,7 @@ def test__put__found__with_all_required_fields__is_online_as_true(self): self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, [ + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, [ call(instance=model.mentorship_session, sender=model.mentorship_session.__class__), ]) @@ -663,7 +663,7 @@ def test__put__found__with_all_required_fields__is_online_as_true(self): 🔽🔽🔽 PUT with all required fields, is_online is True, MentorshipBill finished """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) def test__put__found__with_all_required_fields__is_online_as_true__bill_finished(self): mentorship_bill = {'status': random.choice(['APPROVED', 'PAID', 'IGNORED'])} statuses = ['PENDING', 'STARTED', 'COMPLETED', 'FAILED', 'IGNORED'] @@ -677,7 +677,7 @@ def test__put__found__with_all_required_fields__is_online_as_true__bill_finished mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -724,14 +724,14 @@ def test__put__found__with_all_required_fields__is_online_as_true__bill_finished self.assertEqual(self.bc.database.list_of('mentorship.MentorshipBill'), [ self.bc.format.to_dict(model.mentorship_bill), ]) - self.assertEqual(str(signals.mentorship_session_status.send.call_args_list), str([])) + self.assertEqual(str(signals.mentorship_session_status.send_robust.call_args_list), str([])) """ 🔽🔽🔽 PUT passing a MentorshipBill with some MentorshipSession without MentorshipService """ - @patch('breathecode.mentorship.signals.mentorship_session_status.send', MagicMock()) - # @patch('breathecode.mentorship.signals.mentorship_session_status.send', + @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', MagicMock()) + # @patch('breathecode.mentorship.signals.mentorship_session_status.send_robust', # MagicMock(side_effect=[None, None, Exception('error')])) def test__put__found__passing_a_bill_with_some_session_without_service(self): mentorship_bill = {'status': 'DUE'} @@ -757,7 +757,7 @@ def test__put__found__passing_a_bill_with_some_session_without_service(self): mentor_profile=1, profile_academy=1) - signals.mentorship_session_status.send.call_args_list = [] + signals.mentorship_session_status.send_robust.call_args_list = [] self.bc.request.set_headers(academy=1) self.client.force_authenticate(model.user) @@ -826,6 +826,6 @@ def test__put__found__passing_a_bill_with_some_session_without_service(self): }, ]) - self.assertEqual(signals.mentorship_session_status.send.call_args_list, [ + self.assertEqual(signals.mentorship_session_status.send_robust.call_args_list, [ call(instance=model.mentorship_session[0], sender=model.mentorship_session[0].__class__), ]) diff --git a/breathecode/monitoring/admin.py b/breathecode/monitoring/admin.py index 1bd1150ad..c717d9f58 100644 --- a/breathecode/monitoring/admin.py +++ b/breathecode/monitoring/admin.py @@ -260,7 +260,7 @@ def current_status(self, obj): def process_webhook(modeladmin, request, queryset): # stay this here for use the poor mocking system for hook in queryset.all(): - github_webhook.send(instance=hook, sender=RepositoryWebhook) + github_webhook.send_robust(instance=hook, sender=RepositoryWebhook) @admin.register(RepositoryWebhook) diff --git a/breathecode/monitoring/tests/scripts/tests_check_cohort_user_status_ended_cohort.py b/breathecode/monitoring/tests/scripts/tests_check_cohort_user_status_ended_cohort.py index 30897338c..3d2bcd8d9 100644 --- a/breathecode/monitoring/tests/scripts/tests_check_cohort_user_status_ended_cohort.py +++ b/breathecode/monitoring/tests/scripts/tests_check_cohort_user_status_ended_cohort.py @@ -1,13 +1,14 @@ -from unittest.mock import patch -from unittest.mock import MagicMock, call +from unittest.mock import MagicMock, call, patch + +from breathecode.monitoring.actions import run_script from breathecode.tests.mocks import ( GOOGLE_CLOUD_PATH, - apply_google_cloud_client_mock, - apply_google_cloud_bucket_mock, apply_google_cloud_blob_mock, + apply_google_cloud_bucket_mock, + apply_google_cloud_client_mock, ) + from ..mixins import MonitoringTestCase -from breathecode.monitoring.actions import run_script class AcademyCohortTestSuite(MonitoringTestCase): @@ -15,7 +16,7 @@ class AcademyCohortTestSuite(MonitoringTestCase): 🔽🔽🔽 Bad educational status """ - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @@ -47,7 +48,7 @@ def tests_check_user_status__postponed_ended_cohort(self): **self.model_to_dict(model, 'monitor_script'), }]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @@ -79,7 +80,7 @@ def tests_check_user_status__suspended_ended_cohort(self): **self.model_to_dict(model, 'monitor_script'), }]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) @@ -111,7 +112,7 @@ def tests_check_user_status__graduated_ended_cohort(self): **self.model_to_dict(model, 'monitor_script'), }]) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch(GOOGLE_CLOUD_PATH['client'], apply_google_cloud_client_mock()) @patch(GOOGLE_CLOUD_PATH['bucket'], apply_google_cloud_bucket_mock()) @patch(GOOGLE_CLOUD_PATH['blob'], apply_google_cloud_blob_mock()) diff --git a/breathecode/monitoring/tests/urls/tests_stripe_webhook.py b/breathecode/monitoring/tests/urls/tests_stripe_webhook.py index 3f6b7426e..7fe237504 100644 --- a/breathecode/monitoring/tests/urls/tests_stripe_webhook.py +++ b/breathecode/monitoring/tests/urls/tests_stripe_webhook.py @@ -1,13 +1,15 @@ -from unittest.mock import patch, MagicMock, call +from unittest.mock import MagicMock, call, patch + from django.http.request import HttpRequest from django.urls import reverse_lazy +from rest_framework import status + +from breathecode.monitoring import signals -from ..mixins import MonitoringTestCase # that 'import as' is thanks pytest think 'test_endpoint' is one fixture from ...admin import test_endpoint as check_endpoint from ...models import Endpoint -from rest_framework import status -from breathecode.monitoring import signals +from ..mixins import MonitoringTestCase CURRENT_MOCK = MagicMock() CURRENT_PATH = 'breathecode.monitoring.tasks.test_endpoint' @@ -20,7 +22,7 @@ class AcademyCohortTestSuite(MonitoringTestCase): # When: no signature # Then: return 403 - @patch('breathecode.monitoring.signals.stripe_webhook.send', MagicMock(return_value=None)) + @patch('breathecode.monitoring.signals.stripe_webhook.send_robust', MagicMock(return_value=None)) def tests_no_signature(self): # model = self.bc.database.create() @@ -36,7 +38,7 @@ def tests_no_signature(self): # When: invalid payload # Then: return 400 - @patch('breathecode.monitoring.signals.stripe_webhook.send', MagicMock(return_value=None)) + @patch('breathecode.monitoring.signals.stripe_webhook.send_robust', MagicMock(return_value=None)) @patch('stripe.Webhook.construct_event', MagicMock(side_effect=ValueError('x'))) def tests_invalid_payload(self): url = reverse_lazy('monitoring:stripe_webhook') @@ -52,7 +54,7 @@ def tests_invalid_payload(self): # When: invalid payload, inside action # Then: return 400 - @patch('breathecode.monitoring.signals.stripe_webhook.send', MagicMock(return_value=None)) + @patch('breathecode.monitoring.signals.stripe_webhook.send_robust', MagicMock(return_value=None)) @patch('stripe.Webhook.construct_event', MagicMock(return_value={})) def tests_invalid_payload__inside_action(self): url = reverse_lazy('monitoring:stripe_webhook') @@ -68,7 +70,7 @@ def tests_invalid_payload__inside_action(self): # When: success # Then: return 200 - @patch('breathecode.monitoring.signals.stripe_webhook.send', MagicMock(return_value=None)) + @patch('breathecode.monitoring.signals.stripe_webhook.send_robust', MagicMock(return_value=None)) def tests_success(self): url = reverse_lazy('monitoring:stripe_webhook') self.bc.request.set_headers(stripe_signature='123') @@ -106,6 +108,6 @@ def tests_success(self): StripeEvent = self.bc.database.get_model('monitoring.StripeEvent') event = StripeEvent.objects.filter(id=1).first() - self.bc.check.calls(signals.stripe_webhook.send.call_args_list, [ + self.bc.check.calls(signals.stripe_webhook.send_robust.call_args_list, [ call(event=event, sender=event.__class__), ]) diff --git a/breathecode/monitoring/views.py b/breathecode/monitoring/views.py index 0af0a4910..1e73e45e5 100644 --- a/breathecode/monitoring/views.py +++ b/breathecode/monitoring/views.py @@ -2,10 +2,10 @@ import os import stripe -from django.utils import timezone from circuitbreaker import CircuitBreakerError from django.db.models import Q from django.http import StreamingHttpResponse +from django.utils import timezone from rest_framework import status from rest_framework.decorators import api_view, permission_classes from rest_framework.permissions import AllowAny @@ -154,7 +154,7 @@ def process_github_webhook(request, subscription_token): webhook = add_github_webhook(payload, academy_slug) if webhook: logger.debug('triggering signal github_webhook: ' + payload['scope']) - github_webhook.send(instance=webhook, sender=RepositoryWebhook) + github_webhook.send_robust(instance=webhook, sender=RepositoryWebhook) return Response(payload, status=status.HTTP_200_OK) else: logger.debug(f'Error at processing github webhook from academy {academy_slug}') @@ -182,7 +182,7 @@ def process_stripe_webhook(request): raise ValidationException('Not allowed', code=403, slug='not-allowed') if event := add_stripe_webhook(event): - signals.stripe_webhook.send(event=event, sender=event.__class__) + signals.stripe_webhook.send_robust(event=event, sender=event.__class__) return Response({'success': True}) diff --git a/breathecode/payments/admin.py b/breathecode/payments/admin.py index 45631bdb4..b4f7296ff 100644 --- a/breathecode/payments/admin.py +++ b/breathecode/payments/admin.py @@ -107,7 +107,7 @@ class PlanTranslationAdmin(admin.ModelAdmin): def grant_service_permissions(modeladmin, request, queryset): for item in queryset.all(): - signals.grant_service_permissions.send(instance=item, sender=item.__class__) + signals.grant_service_permissions.send_robust(instance=item, sender=item.__class__) @admin.register(Consumable) diff --git a/breathecode/payments/models.py b/breathecode/payments/models.py index cb754ff3d..85461d95d 100644 --- a/breathecode/payments/models.py +++ b/breathecode/payments/models.py @@ -1093,7 +1093,7 @@ def save(self, *args, **kwargs) -> None: super().save(*args, **kwargs) if on_create: - signals.planfinancing_created.send(instance=self, sender=self.__class__) + signals.planfinancing_created.send_robust(instance=self, sender=self.__class__) class Subscription(AbstractIOweYou): @@ -1151,7 +1151,7 @@ def save(self, *args, **kwargs) -> None: super().save(*args, **kwargs) if on_create: - signals.subscription_created.send(instance=self, sender=self.__class__) + signals.subscription_created.send_robust(instance=self, sender=self.__class__) class SubscriptionServiceItem(models.Model): @@ -1329,7 +1329,7 @@ def save(self, *args, **kwargs): created = not self.id if created and self.how_many != 0: - signals.grant_service_permissions.send(instance=self, sender=self.__class__) + signals.grant_service_permissions.send_robust(instance=self, sender=self.__class__) super().save(*args, **kwargs) diff --git a/breathecode/payments/receivers.py b/breathecode/payments/receivers.py index f8bd92549..82906a4d2 100644 --- a/breathecode/payments/receivers.py +++ b/breathecode/payments/receivers.py @@ -25,7 +25,7 @@ @receiver(consume_service, sender=Consumable) def consume_service_receiver(sender: Type[Consumable], instance: Consumable, how_many: float, **kwargs): if instance.how_many == 0: - lose_service_permissions.send(instance=instance, sender=sender) + lose_service_permissions.send_robust(instance=instance, sender=sender) return if instance.how_many == -1: @@ -35,7 +35,7 @@ def consume_service_receiver(sender: Type[Consumable], instance: Consumable, how instance.save() if instance.how_many == 0: - lose_service_permissions.send(instance=instance, sender=sender) + lose_service_permissions.send_robust(instance=instance, sender=sender) @receiver(reimburse_service_units, sender=Consumable) @@ -49,7 +49,7 @@ def reimburse_service_units_receiver(sender: Type[Consumable], instance: Consuma instance.save() if grant_permissions: - grant_service_permissions.send(instance=instance, sender=sender) + grant_service_permissions.send_robust(instance=instance, sender=sender) @receiver(lose_service_permissions, sender=Consumable) @@ -90,7 +90,7 @@ def plan_m2m_wrapper(sender: Type[Plan.service_items.through], instance: Plan, * if kwargs['action'] != 'post_add': return - update_plan_m2m_service_items.send(sender=sender, instance=instance) + update_plan_m2m_service_items.send_robust(sender=sender, instance=instance) @receiver(update_plan_m2m_service_items, sender=Plan.service_items.through) diff --git a/breathecode/payments/tasks.py b/breathecode/payments/tasks.py index a17222a17..642e5f1f2 100644 --- a/breathecode/payments/tasks.py +++ b/breathecode/payments/tasks.py @@ -838,7 +838,7 @@ def end_the_consumption_session(self, consumption_session_id: int, how_many: flo raise AbortTask(f'ConsumptionSession with id {consumption_session_id} already processed') consumable = session.consumable - consume_service.send(instance=consumable, sender=consumable.__class__, how_many=how_many) + consume_service.send_robust(instance=consumable, sender=consumable.__class__, how_many=how_many) session.was_discounted = True session.status = 'DONE' @@ -914,7 +914,7 @@ def refund_mentoring_session(session_id: int, **_: Any): how_many = consumption_session.how_many consumable = consumption_session.consumable - reimburse_service_units.send(instance=consumable, sender=consumable.__class__, how_many=how_many) + reimburse_service_units.send_robust(instance=consumable, sender=consumable.__class__, how_many=how_many) consumption_session.status = 'CANCELLED' consumption_session.save() diff --git a/breathecode/payments/tests/signals/tests_consume_service.py b/breathecode/payments/tests/signals/tests_consume_service.py index 8377f48e5..d07aaac89 100644 --- a/breathecode/payments/tests/signals/tests_consume_service.py +++ b/breathecode/payments/tests/signals/tests_consume_service.py @@ -7,7 +7,7 @@ class TestSignal(LegacyAPITestCase): - @patch('breathecode.payments.signals.lose_service_permissions.send', MagicMock()) + @patch('breathecode.payments.signals.lose_service_permissions.send_robust', MagicMock()) def test__consumable_how_many_minus_1__consume_gte_1(self, enable_signals): enable_signals() @@ -27,9 +27,9 @@ def test__consumable_how_many_minus_1__consume_gte_1(self, enable_signals): 'how_many': how_many, }, ]) - self.assertEqual(signals.lose_service_permissions.send.call_args_list, []) + self.assertEqual(signals.lose_service_permissions.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.lose_service_permissions.send', MagicMock()) + @patch('breathecode.payments.signals.lose_service_permissions.send_robust', MagicMock()) def test__consumable_how_many_0__consume_gte_1(self, enable_signals): enable_signals() @@ -49,11 +49,11 @@ def test__consumable_how_many_0__consume_gte_1(self, enable_signals): 'how_many': how_many, }, ]) - self.assertEqual(signals.lose_service_permissions.send.call_args_list, [ + self.assertEqual(signals.lose_service_permissions.send_robust.call_args_list, [ call(sender=model.consumable.__class__, instance=model.consumable), ]) - @patch('breathecode.payments.signals.lose_service_permissions.send', MagicMock()) + @patch('breathecode.payments.signals.lose_service_permissions.send_robust', MagicMock()) def test__consumable_how_many_gte_1__consume_gte_1(self, enable_signals): enable_signals() @@ -73,4 +73,4 @@ def test__consumable_how_many_gte_1__consume_gte_1(self, enable_signals): 'how_many': how_many, }, ]) - self.assertEqual(signals.lose_service_permissions.send.call_args_list, []) + self.assertEqual(signals.lose_service_permissions.send_robust.call_args_list, []) diff --git a/breathecode/payments/views.py b/breathecode/payments/views.py index 73ce713f4..9c4f2ac34 100644 --- a/breathecode/payments/views.py +++ b/breathecode/payments/views.py @@ -1081,7 +1081,7 @@ def put(self, request, service_slug, hash=None): how_many = session.how_many consumable = session.consumable - reimburse_service_units.send(instance=consumable, sender=consumable.__class__, how_many=how_many) + reimburse_service_units.send_robust(instance=consumable, sender=consumable.__class__, how_many=how_many) return Response({'status': 'reversed'}, status=status.HTTP_200_OK) diff --git a/breathecode/provisioning/tests/tasks/tests_upload.py b/breathecode/provisioning/tests/tasks/tests_upload.py index af05b61ab..4fb903329 100644 --- a/breathecode/provisioning/tests/tasks/tests_upload.py +++ b/breathecode/provisioning/tests/tasks/tests_upload.py @@ -930,7 +930,7 @@ def test_users_not_found__case2(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything(self): csv = codespaces_csv(10) @@ -1036,7 +1036,7 @@ def test_from_github_credentials__generate_anything(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) @patch('breathecode.provisioning.tasks.PANDAS_ROWS_LIMIT', PropertyMock(return_value=3)) def test_pagination(self): @@ -1156,7 +1156,7 @@ def test_pagination(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything__force(self): csv = codespaces_csv(10) @@ -1265,7 +1265,7 @@ def test_from_github_credentials__generate_anything__force(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything__case1(self): csv = codespaces_csv(10) @@ -1474,7 +1474,7 @@ def test_users_not_found(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__vendor_not_found(self): csv = gitpod_csv(10) @@ -1571,7 +1571,7 @@ def test_from_github_credentials__vendor_not_found(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything(self): csv = gitpod_csv(10) @@ -1675,7 +1675,7 @@ def test_from_github_credentials__generate_anything(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) @patch('breathecode.provisioning.tasks.PANDAS_ROWS_LIMIT', PropertyMock(return_value=3)) def test_pagination(self): @@ -1793,7 +1793,7 @@ def test_pagination(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything__case1(self): csv = gitpod_csv(10) @@ -1913,9 +1913,9 @@ def test_from_github_credentials__generate_anything__case1(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.authenticate.signals.academy_invite_accepted.send', MagicMock()) + @patch('breathecode.authenticate.signals.academy_invite_accepted.send_robust', MagicMock()) def test_from_github_credentials__generate_anything__case2(self): csv = gitpod_csv(10) @@ -2051,9 +2051,9 @@ def test_from_github_credentials__generate_anything__case2(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.authenticate.signals.academy_invite_accepted.send', MagicMock()) + @patch('breathecode.authenticate.signals.academy_invite_accepted.send_robust', MagicMock()) def test_from_github_credentials__generate_anything__case3(self): csv = gitpod_csv(10) @@ -2311,7 +2311,7 @@ def test_users_not_found(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__vendor_not_found(self): csv = rigobot_csv(10) @@ -2424,7 +2424,7 @@ def test_from_github_credentials__vendor_not_found(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything(self): csv = rigobot_csv(10) @@ -2546,7 +2546,7 @@ def test_from_github_credentials__generate_anything(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) @patch('breathecode.provisioning.tasks.PANDAS_ROWS_LIMIT', PropertyMock(return_value=3)) def test_pagination(self): @@ -2682,7 +2682,7 @@ def test_pagination(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) def test_from_github_credentials__generate_anything__case1(self): csv = rigobot_csv(10) @@ -2811,9 +2811,9 @@ def test_from_github_credentials__generate_anything__case1(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.authenticate.signals.academy_invite_accepted.send', MagicMock()) + @patch('breathecode.authenticate.signals.academy_invite_accepted.send_robust', MagicMock()) def test_from_github_credentials__generate_anything__case2(self): csv = rigobot_csv(10) @@ -2958,9 +2958,9 @@ def test_from_github_credentials__generate_anything__case2(self): @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) @patch('logging.Logger.info', MagicMock()) @patch('logging.Logger.error', MagicMock()) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock()) @patch('breathecode.notify.utils.hook_manager.HookManagerClass.process_model_event', MagicMock()) - @patch('breathecode.authenticate.signals.academy_invite_accepted.send', MagicMock()) + @patch('breathecode.authenticate.signals.academy_invite_accepted.send_robust', MagicMock()) def test_from_github_credentials__generate_anything__case3(self): csv = rigobot_csv(10) diff --git a/breathecode/registry/models.py b/breathecode/registry/models.py index bed392e09..236626979 100644 --- a/breathecode/registry/models.py +++ b/breathecode/registry/models.py @@ -1,16 +1,24 @@ -import base64, frontmatter, markdown, pathlib, logging, re, hashlib +import base64 +import hashlib +import logging +import pathlib +import re from urllib.parse import urlparse + +import frontmatter +import markdown +from django.contrib.auth.models import AnonymousUser, User from django.db import models -from django.contrib.auth.models import User -from django.contrib.auth.models import AnonymousUser +from django.db.models import Q from django.template.loader import get_template -from breathecode.admissions.models import Academy, SyllabusVersion from django.utils import timezone -from django.db.models import Q -from .signals import (asset_slug_modified, asset_readme_modified, asset_title_modified, asset_status_updated) from slugify import slugify + +from breathecode.admissions.models import Academy, SyllabusVersion from breathecode.assessment.models import Assessment +from .signals import asset_readme_modified, asset_slug_modified, asset_status_updated, asset_title_modified + __all__ = ['AssetTechnology', 'Asset', 'AssetAlias'] logger = logging.getLogger(__name__) @@ -511,11 +519,12 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) self.__old_slug = self.slug self.__old_readme_raw = self.readme_raw + self.__old_status = self.status - if slug_modified: asset_slug_modified.send(instance=self, sender=Asset) - if readme_modified: asset_readme_modified.send(instance=self, sender=Asset) - if title_modified: asset_title_modified.send(instance=self, sender=Asset) - if status_modified: asset_status_updated.send(instance=self, sender=Asset) + if slug_modified: asset_slug_modified.send_robust(instance=self, sender=Asset) + if readme_modified: asset_readme_modified.send_robust(instance=self, sender=Asset) + if title_modified: asset_title_modified.send_robust(instance=self, sender=Asset) + if status_modified: asset_status_updated.send_robust(instance=self, sender=Asset) def get_preview_generation_url(self): diff --git a/breathecode/registry/tests/urls/v1/tests_academy_asset.py b/breathecode/registry/tests/urls/v1/tests_academy_asset.py index 5bef0b4e8..d57ccd14a 100644 --- a/breathecode/registry/tests/urls/v1/tests_academy_asset.py +++ b/breathecode/registry/tests/urls/v1/tests_academy_asset.py @@ -190,7 +190,7 @@ def put_serializer(academy, category, asset, data={}): @pytest.fixture(autouse=True) def setup(db, monkeypatch): - monkeypatch.setattr('breathecode.registry.signals.asset_slug_modified.send', MagicMock()) + monkeypatch.setattr('breathecode.registry.signals.asset_slug_modified.send_robust', MagicMock()) yield diff --git a/breathecode/registry/tests/urls/v2/tests_academy_asset_slug.py b/breathecode/registry/tests/urls/v2/tests_academy_asset_slug.py index f6d93c5fd..288304522 100644 --- a/breathecode/registry/tests/urls/v2/tests_academy_asset_slug.py +++ b/breathecode/registry/tests/urls/v2/tests_academy_asset_slug.py @@ -74,7 +74,7 @@ def get_serializer(bc: Breathecode, asset, asset_category=None, data={}): @pytest.fixture(autouse=True) def setup(db, monkeypatch): - monkeypatch.setattr('breathecode.registry.signals.asset_slug_modified.send', MagicMock()) + monkeypatch.setattr('breathecode.registry.signals.asset_slug_modified.send_robust', MagicMock()) yield diff --git a/breathecode/services/slack/tests/commands/tests_cohort.py b/breathecode/services/slack/tests/commands/tests_cohort.py index 78dab9360..bc8f4f886 100644 --- a/breathecode/services/slack/tests/commands/tests_cohort.py +++ b/breathecode/services/slack/tests/commands/tests_cohort.py @@ -1,16 +1,20 @@ -import re, urllib +import re +import urllib from unittest.mock import MagicMock, patch + from rest_framework import status -from ..mixins import SlackTestCase + import breathecode.services.slack.commands as commands -from ...exceptions import SlackException + from ...commands.cohort import execute +from ...exceptions import SlackException +from ..mixins import SlackTestCase class SlackTestSuite(SlackTestCase): - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___context_is_not_provided_or_is_none(self): """Testing when context is None or not provided.""" @@ -20,8 +24,8 @@ def test_slack_command___context_is_not_provided_or_is_none(self): with self.assertRaisesMessage(SlackException, 'context-missing'): result = execute(users=[], context=None) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_is_not_authorized(self): """Testing when user is not authorized.""" @@ -30,8 +34,8 @@ def test_slack_command___user_is_not_authorized(self): with self.assertRaisesMessage(SlackException, 'unauthorized-user'): result = execute(users=[], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___cohort_does_not_exist(self): """Testing when cohort does not exist.""" @@ -51,8 +55,8 @@ def test_slack_command___cohort_does_not_exist(self): with self.assertRaisesMessage(SlackException, 'cohort-not-found'): result = execute(users=[], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___cohort_does_exist_but_not_associated_with_slack_channel(self): """Testing when cohort does exist but not associated with slack channel.""" @@ -71,8 +75,8 @@ def test_slack_command___cohort_does_exist_but_not_associated_with_slack_channel with self.assertRaisesMessage(SlackException, 'cohort-not-found'): result = execute(users=['fdd2325'], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___cohort_does_exist_and_associated_with_slack_channel(self): """Testing when cohort exists and is associated with slack channel""" @@ -117,8 +121,8 @@ def test_slack_command___cohort_does_exist_and_associated_with_slack_channel(sel self.assertEqual(result, expected) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___cohort_does_exist_and_role_is_teacher(self): """Testing when cohort exists and role is teacher""" diff --git a/breathecode/services/slack/tests/commands/tests_student.py b/breathecode/services/slack/tests/commands/tests_student.py index de5745f5c..16b56eed7 100644 --- a/breathecode/services/slack/tests/commands/tests_student.py +++ b/breathecode/services/slack/tests/commands/tests_student.py @@ -2,9 +2,10 @@ from unittest.mock import MagicMock, call, patch from breathecode.tests.mixins.breathecode_mixin.breathecode import fake -from ..mixins import SlackTestCase -from ...exceptions import SlackException + from ...commands.student import execute +from ...exceptions import SlackException +from ..mixins import SlackTestCase API_URL = fake.url()[0:-1] @@ -36,8 +37,8 @@ def get_env(key, value=None): class SlackTestSuite(SlackTestCase): - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___context_is_not_provide_or_is_none(self): """Testing .""" @@ -47,8 +48,8 @@ def test_slack_command___context_is_not_provide_or_is_none(self): with self.assertRaisesMessage(SlackException, 'context-missing'): result = execute(users=[], context=None) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_is_not_authorized(self): """Testing .""" @@ -57,8 +58,8 @@ def test_slack_command___user_is_not_authorized(self): with self.assertRaisesMessage(SlackException, 'unauthorized-user'): result = execute(users=[], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___users_is_an_empty_list(self): """Testing when passing and empty list to users.""" @@ -78,8 +79,8 @@ def test_slack_command___users_is_an_empty_list(self): with self.assertRaisesMessage(SlackException, 'users-not-provided'): result = execute(users=[], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_not_registered_in_a_cohort(self): """Testing when user is not registered in a cohort.""" @@ -98,8 +99,8 @@ def test_slack_command___user_not_registered_in_a_cohort(self): with self.assertRaisesMessage(SlackException, 'cohort-user-not-found'): result = execute(users=['fdd2325'], context=data) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_registered_in_a_cohort__without_financial_status_or_educational_status(self): """Testing when user is registered in a cohort.""" @@ -147,8 +148,8 @@ def test_slack_command___user_registered_in_a_cohort__without_financial_status_o self.assertEqual(result, expected) self.assertEqual(self.bc.database.list_of('authenticate.Profile'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_registered_in_two_cohorts__with_financial_status_and_educational_status(self): """Testing when user is registered in a cohort.""" @@ -208,8 +209,8 @@ def test_slack_command___user_registered_in_two_cohorts__with_financial_status_a self.assertEqual(result, expected) self.assertEqual(self.bc.database.list_of('authenticate.Profile'), []) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___user_registered_in_two_different_cohorts__with_financial_status_and_educational_status( self): """Testing when user is registered in two different cohorts with financial and educational status.""" @@ -276,8 +277,8 @@ def test_slack_command___user_registered_in_two_different_cohorts__with_financia """ @patch('os.getenv', MagicMock(side_effect=apply_get_env({'API_URL': API_URL}))) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___with_profile_empty(self): """Testing when user is registered in two different cohorts with financial and educational status.""" @@ -351,8 +352,8 @@ def test_slack_command___with_profile_empty(self): """ @patch('os.getenv', MagicMock(side_effect=apply_get_env({'API_URL': API_URL}))) - @patch('django.db.models.signals.pre_delete.send', MagicMock(return_value=None)) - @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock(return_value=None)) + @patch('django.db.models.signals.pre_delete.send_robust', MagicMock(return_value=None)) + @patch('breathecode.admissions.signals.student_edu_status_updated.send_robust', MagicMock(return_value=None)) def test_slack_command___with_profile_set(self): """Testing when user is registered in two different cohorts with financial and educational status.""" diff --git a/breathecode/utils/decorators/has_permission.py b/breathecode/utils/decorators/has_permission.py index 6d46106a2..da9f27acf 100644 --- a/breathecode/utils/decorators/has_permission.py +++ b/breathecode/utils/decorators/has_permission.py @@ -168,7 +168,7 @@ def build_context(**opts): elif it_will_consume: item = context['consumables'].first() - consume_service.send(instance=item, sender=item.__class__, how_many=1) + consume_service.send_robust(instance=item, sender=item.__class__, how_many=1) return response diff --git a/breathecode/utils/tests/decorators/tests_has_permission.py b/breathecode/utils/tests/decorators/tests_has_permission.py index ac9b559d5..a2e7438b3 100644 --- a/breathecode/utils/tests/decorators/tests_has_permission.py +++ b/breathecode/utils/tests/decorators/tests_has_permission.py @@ -315,7 +315,7 @@ def tearDown(self) -> None: 🔽🔽🔽 Function get """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) @patch('breathecode.payments.models.ConsumptionSession.build_session', @@ -335,9 +335,9 @@ def test__function__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user(self): @@ -358,9 +358,9 @@ def test__function__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_permission__dont_match(self): @@ -381,9 +381,9 @@ def test__function__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_permission(self): @@ -405,9 +405,9 @@ def test__function__get__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission(self): @@ -431,13 +431,13 @@ def test__function__get__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function get id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__anonymous_user(self): @@ -455,9 +455,9 @@ def test__function__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user(self): @@ -478,9 +478,9 @@ def test__function__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_permission__dont_match(self): @@ -501,9 +501,9 @@ def test__function__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_permission(self): @@ -525,9 +525,9 @@ def test__function__get_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission(self): @@ -551,13 +551,13 @@ def test__function__get_id__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function post """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__anonymous_user(self): @@ -575,9 +575,9 @@ def test__function__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user(self): @@ -598,9 +598,9 @@ def test__function__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_permission__dont_match(self): @@ -621,9 +621,9 @@ def test__function__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_permission(self): @@ -645,9 +645,9 @@ def test__function__post__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission(self): @@ -671,13 +671,13 @@ def test__function__post__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function put id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__anonymous_user(self): @@ -695,9 +695,9 @@ def test__function__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user(self): @@ -718,9 +718,9 @@ def test__function__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_permission__dont_match(self): @@ -741,9 +741,9 @@ def test__function__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_permission(self): @@ -765,9 +765,9 @@ def test__function__put_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission(self): @@ -791,13 +791,13 @@ def test__function__put_id__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function delete id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__anonymous_user(self): @@ -815,9 +815,9 @@ def test__function__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user(self): @@ -838,9 +838,9 @@ def test__function__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_permission__dont_match(self): @@ -861,9 +861,9 @@ def test__function__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_permission(self): @@ -885,9 +885,9 @@ def test__function__delete_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission(self): @@ -911,7 +911,7 @@ def test__function__delete_id__with_user__with_group_related_to_permission(self) self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) class ConsumerFunctionBasedViewTestSuite(UtilsTestCase): @@ -924,7 +924,7 @@ def setUp(self): 🔽🔽🔽 Function get """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__anonymous_user(self): @@ -942,9 +942,9 @@ def test__function__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user(self): @@ -965,9 +965,9 @@ def test__function__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_permission__dont_match(self): @@ -988,9 +988,9 @@ def test__function__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__without_consumable(self): @@ -1014,9 +1014,9 @@ def test__function__get__with_user__with_group_related_to_permission__without_co self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -1041,11 +1041,11 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -1070,9 +1070,9 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -1097,11 +1097,11 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -1126,7 +1126,7 @@ def test__function__get__with_user__with_group_related_to_permission__group_was_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -1134,7 +1134,7 @@ def test__function__get__with_user__with_group_related_to_permission__group_was_ 🔽🔽🔽 Function get id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__anonymous_user(self): @@ -1152,9 +1152,9 @@ def test__function__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user(self): @@ -1175,9 +1175,9 @@ def test__function__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_permission__dont_match(self): @@ -1198,9 +1198,9 @@ def test__function__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -1224,9 +1224,9 @@ def test__function__get_id__with_user__with_group_related_to_permission__without self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -1251,11 +1251,11 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -1280,9 +1280,9 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -1307,11 +1307,11 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -1336,7 +1336,7 @@ def test__function__get_id__with_user__with_group_related_to_permission__group_w self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -1344,7 +1344,7 @@ def test__function__get_id__with_user__with_group_related_to_permission__group_w 🔽🔽🔽 Function post """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__anonymous_user(self): @@ -1362,9 +1362,9 @@ def test__function__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user(self): @@ -1385,9 +1385,9 @@ def test__function__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_permission__dont_match(self): @@ -1408,9 +1408,9 @@ def test__function__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__without_consumable(self): @@ -1434,9 +1434,9 @@ def test__function__post__with_user__with_group_related_to_permission__without_c self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -1461,11 +1461,11 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -1490,9 +1490,9 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -1517,11 +1517,11 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -1546,7 +1546,7 @@ def test__function__post__with_user__with_group_related_to_permission__group_was self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -1554,7 +1554,7 @@ def test__function__post__with_user__with_group_related_to_permission__group_was 🔽🔽🔽 Function put id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__anonymous_user(self): @@ -1572,9 +1572,9 @@ def test__function__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user(self): @@ -1595,9 +1595,9 @@ def test__function__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_permission__dont_match(self): @@ -1618,9 +1618,9 @@ def test__function__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -1644,9 +1644,9 @@ def test__function__put_id__with_user__with_group_related_to_permission__without self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -1671,11 +1671,11 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -1700,9 +1700,9 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -1727,11 +1727,11 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -1756,7 +1756,7 @@ def test__function__put_id__with_user__with_group_related_to_permission__group_w self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -1764,7 +1764,7 @@ def test__function__put_id__with_user__with_group_related_to_permission__group_w 🔽🔽🔽 Function delete id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__anonymous_user(self): @@ -1782,9 +1782,9 @@ def test__function__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user(self): @@ -1805,9 +1805,9 @@ def test__function__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_permission__dont_match(self): @@ -1828,9 +1828,9 @@ def test__function__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -1854,9 +1854,9 @@ def test__function__delete_id__with_user__with_group_related_to_permission__with self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -1881,11 +1881,11 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -1910,9 +1910,9 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -1937,11 +1937,11 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -1966,7 +1966,7 @@ def test__function__delete_id__with_user__with_group_related_to_permission__grou self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -1981,7 +1981,7 @@ def setUp(self): 🔽🔽🔽 Function get """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__anonymous_user(self): @@ -1999,9 +1999,9 @@ def test__function__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user(self): @@ -2022,9 +2022,9 @@ def test__function__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_permission__dont_match(self): @@ -2045,9 +2045,9 @@ def test__function__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__without_consumable(self): @@ -2090,9 +2090,9 @@ def test__function__get__with_user__with_group_related_to_permission__without_co self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -2136,11 +2136,11 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -2184,9 +2184,9 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -2230,11 +2230,11 @@ def test__function__get__with_user__with_group_related_to_permission__consumable self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -2278,10 +2278,10 @@ def test__function__get__with_user__with_group_related_to_permission__group_was_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get__with_user__without_consumption_session(self): @@ -2327,12 +2327,12 @@ def test__function__get__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__does_not_match(self): @@ -2385,12 +2385,12 @@ def test__view__get__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -2439,10 +2439,10 @@ def test__view__get__with_user__consumption_session__does_not_match__consumables self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__match(self): @@ -2487,13 +2487,13 @@ def test__view__get__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function get id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__anonymous_user(self): @@ -2511,9 +2511,9 @@ def test__function__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user(self): @@ -2534,9 +2534,9 @@ def test__function__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_permission__dont_match(self): @@ -2557,9 +2557,9 @@ def test__function__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -2602,9 +2602,9 @@ def test__function__get_id__with_user__with_group_related_to_permission__without self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -2648,11 +2648,11 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -2696,9 +2696,9 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -2742,11 +2742,11 @@ def test__function__get_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -2790,10 +2790,10 @@ def test__function__get_id__with_user__with_group_related_to_permission__group_w self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__get_id__with_user__without_consumption_session(self): @@ -2839,12 +2839,12 @@ def test__function__get_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__does_not_match(self): @@ -2897,12 +2897,12 @@ def test__view__get_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -2953,10 +2953,10 @@ def test__view__get_id__with_user__consumption_session__does_not_match__consumab self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__match(self): @@ -3003,13 +3003,13 @@ def test__view__get_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function post """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__anonymous_user(self): @@ -3027,9 +3027,9 @@ def test__function__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user(self): @@ -3050,9 +3050,9 @@ def test__function__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_permission__dont_match(self): @@ -3073,9 +3073,9 @@ def test__function__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__without_consumable(self): @@ -3118,9 +3118,9 @@ def test__function__post__with_user__with_group_related_to_permission__without_c self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -3164,11 +3164,11 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -3212,9 +3212,9 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -3258,11 +3258,11 @@ def test__function__post__with_user__with_group_related_to_permission__consumabl self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -3306,10 +3306,10 @@ def test__function__post__with_user__with_group_related_to_permission__group_was self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__post__with_user__without_consumption_session(self): @@ -3355,12 +3355,12 @@ def test__function__post__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__does_not_match(self): @@ -3413,12 +3413,12 @@ def test__view__post__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -3467,10 +3467,10 @@ def test__view__post__with_user__consumption_session__does_not_match__consumable self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__match(self): @@ -3515,13 +3515,13 @@ def test__view__post__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function put id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__anonymous_user(self): @@ -3539,9 +3539,9 @@ def test__function__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user(self): @@ -3562,9 +3562,9 @@ def test__function__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_permission__dont_match(self): @@ -3585,9 +3585,9 @@ def test__function__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -3630,9 +3630,9 @@ def test__function__put_id__with_user__with_group_related_to_permission__without self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -3676,11 +3676,11 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -3724,9 +3724,9 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -3770,11 +3770,11 @@ def test__function__put_id__with_user__with_group_related_to_permission__consuma self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -3818,10 +3818,10 @@ def test__function__put_id__with_user__with_group_related_to_permission__group_w self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__put_id__with_user__without_consumption_session(self): @@ -3867,12 +3867,12 @@ def test__function__put_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__does_not_match(self): @@ -3925,12 +3925,12 @@ def test__view__put_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -3981,10 +3981,10 @@ def test__view__put_id__with_user__consumption_session__does_not_match__consumab self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__match(self): @@ -4031,13 +4031,13 @@ def test__view__put_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 Function delete id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__anonymous_user(self): @@ -4055,9 +4055,9 @@ def test__function__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user(self): @@ -4078,9 +4078,9 @@ def test__function__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_permission__dont_match(self): @@ -4101,9 +4101,9 @@ def test__function__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__without_consumable(self): @@ -4146,9 +4146,9 @@ def test__function__delete_id__with_user__with_group_related_to_permission__with self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_minus_1(self): @@ -4192,11 +4192,11 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_0(self): @@ -4240,9 +4240,9 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__consumable__how_many_gte_1(self): @@ -4286,11 +4286,11 @@ def test__function__delete_id__with_user__with_group_related_to_permission__cons self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__with_group_related_to_permission__group_was_blacklisted_by_cb(self): @@ -4334,10 +4334,10 @@ def test__function__delete_id__with_user__with_group_related_to_permission__grou self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__function__delete_id__with_user__without_consumption_session(self): @@ -4383,12 +4383,12 @@ def test__function__delete_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__does_not_match(self): @@ -4441,12 +4441,12 @@ def test__view__delete_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -4497,10 +4497,10 @@ def test__view__delete_id__with_user__consumption_session__does_not_match__consu self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__match(self): @@ -4547,7 +4547,7 @@ def test__view__delete_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) class ViewTestSuite(UtilsTestCase): @@ -4560,7 +4560,7 @@ def setUp(self): 🔽🔽🔽 View get """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__anonymous_user(self): @@ -4578,9 +4578,9 @@ def test__view__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user(self): @@ -4601,9 +4601,9 @@ def test__view__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_permission__dont_match(self): @@ -4624,9 +4624,9 @@ def test__view__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_permission(self): @@ -4648,9 +4648,9 @@ def test__view__get__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission(self): @@ -4674,13 +4674,13 @@ def test__view__get__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View get id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__anonymous_user(self): @@ -4698,9 +4698,9 @@ def test__view__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user(self): @@ -4721,9 +4721,9 @@ def test__view__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_permission__dont_match(self): @@ -4744,9 +4744,9 @@ def test__view__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_permission(self): @@ -4768,9 +4768,9 @@ def test__view__get_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission(self): @@ -4794,13 +4794,13 @@ def test__view__get_id__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View post """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__anonymous_user(self): @@ -4818,9 +4818,9 @@ def test__view__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user(self): @@ -4841,9 +4841,9 @@ def test__view__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_permission__dont_match(self): @@ -4864,9 +4864,9 @@ def test__view__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_permission(self): @@ -4888,9 +4888,9 @@ def test__view__post__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission(self): @@ -4914,13 +4914,13 @@ def test__view__post__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View put id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__anonymous_user(self): @@ -4938,9 +4938,9 @@ def test__view__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user(self): @@ -4961,9 +4961,9 @@ def test__view__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_permission__dont_match(self): @@ -4984,9 +4984,9 @@ def test__view__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_permission(self): @@ -5008,9 +5008,9 @@ def test__view__put_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission(self): @@ -5034,13 +5034,13 @@ def test__view__put_id__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View delete id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__anonymous_user(self): @@ -5058,9 +5058,9 @@ def test__view__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user(self): @@ -5081,9 +5081,9 @@ def test__view__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_permission__dont_match(self): @@ -5104,9 +5104,9 @@ def test__view__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_permission(self): @@ -5128,9 +5128,9 @@ def test__view__delete_id__with_user__with_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission(self): @@ -5154,7 +5154,7 @@ def test__view__delete_id__with_user__with_group_related_to_permission(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) class ConsumerViewTestSuite(UtilsTestCase): @@ -5167,7 +5167,7 @@ def setUp(self): 🔽🔽🔽 View get """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__anonymous_user(self): @@ -5185,9 +5185,9 @@ def test__view__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user(self): @@ -5208,9 +5208,9 @@ def test__view__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_permission__dont_match(self): @@ -5231,9 +5231,9 @@ def test__view__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__without_consumer(self): @@ -5257,9 +5257,9 @@ def test__view__get__with_user__with_group_related_to_permission__without_consum self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -5284,11 +5284,11 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -5313,9 +5313,9 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -5340,7 +5340,7 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -5348,7 +5348,7 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ 🔽🔽🔽 View get id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__anonymous_user(self): @@ -5366,9 +5366,9 @@ def test__view__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user(self): @@ -5389,9 +5389,9 @@ def test__view__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_permission__dont_match(self): @@ -5412,9 +5412,9 @@ def test__view__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -5438,9 +5438,9 @@ def test__view__get_id__with_user__with_group_related_to_permission__without_con self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -5465,11 +5465,11 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -5494,9 +5494,9 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -5521,7 +5521,7 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -5529,7 +5529,7 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h 🔽🔽🔽 View post """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__anonymous_user(self): @@ -5547,9 +5547,9 @@ def test__view__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user(self): @@ -5570,9 +5570,9 @@ def test__view__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_permission__dont_match(self): @@ -5593,9 +5593,9 @@ def test__view__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__without_consumer(self): @@ -5619,9 +5619,9 @@ def test__view__post__with_user__with_group_related_to_permission__without_consu self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -5646,11 +5646,11 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -5675,9 +5675,9 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -5702,7 +5702,7 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -5710,7 +5710,7 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how 🔽🔽🔽 View put id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__anonymous_user(self): @@ -5728,9 +5728,9 @@ def test__view__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user(self): @@ -5751,9 +5751,9 @@ def test__view__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_permission__dont_match(self): @@ -5774,9 +5774,9 @@ def test__view__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -5800,9 +5800,9 @@ def test__view__put_id__with_user__with_group_related_to_permission__without_con self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -5827,11 +5827,11 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -5856,9 +5856,9 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -5883,7 +5883,7 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -5891,7 +5891,7 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h 🔽🔽🔽 View delete id """ - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__anonymous_user(self): @@ -5909,9 +5909,9 @@ def test__view__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user(self): @@ -5932,9 +5932,9 @@ def test__view__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_permission__dont_match(self): @@ -5955,9 +5955,9 @@ def test__view__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -5981,9 +5981,9 @@ def test__view__delete_id__with_user__with_group_related_to_permission__without_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -6008,11 +6008,11 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -6037,9 +6037,9 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -6064,7 +6064,7 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @@ -6080,7 +6080,7 @@ def setUp(self): """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__anonymous_user(self): @@ -6099,10 +6099,10 @@ def test__view__get__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user(self): @@ -6124,10 +6124,10 @@ def test__view__get__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_permission__dont_match(self): @@ -6149,10 +6149,10 @@ def test__view__get__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__without_consumer(self): @@ -6196,10 +6196,10 @@ def test__view__get__with_user__with_group_related_to_permission__without_consum self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -6244,12 +6244,12 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -6294,10 +6294,10 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -6342,12 +6342,12 @@ def test__view__get__with_user__with_group_related_to_permission__consumer__how_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__without_consumption_session(self): @@ -6394,12 +6394,12 @@ def test__view__get__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__does_not_match(self): @@ -6453,12 +6453,12 @@ def test__view__get__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -6507,10 +6507,10 @@ def test__view__get__with_user__consumption_session__does_not_match__consumables self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get__with_user__consumption_session__match(self): @@ -6555,14 +6555,14 @@ def test__view__get__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View get id """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__anonymous_user(self): @@ -6581,10 +6581,10 @@ def test__view__get_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user(self): @@ -6606,10 +6606,10 @@ def test__view__get_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_permission__dont_match(self): @@ -6631,10 +6631,10 @@ def test__view__get_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -6678,10 +6678,10 @@ def test__view__get_id__with_user__with_group_related_to_permission__without_con self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -6726,12 +6726,12 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -6776,10 +6776,10 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -6824,12 +6824,12 @@ def test__view__get_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__without_consumption_session(self): @@ -6876,12 +6876,12 @@ def test__view__get_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__does_not_match(self): @@ -6935,12 +6935,12 @@ def test__view__get_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -6991,10 +6991,10 @@ def test__view__get_id__with_user__consumption_session__does_not_match__consumab self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__get_id__with_user__consumption_session__match(self): @@ -7041,14 +7041,14 @@ def test__view__get_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View post """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__anonymous_user(self): @@ -7067,10 +7067,10 @@ def test__view__post__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user(self): @@ -7092,10 +7092,10 @@ def test__view__post__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_permission__dont_match(self): @@ -7117,10 +7117,10 @@ def test__view__post__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__without_consumer(self): @@ -7164,10 +7164,10 @@ def test__view__post__with_user__with_group_related_to_permission__without_consu self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -7212,12 +7212,12 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -7262,10 +7262,10 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -7310,12 +7310,12 @@ def test__view__post__with_user__with_group_related_to_permission__consumer__how self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__without_consumption_session(self): @@ -7362,12 +7362,12 @@ def test__view__post__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__does_not_match(self): @@ -7421,12 +7421,12 @@ def test__view__post__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -7475,10 +7475,10 @@ def test__view__post__with_user__consumption_session__does_not_match__consumable self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__post__with_user__consumption_session__match(self): @@ -7523,14 +7523,14 @@ def test__view__post__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View put id """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__anonymous_user(self): @@ -7549,10 +7549,10 @@ def test__view__put_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user(self): @@ -7574,10 +7574,10 @@ def test__view__put_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_permission__dont_match(self): @@ -7599,10 +7599,10 @@ def test__view__put_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -7646,10 +7646,10 @@ def test__view__put_id__with_user__with_group_related_to_permission__without_con self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -7694,12 +7694,12 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -7744,10 +7744,10 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -7792,12 +7792,12 @@ def test__view__put_id__with_user__with_group_related_to_permission__consumer__h self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__without_consumption_session(self): @@ -7844,12 +7844,12 @@ def test__view__put_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__does_not_match(self): @@ -7903,12 +7903,12 @@ def test__view__put_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -7961,10 +7961,10 @@ def test__view__put_id__with_user__consumption_session__does_not_match__consumab self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__put_id__with_user__consumption_session__match(self): @@ -8011,14 +8011,14 @@ def test__view__put_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) """ 🔽🔽🔽 View delete id """ @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__anonymous_user(self): @@ -8037,10 +8037,10 @@ def test__view__delete_id__anonymous_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user(self): @@ -8062,10 +8062,10 @@ def test__view__delete_id__with_user(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_permission__dont_match(self): @@ -8087,10 +8087,10 @@ def test__view__delete_id__with_user__with_permission__dont_match(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__without_consumer(self): @@ -8134,10 +8134,10 @@ def test__view__delete_id__with_user__with_group_related_to_permission__without_ self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_minus_1(self): @@ -8182,12 +8182,12 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_0(self): @@ -8232,10 +8232,10 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__with_group_related_to_permission__consumer__how_many_1(self): @@ -8280,12 +8280,12 @@ def test__view__delete_id__with_user__with_group_related_to_permission__consumer self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__without_consumption_session(self): @@ -8332,12 +8332,12 @@ def test__view__delete_id__with_user__without_consumption_session(self): self.assertEqual(self.bc.database.list_of('payments.ConsumptionSession'), []) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__does_not_match(self): @@ -8391,12 +8391,12 @@ def test__view__delete_id__with_user__consumption_session__does_not_match(self): self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, [ + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ]) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__does_not_match__consumables_minus_sessions_et_0(self): @@ -8447,10 +8447,10 @@ def test__view__delete_id__with_user__consumption_session__does_not_match__consu self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) @patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - @patch('breathecode.payments.signals.consume_service.send', MagicMock(return_value=UTC_NOW)) + @patch('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=UTC_NOW)) @patch('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) def test__view__delete_id__with_user__consumption_session__match(self): @@ -8497,4 +8497,4 @@ def test__view__delete_id__with_user__consumption_session__match(self): ]) self.assertEqual(models.ConsumptionSession.build_session.call_args_list, []) - self.assertEqual(payments_signals.consume_service.send.call_args_list, []) + self.assertEqual(payments_signals.consume_service.send_robust.call_args_list, []) diff --git a/capyc/django/pytest/fixtures/signals.py b/capyc/django/pytest/fixtures/signals.py index fd1c3b2f1..b192e26bc 100644 --- a/capyc/django/pytest/fixtures/signals.py +++ b/capyc/django/pytest/fixtures/signals.py @@ -4,6 +4,7 @@ # not working yet import importlib from typing import Generator, final +from unittest.mock import MagicMock import pytest @@ -86,9 +87,7 @@ def signals_map(): @final class Signals: - """ - QuerySet utils. - """ + """Signal utils.""" def __init__(self, monkeypatch: pytest.MonkeyPatch, signals_map: dict[str, Signal | ModelSignal]) -> None: self._monkeypatch = monkeypatch @@ -108,12 +107,12 @@ def disable(self): """ # Mock the functions to disable signals - self._monkeypatch.setattr(Signal, 'send', lambda *args, **kwargs: None) - self._monkeypatch.setattr(Signal, 'send_robust', lambda *args, **kwargs: None) + self._monkeypatch.setattr(Signal, 'send', MagicMock(return_value=None)) + self._monkeypatch.setattr(Signal, 'send_robust', MagicMock(return_value=None)) # Mock the functions to disable signals - self._monkeypatch.setattr(ModelSignal, 'send', lambda *args, **kwargs: None) - self._monkeypatch.setattr(ModelSignal, 'send_robust', lambda *args, **kwargs: None) + self._monkeypatch.setattr(ModelSignal, 'send', MagicMock(return_value=None)) + self._monkeypatch.setattr(ModelSignal, 'send_robust', MagicMock(return_value=None)) def enable(self, *to_enable, debug=False): """ @@ -155,7 +154,7 @@ def send_mock(*args, **kwargs): print('\n') - self._monkeypatch.setattr(module, send_mock) + self._monkeypatch.setattr(module, MagicMock(side_effect=send_mock)) apply_mock(f'{signal}.send') apply_mock(f'{signal}.send_robust') @@ -163,9 +162,7 @@ def send_mock(*args, **kwargs): @pytest.fixture def signals(monkeypatch, signals_map: dict[str, Signal | ModelSignal]) -> Generator[Signals, None, None]: - """ - Signals utils. - """ + """Signals utils.""" s = Signals(monkeypatch, signals_map) s.disable() diff --git a/docs/signals/quickstart.md b/docs/signals/quickstart.md index d8747adce..39874cc13 100644 --- a/docs/signals/quickstart.md +++ b/docs/signals/quickstart.md @@ -37,7 +37,7 @@ class CohortSerializer(CohortSerializerMixin): def create(self, validated_data): cohort = Cohort.objects.create(**validated_data, **self.context) - cohort_saved.send(instance=self, sender=CohortUser) + cohort_saved.send_robust(instance=self, sender=CohortUser) return cohort ```