-
-
Notifications
You must be signed in to change notification settings - Fork 256
Add endpoints for digest settings. #3345
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
Open
fettuccinae
wants to merge
10
commits into
metabrainz:metabrainz-notifications
Choose a base branch
from
fettuccinae:backend
base: metabrainz-notifications
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c04c7b3
Add frontend for digest settings
fettuccinae 2f2e13f
Change minimum digest age to 1 day
fettuccinae 2f435bf
Add endpoints for digest-preference
fettuccinae 351cf76
Fix tests
fettuccinae 7686973
Add tests
fettuccinae 2c1ade8
Fix test
fettuccinae 061498c
Add docstrings, Fix a bug
fettuccinae cf934fc
Remove frontend bits and Rename endpoints
fettuccinae 895dc81
Use /notifications instead of /notification-settings
fettuccinae b87932e
Fix typo
fettuccinae 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
89 changes: 89 additions & 0 deletions
89
listenbrainz/domain/tests/test_metabrainz_notifications.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,89 @@ | ||
from unittest.mock import patch, MagicMock | ||
from listenbrainz.domain import metabrainz_notifications | ||
from listenbrainz.tests.integration import NonAPIIntegrationTestCase | ||
|
||
|
||
class MetabrainNotificationsTestCase(NonAPIIntegrationTestCase): | ||
@patch("listenbrainz.domain.metabrainz_notifications.send_multiple_notifications") | ||
def test_send_notification(self, mock_send_multiple): | ||
metabrainz_notifications.send_notification( | ||
subject="test123", | ||
body="testbody456", | ||
musicbrainz_row_id=123, | ||
user_email="[email protected]", | ||
from_addr="[email protected]", | ||
) | ||
expected_notification = [ | ||
[ | ||
{ | ||
"subject": "test123", | ||
"body": "testbody456", | ||
"user_id": 123, | ||
"to": "[email protected]", | ||
"project": "listenbrainz", | ||
"sent_from": "[email protected]", | ||
"send_email": True, | ||
"important": True, | ||
"expire_age": 7, | ||
} | ||
] | ||
] | ||
|
||
mock_send_multiple.assert_called_once_with(expected_notification) | ||
|
||
@patch("listenbrainz.domain.metabrainz_notifications._fetch_token") | ||
@patch("requests.post") | ||
def test_send_multiple_notifications(self, mock_post, mock_fetch_token): | ||
mock_fetch_token.return_value = "access_token" | ||
mock_response = MagicMock() | ||
mock_response.raise_for_status.return_value = None | ||
mock_post.return_value = mock_response | ||
|
||
notifications = [{"user_id": 1, "body": "Notification 1"}] | ||
|
||
metabrainz_notifications.send_multiple_notifications(notifications) | ||
|
||
mock_fetch_token.assert_called_once() | ||
expected_url = "https://metabrainz.org/notification/send" | ||
expected_headers = {"Authorization": "Bearer access_token"} | ||
mock_post.assert_called_once_with( | ||
url=expected_url, json=notifications, headers=expected_headers | ||
) | ||
mock_response.raise_for_status.assert_called_once() | ||
|
||
@patch("listenbrainz.domain.metabrainz_notifications._fetch_token") | ||
@patch("requests.get") | ||
def test_get_digest_preference(self, mock_get, mock_fetch_token): | ||
mock_fetch_token.return_value = "access_token" | ||
mock_response = MagicMock() | ||
mock_response.raise_for_status.return_value = None | ||
mock_response.json.return_value = {"digest": True, "digest_age": 7} | ||
mock_get.return_value = mock_response | ||
|
||
result = metabrainz_notifications.get_digest_preference(musicbrainz_row_id=456) | ||
|
||
expected_url = "https://metabrainz.org/notification/456/digest-preference" | ||
mock_get.assert_called_once_with( | ||
url=expected_url, headers={"Authorization": "Bearer access_token"} | ||
) | ||
self.assertEqual(result, {"digest": True, "digest_age": 7}) | ||
|
||
@patch("listenbrainz.domain.metabrainz_notifications._fetch_token") | ||
@patch("requests.post") | ||
def test_set_digest_preference(self, mock_post, mock_fetch_token): | ||
mock_fetch_token.return_value = "access_token" | ||
mock_response = MagicMock() | ||
mock_response.raise_for_status.return_value = None | ||
mock_response.json.return_value = {"digest": True, "digest_age": 14} | ||
mock_post.return_value = mock_response | ||
|
||
result = metabrainz_notifications.set_digest_preference( | ||
musicbrainz_row_id=789, digest=True, digest_age=14 | ||
) | ||
|
||
expected_url = "https://metabrainz.org/notification/789/digest-preference" | ||
expected_data = {"digest": True, "digest_age": 14} | ||
mock_post.assert_called_once_with( | ||
url=expected_url, json=expected_data, headers={"Authorization": "Bearer access_token"} | ||
) | ||
self.assertEqual(result, {"digest": True, "digest_age": 14}) |
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
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.
docstrings
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.
Oops, sorry. Got lost in branches. Added it now.