diff --git a/breathecode/events/views.py b/breathecode/events/views.py index ca42c23f4..4924fc433 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -35,7 +35,7 @@ response_207, ) from breathecode.utils.api_view_extensions.api_view_extensions import APIViewExtensions -from breathecode.utils.decorators import consume, has_permission +from breathecode.utils.decorators import consume from breathecode.utils.i18n import translation from breathecode.utils.multi_status_response import MultiStatusResponse from breathecode.utils.views import private_view, render_message diff --git a/breathecode/registry/views.py b/breathecode/registry/views.py index f4ce94453..c0b5d76d4 100644 --- a/breathecode/registry/views.py +++ b/breathecode/registry/views.py @@ -24,7 +24,6 @@ from breathecode.services.seo import SEOAnalyzer from breathecode.utils import GenerateLookupsMixin, capable_of, consume from breathecode.utils.api_view_extensions.api_view_extensions import APIViewExtensions -from breathecode.utils.decorators.has_permission import has_permission from breathecode.utils.i18n import translation from breathecode.utils.views import render_message from capyc.rest_framework.exceptions import ValidationException diff --git a/breathecode/utils/decorators/consume.py b/breathecode/utils/decorators/consume.py index 5f0fb2f64..4429c231d 100644 --- a/breathecode/utils/decorators/consume.py +++ b/breathecode/utils/decorators/consume.py @@ -258,7 +258,7 @@ def wrapper(*args, **kwargs): elif it_will_consume: item = context['consumables'].first() - consume_service.send(instance=item, sender=item.__class__, how_many=context['price']) + consume_service.send_robust(instance=item, sender=item.__class__, how_many=context['price']) return response @@ -369,7 +369,7 @@ async def async_wrapper(*args, **kwargs): elif it_will_consume: item = await context['consumables'].afirst() - consume_service.send(instance=item, sender=item.__class__, how_many=context['price']) + consume_service.send_robust(instance=item, sender=item.__class__, how_many=context['price']) return response diff --git a/breathecode/utils/decorators/has_permission.py b/breathecode/utils/decorators/has_permission.py index d35ead2fe..b5aad7008 100644 --- a/breathecode/utils/decorators/has_permission.py +++ b/breathecode/utils/decorators/has_permission.py @@ -1,7 +1,6 @@ import asyncio import logging import traceback -from contextlib import asynccontextmanager, contextmanager from typing import Any, Optional from adrf.requests import AsyncRequest diff --git a/breathecode/utils/tests/decorators/tests_consume.py b/breathecode/utils/tests/decorators/tests_consume.py index e45e1c8d4..8785881a0 100644 --- a/breathecode/utils/tests/decorators/tests_consume.py +++ b/breathecode/utils/tests/decorators/tests_consume.py @@ -30,7 +30,7 @@ @pytest.fixture(autouse=True) def setup(db, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr('django.utils.timezone.now', MagicMock(return_value=UTC_NOW)) - monkeypatch.setattr('breathecode.payments.signals.consume_service.send', MagicMock(return_value=None)) + monkeypatch.setattr('breathecode.payments.signals.consume_service.send_robust', MagicMock(return_value=None)) monkeypatch.setattr('breathecode.payments.models.ConsumptionSession.build_session', MagicMock(wraps=models.ConsumptionSession.build_session)) @@ -283,7 +283,7 @@ async def test_anonymous_user(self, database: capy.Database, make_view_all_cases @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -304,7 +304,7 @@ async def test_with_user(self, database: capy.Database, make_view_all_cases): @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -325,7 +325,7 @@ async def test_with_user__with_permission__dont_match(self, database: capy.Datab @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -350,7 +350,7 @@ async def test_with_user__with_group_related_to_permission__without_consumable(s @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -379,7 +379,7 @@ async def test_with_user__with_group_related_to_permission__consumable__how_many @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -411,7 +411,7 @@ async def test_with_user__with_group_related_to_permission__consumable__how_many @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -440,7 +440,7 @@ async def test_with_user__with_group_related_to_permission__consumable__how_many @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -472,7 +472,7 @@ async def test_with_user__with_group_related_to_permission__group_was_blackliste @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -497,7 +497,7 @@ async def test__function__get__anonymous_user(self, bc: Breathecode, make_view_c @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -518,7 +518,7 @@ async def test__function__get__with_user(self, bc: Breathecode, make_view_consum @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -540,7 +540,7 @@ async def test__function__get__with_user__with_permission__dont_match(self, bc: @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -590,7 +590,7 @@ async def test__function__get__with_user__with_group_related_to_permission__with @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -646,7 +646,7 @@ async def test__function__get__with_user__with_group_related_to_permission__cons @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -705,7 +705,7 @@ async def test__function__get__with_user__with_group_related_to_permission__cons @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -761,7 +761,7 @@ async def test__function__get__with_user__with_group_related_to_permission__cons @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -821,7 +821,7 @@ async def test__function__get__with_user__with_group_related_to_permission__grou @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -879,7 +879,7 @@ async def test__function__get__with_user__without_consumption_session(self, bc: @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -945,7 +945,7 @@ async def test__with_user__consumption_session__does_not_match(self, bc: Breathe @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [ + assert payments_signals.consume_service.send_robust.call_args_list == [ call(instance=model.consumable, sender=model.consumable.__class__, how_many=1), ] @@ -1001,7 +1001,7 @@ async def test__with_user__consumption_session__does_not_match__consumables_minu @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() @@ -1054,6 +1054,6 @@ async def test__with_user__consumption_session__match(self, bc: Breathecode, mak @sync_to_async def check_consume_service(): - assert payments_signals.consume_service.send.call_args_list == [] + assert payments_signals.consume_service.send_robust.call_args_list == [] await check_consume_service() diff --git a/breathecode/utils/validate_conversion_info.py b/breathecode/utils/validate_conversion_info.py index 42f4f8d98..5ffef7120 100644 --- a/breathecode/utils/validate_conversion_info.py +++ b/breathecode/utils/validate_conversion_info.py @@ -1,5 +1,5 @@ from breathecode.utils.i18n import translation -from capyc.rest_framework.exceptions import PaymentException, ValidationException +from capyc.rest_framework.exceptions import ValidationException __all__ = ['validate_conversion_info']