Compare commits
No commits in common. "5ba432e9fdf4768c649df5dc4d615ce577b55ae2" and "9bdd07d59e0274498d9afeef91cf2e4389faa1ec" have entirely different histories.
5ba432e9fd
...
9bdd07d59e
@ -7,8 +7,8 @@ class ProfileTest(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user: User = User.objects.create(username='bozo', password='password')
|
self.user: User = User.objects.create(username='bozo', password='password')
|
||||||
self.user.save()
|
self.user.save()
|
||||||
self.expected_response = {'avatar_url': '/static/avatars/default.avif', 'user_id': 1, 'username': 'bozo'}
|
self.expected_response = {"name": "bozo",
|
||||||
|
"title": ""}
|
||||||
self.url = "/api/profiles/"
|
self.url = "/api/profiles/"
|
||||||
|
|
||||||
def test_profile_create_on_user_created(self):
|
def test_profile_create_on_user_created(self):
|
||||||
|
@ -7,7 +7,6 @@ class TournamentSerializer(serializers.ModelSerializer):
|
|||||||
level = serializers.ReadOnlyField()
|
level = serializers.ReadOnlyField()
|
||||||
started = serializers.ReadOnlyField()
|
started = serializers.ReadOnlyField()
|
||||||
finished = serializers.ReadOnlyField()
|
finished = serializers.ReadOnlyField()
|
||||||
name = serializers.CharField(default="")
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = TournamentModel
|
model = TournamentModel
|
||||||
@ -21,18 +20,3 @@ class TournamentSerializer(serializers.ModelSerializer):
|
|||||||
break
|
break
|
||||||
levels.append(level)
|
levels.append(level)
|
||||||
return levels
|
return levels
|
||||||
|
|
||||||
def validate_nb_players(self, value: int):
|
|
||||||
if (value < 2):
|
|
||||||
raise serializers.ValidationError("The numbers of players must be greather than 2.")
|
|
||||||
return value
|
|
||||||
|
|
||||||
def validate_nb_players_by_game(self, value: int):
|
|
||||||
if (value < 2):
|
|
||||||
raise serializers.ValidationError("The numbers of players by game must be greather than 2.")
|
|
||||||
nb_players: str = self.initial_data.get("nb_players")
|
|
||||||
if (nb_players is not None and nb_players.isnumeric()):
|
|
||||||
nb_players: int = int(nb_players)
|
|
||||||
if (value > nb_players):
|
|
||||||
raise serializers.ValidationError("The numbers of players by game must be smaller than the numbers of players.")
|
|
||||||
return value
|
|
@ -1,44 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
from django.test.client import Client
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
import json
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
class CreateTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url = "/api/tournaments/"
|
|
||||||
|
|
||||||
self.username = str(uuid.uuid4())
|
|
||||||
self.password = str(uuid.uuid4())
|
|
||||||
|
|
||||||
self.nb_players_by_game = 2
|
|
||||||
self.nb_players = 8
|
|
||||||
|
|
||||||
user: User = User.objects.create_user(username=self.username, password=self.password)
|
|
||||||
self.client.login(username=self.username, password=self.password)
|
|
||||||
|
|
||||||
def test_normal(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"nb_players_by_game": self.nb_players_by_game, "nb_players": self.nb_players})
|
|
||||||
response_data: dict = json.loads(response.content)
|
|
||||||
self.assertDictContainsSubset({"name": ""}, response_data)
|
|
||||||
|
|
||||||
def test_too_small_nb_players_by_game(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"nb_players_by_game": 1, "nb_players": self.nb_players})
|
|
||||||
response_data = json.loads(response.content)
|
|
||||||
self.assertDictEqual(response_data, {'nb_players_by_game': ['The numbers of players by game must be greather than 2.']})
|
|
||||||
|
|
||||||
def test_too_small_nb_players(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"nb_players_by_game": self.nb_players_by_game, "nb_players": 1})
|
|
||||||
response_data = json.loads(response.content)
|
|
||||||
self.assertDictEqual(response_data, {'nb_players': ['The numbers of players must be greather than 2.'], 'nb_players_by_game': ['The numbers of players by game must be smaller than the numbers of players.']})
|
|
||||||
|
|
||||||
def test_nb_players_smaller_nb_players_by_game(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"nb_players_by_game": 5, "nb_players": 3})
|
|
||||||
response_data = json.loads(response.content)
|
|
||||||
self.assertDictEqual(response_data, {'nb_players_by_game': ['The numbers of players by game must be smaller than the numbers of players.']})
|
|
@ -6,6 +6,5 @@ from .viewset import TournamentViewSet
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("<int:pk>", TournamentViewSet.as_view({"get": "retrieve"}), name="tournament_page"),
|
path("<int:pk>", TournamentViewSet.as_view({"get": "retrieve"}), name="tournament_page"),
|
||||||
path("", TournamentViewSet.as_view({"post": "create"}), name="tournament_page"),
|
re_path(r"search/(?P<state>\w*)", TournamentViewSet.as_view({"get": "list", "post": "create"}), name="tournaments"),
|
||||||
re_path(r"search/(?P<state>\w*)", TournamentViewSet.as_view({"get": "list", }), name="tournaments"),
|
|
||||||
]
|
]
|
Loading…
Reference in New Issue
Block a user