-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
submission/report
endpoint (#317)
* Simplify building of Slack report message * Move function to send reports to Slack to the slack_helpers * Add submission/report endpoint * Add tests for submission/report endpoint * Add submission fields for reports * Save report reason and Slack message ID when reporting * Only report posts that don't already have a report * Fix submission report tests * Adjust submission report Slack fields to match what we need * Update implementation of report sending to new Slack data
- Loading branch information
1 parent
470c55b
commit 99a871e
Showing
8 changed files
with
268 additions
and
86 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.2.10 on 2022-01-16 13:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0016_submission_nsfw"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="submission", | ||
name="report_reason", | ||
field=models.CharField(blank=True, max_length=300, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="submission", | ||
name="report_slack_id", | ||
field=models.CharField(blank=True, max_length=50, null=True), | ||
), | ||
] |
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,23 @@ | ||
# Generated by Django 3.2.10 on 2022-01-16 21:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0017_auto_20220116_1355"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="submission", | ||
old_name="report_slack_id", | ||
new_name="report_slack_message_ts", | ||
), | ||
migrations.AddField( | ||
model_name="submission", | ||
name="report_slack_channel_id", | ||
field=models.CharField(blank=True, max_length=50, null=True), | ||
), | ||
] |
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,63 @@ | ||
import json | ||
from unittest.mock import MagicMock | ||
|
||
from django.test import Client | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from api.views.slack_helpers import client as slack_client | ||
from utils.test_helpers import create_submission, setup_user_client | ||
|
||
|
||
class TestSubmissionReport: | ||
"""Tests validating the behavior of the Submission report process.""" | ||
|
||
def test_report_already_removed(self, client: Client) -> None: | ||
"""Verify that reporting an already removed submission doesn't do anything.""" | ||
slack_client.chat_postMessage = MagicMock() | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3, removed_from_queue=True) | ||
assert submission.removed_from_queue | ||
|
||
data = {"reason": "Violation of ALL the rules"} | ||
|
||
result = client.patch( | ||
reverse("submission-report", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_201_CREATED | ||
assert submission.removed_from_queue | ||
assert slack_client.chat_postMessage.call_count == 0 | ||
|
||
def test_report_not_removed(self, client: Client) -> None: | ||
"""Verify that reporting sends a message to Slack.""" | ||
mock = MagicMock() | ||
slack_client.chat_postMessage = mock | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3) | ||
assert not submission.removed_from_queue | ||
assert not submission.report_reason | ||
assert not submission.report_slack_channel_id | ||
assert not submission.report_slack_message_ts | ||
|
||
data = {"reason": "Violation of ALL the rules"} | ||
|
||
result = client.patch( | ||
reverse("submission-report", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_201_CREATED | ||
assert not submission.removed_from_queue | ||
assert submission.report_reason == "Violation of ALL the rules" |
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.