Skip to content

Commit

Permalink
Merge branch 'dev' into apis/post-users
Browse files Browse the repository at this point in the history
  • Loading branch information
majorsylvie authored Dec 8, 2023
2 parents d0726f7 + 23b4b8c commit 15e23ee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/chigame/api/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Meta:
name = Faker("name")
email = Faker("email")
password = Faker("password")
username = Faker("user_name")


class TournamentFactory(DjangoModelFactory):
Expand Down
55 changes: 54 additions & 1 deletion src/chigame/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -379,6 +379,59 @@ 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.username])
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_user_post(self):
user = {
"email": "[email protected]",
"name": "John Doe",
"username": "john_doe",
"password": "password",
"tokens": 2,
}

url = reverse("api-user-list")
response = self.client.post(url, data=user, format="json")

self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(User.objects.count(), 1)
self.assertEqual(response.data["email"], user["email"])
self.assertEqual(response.data["name"], user["name"])

def test_user_patch(self):
user = UserFactory()
url = reverse("api-user-detail", kwargs={"slug": user.username})

updated_data = {"username": "Johnn"}

response = self.client.patch(url, data=updated_data, format="json")

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(User.objects.count(), 1)
self.assertEqual(response.data["username"], updated_data["username"])

def test_feed_message(self):
self.user1 = UserFactory()
self.user2 = UserFactory()
Expand Down

0 comments on commit 15e23ee

Please sign in to comment.