Fix friend_code max length issues in tests, and fix in_game_name length issues, also update tests to fit more scenarios
This commit is contained in:
parent
0d4655bf80
commit
b9c4d7a61d
10 changed files with 558 additions and 66 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from cards.models import Card
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
class TradeOfferContextMixin:
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
@ -20,4 +21,17 @@ class TradeOfferContextMixin:
|
|||
selected_friend_code = self.request.user.default_friend_code or friend_codes.first()
|
||||
context["selected_friend_code"] = selected_friend_code
|
||||
|
||||
return context
|
||||
return context
|
||||
|
||||
class FriendCodeRequiredMixin:
|
||||
"""
|
||||
Mixin to ensure the authenticated user has at least one friend code.
|
||||
This mixin must be placed after LoginRequiredMixin in the view's inheritance order.
|
||||
"""
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
# Since LoginRequiredMixin guarantees that request.user is authenticated,
|
||||
# we assume request.user has the attribute `friend_codes`. If no friend code exists,
|
||||
# raise a PermissionDenied error.
|
||||
if not getattr(request.user, 'friend_codes', None) or not request.user.friend_codes.exists():
|
||||
raise PermissionDenied("No friend codes available for your account.")
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue