-
Notifications
You must be signed in to change notification settings - Fork 345
[ENG-7965] Add v2 email token confirmation endpoints #11139
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
brianjgeiger
merged 4 commits into
CenterForOpenScience:feature/pbs-25-10
from
Johnetordoff:add-v2-confirmation-endpoint
May 21, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Empty file.
150 changes: 150 additions & 0 deletions
150
api_tests/users/views/sanction_response/test_user_sanction_response.py
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,150 @@ | ||
import pytest | ||
|
||
from api.base.settings.defaults import API_BASE | ||
from framework.auth import Auth | ||
from osf_tests.factories import AuthUserFactory, RetractionFactory | ||
from osf.utils.tokens import encode | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestSanctionResponse: | ||
|
||
@pytest.fixture() | ||
def user(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture | ||
def sanction(self): | ||
sanction = RetractionFactory() | ||
registration = sanction.registrations.first() | ||
sanction.add_authorizer(sanction.initiated_by, registration, save=True) | ||
return sanction | ||
|
||
@pytest.fixture | ||
def registration(self, sanction): | ||
return sanction.registrations.first() | ||
|
||
@pytest.fixture | ||
def url(self, sanction): | ||
return f'/{API_BASE}users/{sanction.initiated_by._id}/sanction_response/' | ||
|
||
@pytest.fixture | ||
def approval_token(self, sanction): | ||
return sanction.approval_state[sanction.initiated_by._id]['approval_token'] | ||
|
||
@pytest.fixture() | ||
def sanction_url(self, user): | ||
return f'/{API_BASE}users/{user._id}/sanction_response/' | ||
|
||
@pytest.fixture() | ||
def token(self, user): | ||
return encode({'uid': user._id, 'email': user.username}) | ||
|
||
def test_get_not_allowed(self, app, sanction_url): | ||
res = app.get(sanction_url, expect_errors=True) | ||
assert res.status_code == 405 | ||
|
||
def test_post_missing_fields(self, app, sanction_url, user): | ||
res = app.post_json_api( | ||
sanction_url, | ||
{'data': {'attributes': {}}}, | ||
auth=user.auth, | ||
expect_errors=True | ||
) | ||
print(res.json) | ||
assert res.json['errors'] == [ | ||
{ | ||
'source': { | ||
'pointer': '/data/attributes/uid' | ||
}, | ||
'detail': 'This field is required.' | ||
}, | ||
{ | ||
'source': { | ||
'pointer': '/data/attributes/destination' | ||
}, | ||
'detail': 'This field is required.' | ||
}, | ||
{ | ||
'source': { | ||
'pointer': '/data/attributes/token' | ||
}, | ||
'detail': 'This field is required.' | ||
}, | ||
{ | ||
'source': { | ||
'pointer': '/data/attributes/action' | ||
}, | ||
'detail': 'This field is required.' | ||
} | ||
] | ||
assert res.status_code == 400 | ||
|
||
def test_post_user_not_found(self, app, token): | ||
fake_uid = 'abc12' | ||
url = f'/{API_BASE}users/{fake_uid}/sanction_response/' | ||
res = app.post_json_api( | ||
url, | ||
{ | ||
'data': { | ||
'attributes': { | ||
'uid': fake_uid, | ||
'token': token, | ||
'action': 'approve', | ||
'sanction_type': 'retraction', | ||
'destination': 'foo' | ||
} | ||
} | ||
}, | ||
expect_errors=True | ||
) | ||
assert res.json['errors'] == [{'detail': 'Not found.'}] | ||
|
||
def test_missing_action(self, app, url, sanction, registration, approval_token): | ||
user = sanction.initiated_by | ||
res = app.post_json_api( | ||
url, | ||
{ | ||
'data': { | ||
'attributes': { | ||
'uid': user._id, | ||
'token': approval_token, | ||
'destination': 'notebook', | ||
'sanction_type': 'retraction', | ||
} | ||
} | ||
}, | ||
auth=Auth(user), | ||
expect_errors=True | ||
) | ||
assert res.status_code == 400 | ||
assert res.json['errors'] == [ | ||
{ | ||
'source': { | ||
'pointer': '/data/attributes/action' | ||
}, | ||
'detail': 'This field is required.' | ||
} | ||
] | ||
|
||
sanction.refresh_from_db() | ||
registration.refresh_from_db() | ||
|
||
def test_post_missing_sanction_type(self, app, sanction_url, user, token): | ||
res = app.post_json_api( | ||
sanction_url, | ||
{ | ||
'data': { | ||
'attributes': { | ||
'uid': user._id, | ||
'token': token, | ||
'action': 'reject', | ||
'destination': 'foo' | ||
} | ||
} | ||
}, | ||
auth=user.auth, | ||
expect_errors=True | ||
) | ||
assert res.status_code == 400 | ||
assert res.json['errors'] == [{'detail': 'sanction_type not found.'}] |
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.
Refactor because it's now shared