-
Notifications
You must be signed in to change notification settings - Fork 406
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
test: seed data for permission and roles e2e tests #4173
Merged
novakzaballa
merged 21 commits into
main
from
test/seed-data-for-permission-and-roles-e2e-tests
Aug 13, 2024
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f9c7d5f
test: Seed data for permission and roles e2e tests
novakzaballa 30f4302
Create a user for use a role
novakzaballa 912261a
Update unit test
novakzaballa 252cb86
Update the PLAN_SUBSCRIPTION_METADATA_FOR_TEST
novakzaballa 95f09d0
Merge branch 'main' into test/seed-data-for-permission-and-roles-e2e-…
novakzaballa 72a0ac8
Solve e2e issue
novakzaballa 2998bb6
Update unit test
novakzaballa 6cc6d28
Code coverage
novakzaballa 62cf5b4
Update assert in the unit test
novakzaballa f9d6aa9
Add unit test for subscription metadata for tests
novakzaballa 7456fa3
Add constants, and username
novakzaballa 0c6c427
Move org_admin to the top of the users
novakzaballa 0e198d1
Update info comment
novakzaballa c22741b
Change logic for get the subscription metadata for e2e test
novakzaballa 5560fbd
Add a default value
novakzaballa 624f6a6
Delete invalid unit test
novakzaballa 6c553c5
Add unit test
novakzaballa 9e06563
Use middleware and permissions mixin
matthewelwell a991b03
Solve e2e issue permission
novakzaballa ff025d3
Solve permissions
novakzaballa bcd05b7
Solve permission issues
novakzaballa 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.conf import settings | ||
|
||
|
||
class E2ETestMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
request.is_e2e = False | ||
if ( | ||
request.META.get("HTTP_X_E2E_TEST_AUTH_TOKEN") | ||
== settings.E2E_TEST_AUTH_TOKEN | ||
): | ||
request.is_e2e = True | ||
|
||
return self.get_response(request) |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import os | ||
|
||
from django.views import View | ||
from rest_framework.permissions import BasePermission | ||
from rest_framework.request import Request | ||
|
||
|
||
class E2ETestPermission(BasePermission): | ||
def has_permission(self, request, view): | ||
if "E2E_TEST_AUTH_TOKEN" not in os.environ: | ||
return False | ||
return ( | ||
request.META.get("HTTP_X_E2E_TEST_AUTH_TOKEN") | ||
== os.environ["E2E_TEST_AUTH_TOKEN"] | ||
) | ||
def has_permission(self, request: Request, view: View) -> bool: | ||
return getattr(request, "is_e2e", False) is True | ||
|
||
|
||
class E2ETestPermissionMixin: | ||
def has_permission(self, request: Request, view: View) -> bool: | ||
if getattr(request, "is_e2e", False) is True: | ||
return True | ||
return super().has_permission(request, view) |
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
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
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.
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.
@novakzaballa even if this was necessary, the call to
super()
is quite clearly unnecessary as we're early returning on the line above if it's not true.In general though, this is exactly the job that the
E2ETestPermissionMixin
is trying to achieve. Can you have another look at this please?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.
You’re right, the call to super() was no longer necessary and has been corrected.
There was an issue with this part of the code that was validating the number of projects and returning
False
, I moved part of the logic exclusively to this validation.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.
In this case, I don't think the mixin is actually doing anything? I would rather see the mixin used, or removed if we can't get it working.
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.
I removed it since it doesn't do what we expect.