-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into apis/post-users
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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() | ||
|