-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing test cases to POST and PATCH user models at the api/users endpoint #340
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c319122
Created a test for GET at the api/users endpoint
cuyakonwu 0a685e3
Appopriately implemented the user list and detail tests
cuyakonwu 8a1f341
Removed comments
cuyakonwu 4c201a0
adjusted the delete function to ensuerr a new user was created to beg…
cuyakonwu f3eb9e6
Merge branch 'dev' into api/post-patch-user
giomhern c47b693
Finished Deliverable tests for post and patch at the api/users endpoint
cuyakonwu d9e4ea6
Merge branch 'dev' into api/post-patch-user
giomhern 6236eff
Merge branch 'dev' into api/post-patch-user
cuyakonwu 57275b6
User post is broken
cuyakonwu 243e064
Minor fix for post test -- missing field
giomhern 9983d2b
Merge branch 'dev' into api/post-patch-user
giomhern ffb234e
Merge branch 'dev' into api/post-patch-user
giomhern c89e21f
Merge branch 'dev' into api/post-patch-user
giomhern 507dbff
Merge branch 'dev' into api/post-patch-user
majorsylvie 4b370b4
Merge branch 'dev' into api/post-patch-user
cuyakonwu ea01a82
Merge branch 'dev' into api/post-patch-user
cuyakonwu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from rest_framework.test import APITestCase | ||
|
||
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): | ||
|
@@ -282,3 +282,50 @@ def test_delete_message(self): | |
self.assertEqual(data2["update_on"], Message.objects.get(id=2).update_on) | ||
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={"pk": user.id}) | ||
|
||
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_user_post(self): | ||
user = {"name": "BillyBob", "email": "[email protected]"} | ||
|
||
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={"pk": user.id}) | ||
|
||
updated_data = {"name": "Johnn"} | ||
|
||
response = self.client.patch(url, data=updated_data, format="json") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple, clean, and I approve! |
||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(User.objects.count(), 1) | ||
self.assertEqual(response.data["name"], updated_data["name"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!