-
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 GET and DELETE user models at the api/users endpoint #335
Open
cuyakonwu
wants to merge
9
commits into
dev
Choose a base branch
from
api/UserTest
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 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 3be65a6
Merge branch 'dev' into api/UserTest
giomhern 18bee89
Merge branch 'dev' into api/UserTest
giomhern 9be27cb
Merge branch 'dev' into api/UserTest
cuyakonwu 3189394
Added a username faker to support better lookups
cuyakonwu 3ecb0c9
Merge branch 'dev' into api/UserTest
majorsylvie 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,27 @@ 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) | ||
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. This looks good to me! |
||
|
||
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) | ||
giomhern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.assertEqual(User.objects.count(), 0) |
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.
Perhaps compare fields here to ensure that the response and the user (from the factory) match!
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.
There would be no simple way to do that as the faker is random, I will fix that once I implement the patch test!