-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add route to get a member's data for helper review #451
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4f9c088
Add route to get a member's data for helper review
mbaruh d2690bb
Amend top_channel_activity return type
mbaruh 3468d12
Added test for metricity-review-data
mbaruh 66047f0
Test metricity-review-data when user doesn't exist
mbaruh 07847e9
Get rid of stray print
mbaruh fdc1be6
Ignore deleted messaages in message counts
mbaruh 89bf60e
Merge branch 'master' into mbaruh/channel-activity
mbaruh f4a6748
Document endpoint in viewset docstring
mbaruh 9b1b42a
Split test_no_metricity_user to two tests by endpoints
mbaruh cd797f8
Add case in query for voice chat activity
mbaruh bc66963
Add more records to test the endpoint with
mbaruh d213474
Merge branch 'main' into mbaruh/channel-activity
mbaruh 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 |
---|---|---|
|
@@ -410,7 +410,7 @@ def test_get_metricity_data(self): | |
joined_at = "foo" | ||
total_messages = 1 | ||
total_blocks = 1 | ||
self.mock_metricity_user(joined_at, total_messages, total_blocks) | ||
self.mock_metricity_user(joined_at, total_messages, total_blocks, []) | ||
|
||
# When | ||
url = reverse('bot:user-metricity-data', args=[0], host='api') | ||
|
@@ -436,13 +436,24 @@ def test_no_metricity_user(self): | |
# Then | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_no_metricity_user_for_review(self): | ||
# Given | ||
self.mock_no_metricity_user() | ||
|
||
# When | ||
url = reverse('bot:user-metricity-review-data', args=[0], host='api') | ||
response = self.client.get(url) | ||
|
||
# Then | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_metricity_voice_banned(self): | ||
cases = [ | ||
{'exception': None, 'voice_banned': True}, | ||
{'exception': ObjectDoesNotExist, 'voice_banned': False}, | ||
] | ||
|
||
self.mock_metricity_user("foo", 1, 1) | ||
self.mock_metricity_user("foo", 1, 1, [["bar", 1]]) | ||
|
||
for case in cases: | ||
with self.subTest(exception=case['exception'], voice_banned=case['voice_banned']): | ||
|
@@ -455,14 +466,35 @@ def test_metricity_voice_banned(self): | |
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json()["voice_banned"], case["voice_banned"]) | ||
|
||
def mock_metricity_user(self, joined_at, total_messages, total_blocks): | ||
def test_metricity_review_data(self): | ||
# Given | ||
joined_at = "foo" | ||
total_messages = 10 | ||
total_blocks = 1 | ||
channel_activity = [["bar", 4], ["buzz", 6]] | ||
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. There should be subtests to test each case in the query (i.e. you need to test off topic and help channels too). |
||
self.mock_metricity_user(joined_at, total_messages, total_blocks, channel_activity) | ||
|
||
# When | ||
url = reverse('bot:user-metricity-review-data', args=[0], host='api') | ||
response = self.client.get(url) | ||
|
||
# Then | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json(), { | ||
"joined_at": joined_at, | ||
"top_channel_activity": channel_activity, | ||
"total_messages": total_messages | ||
}) | ||
|
||
def mock_metricity_user(self, joined_at, total_messages, total_blocks, top_channel_activity): | ||
patcher = patch("pydis_site.apps.api.viewsets.bot.user.Metricity") | ||
self.metricity = patcher.start() | ||
self.addCleanup(patcher.stop) | ||
self.metricity = self.metricity.return_value.__enter__.return_value | ||
self.metricity.user.return_value = dict(joined_at=joined_at) | ||
self.metricity.total_messages.return_value = total_messages | ||
self.metricity.total_message_blocks.return_value = total_blocks | ||
self.metricity.top_channel_activity.return_value = top_channel_activity | ||
|
||
def mock_no_metricity_user(self): | ||
patcher = patch("pydis_site.apps.api.viewsets.bot.user.Metricity") | ||
|
@@ -472,3 +504,4 @@ def mock_no_metricity_user(self): | |
self.metricity.user.side_effect = NotFound() | ||
self.metricity.total_messages.side_effect = NotFound() | ||
self.metricity.total_message_blocks.side_effect = NotFound() | ||
self.metricity.top_channel_activity.side_effect = NotFound() |
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
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.
Grammar here is irking me a bit.
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.
The purpose of those names is to be used in a sentence, rather than titles, although I agree it's not the prettiest
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.
Ah, gotcha, I thought it would be more a sort of list like ```
Help channels: 24,404 messages
Off topic: 12,000 messages
...: ... messages