generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 14
test: adds test cases for authentication #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
44b6410
feat(auth): Integrated RDS Auth
VaibhavSingh8 13051de
feat(auth): Integrated RDS Auth
VaibhavSingh8 54418c5
fix: env.example
VaibhavSingh8 500f0b6
refactor: changes based on ai pr review
VaibhavSingh8 9060369
feat(auth): Implemented google authentication for todo-app
VaibhavSingh8 8ea44e6
resolved pr comments
VaibhavSingh8 5a4c210
resolved pr comments
VaibhavSingh8 48c3546
resolved bot comments
VaibhavSingh8 5915f74
removed exceptions from views file
VaibhavSingh8 8936274
refactored auth views
VaibhavSingh8 9e0a411
refactored unused field
VaibhavSingh8 89b65db
Merge Google Auth feature (final implementation)
VaibhavSingh8 4101eb4
resolved review comments and added status code to api responses
VaibhavSingh8 a18d700
resolved pr comments
VaibhavSingh8 114f5fe
resolved pr comments
VaibhavSingh8 6e84d9f
Tests for Authentication feature (#80)
VaibhavSingh8 1689c8c
Merge remote-tracking branch 'origin/develop' into auth-final
VaibhavSingh8 da7abf9
fixed workflow file
VaibhavSingh8 a2a8c41
refactor based on ai pr reviews
VaibhavSingh8 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from datetime import datetime, timezone | ||
|
||
users_db_data = [ | ||
{ | ||
"google_id": "123456789", | ||
"email_id": "[email protected]", | ||
"name": "Test User", | ||
"created_at": datetime.now(timezone.utc), | ||
"updated_at": datetime.now(timezone.utc), | ||
}, | ||
{ | ||
"google_id": "987654321", | ||
"email_id": "[email protected]", | ||
"name": "Another User", | ||
"created_at": datetime.now(timezone.utc), | ||
"updated_at": datetime.now(timezone.utc), | ||
}, | ||
] | ||
VaibhavSingh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
from http import HTTPStatus | ||
from bson import ObjectId | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient | ||
from bson import ObjectId | ||
|
||
from todo.tests.fixtures.task import tasks_db_data | ||
from todo.tests.integration.base_mongo_test import BaseMongoTestCase | ||
from todo.constants.messages import ApiErrors, ValidationErrors | ||
from todo.utils.google_jwt_utils import generate_google_token_pair | ||
|
||
|
||
class AuthenticatedMongoTestCase(BaseMongoTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self._setup_auth_cookies() | ||
|
||
def _setup_auth_cookies(self): | ||
user_data = { | ||
"user_id": str(ObjectId()), | ||
"google_id": "test_google_id", | ||
"email": "[email protected]", | ||
"name": "Test User", | ||
} | ||
tokens = generate_google_token_pair(user_data) | ||
self.client.cookies["ext-access"] = tokens["access_token"] | ||
self.client.cookies["ext-refresh"] = tokens["refresh_token"] | ||
|
||
VaibhavSingh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class TaskDetailAPIIntegrationTest(BaseMongoTestCase): | ||
class TaskDetailAPIIntegrationTest(AuthenticatedMongoTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.db.tasks.delete_many({}) # Clear tasks to avoid DuplicateKeyError | ||
|
@@ -17,7 +35,6 @@ def setUp(self): | |
self.existing_task_id = str(self.task_doc["_id"]) | ||
self.non_existent_id = str(ObjectId()) | ||
self.invalid_task_id = "invalid-task-id" | ||
self.client = APIClient() | ||
|
||
def test_get_task_by_id_success(self): | ||
url = reverse("task_detail", args=[self.existing_task_id]) | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
from http import HTTPStatus | ||
from bson import ObjectId | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient | ||
from bson import ObjectId | ||
|
||
from todo.tests.fixtures.task import tasks_db_data | ||
from todo.tests.integration.base_mongo_test import BaseMongoTestCase | ||
from todo.constants.messages import ValidationErrors, ApiErrors | ||
from todo.utils.google_jwt_utils import generate_google_token_pair | ||
|
||
|
||
class AuthenticatedMongoTestCase(BaseMongoTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self._setup_auth_cookies() | ||
|
||
def _setup_auth_cookies(self): | ||
user_data = { | ||
"user_id": str(ObjectId()), | ||
"google_id": "test_google_id", | ||
"email": "[email protected]", | ||
"name": "Test User", | ||
} | ||
tokens = generate_google_token_pair(user_data) | ||
self.client.cookies["ext-access"] = tokens["access_token"] | ||
self.client.cookies["ext-refresh"] = tokens["refresh_token"] | ||
VaibhavSingh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class TaskDeleteAPIIntegrationTest(BaseMongoTestCase): | ||
class TaskDeleteAPIIntegrationTest(AuthenticatedMongoTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.db.tasks.delete_many({}) | ||
|
@@ -17,7 +35,6 @@ def setUp(self): | |
self.existing_task_id = str(task_doc["_id"]) | ||
self.non_existent_id = str(ObjectId()) | ||
self.invalid_task_id = "invalid-task-id" | ||
self.client = APIClient() | ||
|
||
def test_delete_task_success(self): | ||
url = reverse("task_detail", args=[self.existing_task_id]) | ||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file is required for Python to recognize this directory as a package |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.