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,6 +1,14 @@
|
|||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
import re
|
||||
|
||||
def validate_friend_code(value):
|
||||
"""Validate that friend code follows the format XXXX-XXXX-XXXX-XXXX where X is a digit."""
|
||||
if not re.match(r'^\d{4}-\d{4}-\d{4}-\d{4}$', value):
|
||||
raise ValidationError(
|
||||
'Friend code must be in format XXXX-XXXX-XXXX-XXXX where X is a digit.'
|
||||
)
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
default_friend_code = models.ForeignKey("FriendCode", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
|
@ -34,8 +42,8 @@ class CustomUser(AbstractUser):
|
|||
self.save(update_fields=["default_friend_code"])
|
||||
|
||||
class FriendCode(models.Model):
|
||||
friend_code = models.CharField(max_length=19)
|
||||
in_game_name = models.CharField(max_length=16, null=False, blank=False)
|
||||
friend_code = models.CharField(max_length=19, validators=[validate_friend_code])
|
||||
in_game_name = models.CharField(max_length=14, null=False, blank=False)
|
||||
user = models.ForeignKey(CustomUser, on_delete=models.PROTECT, related_name='friend_codes')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue