diff --git a/src/chigame/api/tests/factories.py b/src/chigame/api/tests/factories.py index f4d1b5c7..a2e30108 100644 --- a/src/chigame/api/tests/factories.py +++ b/src/chigame/api/tests/factories.py @@ -82,7 +82,9 @@ class Meta: name = Faker("name") email = Faker("email") + username = Faker("user_name") password = Faker("password") + tokens = Faker("random_int", min=1, max=3) class TournamentFactory(DjangoModelFactory): diff --git a/src/chigame/api/tests/test_api.py b/src/chigame/api/tests/test_api.py index aea8367c..b97336db 100644 --- a/src/chigame/api/tests/test_api.py +++ b/src/chigame/api/tests/test_api.py @@ -12,7 +12,7 @@ # Local application/library specific imports from chigame.api.serializers import GameSerializer from chigame.api.tests.factories import ChatFactory, GameFactory, TournamentFactory, UserFactory -from chigame.games.models import Game, Message +from chigame.games.models import Game, Message, User class GameTests(APITestCase): @@ -379,6 +379,30 @@ def test_delete_message(self): self.assertEqual(data2["content"], Message.objects.get(id=2).content) self.assertEqual(2, Message.objects.get(id=2).token_id) + +class UserTests(APITestCase): + def test_user_get(self): + user = UserFactory() + + list_url = reverse("api-user-list") + detail_url = reverse("api-user-detail", kwargs={"slug": user.username}) + + list_response = self.client.get(list_url) + assert list_response.status_code == 200 + + detail_response = self.client.get(detail_url) + assert detail_response.status_code == 200 + + def test_user_delete(self): + user = UserFactory() + self.assertEqual(User.objects.count(), 1) + + url = reverse("api-user-detail", args=[user.id]) + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + self.assertEqual(User.objects.count(), 0) + def test_feed_message(self): self.user1 = UserFactory() self.user2 = UserFactory()