fix(submissions): broadcast crop delete + fix for crop admin
This commit is contained in:
@@ -11,7 +11,7 @@ from events.models import Event
|
||||
from games.models import EventGame, Game
|
||||
|
||||
from . import tasks
|
||||
from .models import Scope, Submission
|
||||
from .models import ImageCrop, Scope, Submission, SubmissionFile
|
||||
from .services.aandt_client.models import (
|
||||
AandtApiInfosResponse200,
|
||||
AandtApiMatchesResponse200,
|
||||
@@ -434,3 +434,55 @@ class ListUserSubmissionsApiTests(TestCase):
|
||||
self.assertEqual(
|
||||
{s["id"] for s in data}, {str(self.mine.id), str(self.theirs.id)}
|
||||
)
|
||||
|
||||
|
||||
class SubmissionBroadcastTests(TestCase):
|
||||
def setUp(self):
|
||||
event = Event.objects.create(name="Event", path="event")
|
||||
game = Game.objects.create(name="Game", path="game")
|
||||
event_game = EventGame.objects.create(event=event, game=game)
|
||||
scope = Scope.objects.create(event_game=event_game, name="M1")
|
||||
self.player = CustomUser.objects.create_user(username="player", password="x")
|
||||
submission = Submission.objects.create(
|
||||
event=event, scope=scope, user=self.player
|
||||
)
|
||||
# bulk_create: skips the file broadcast, which would sign an S3 url
|
||||
[submission_file] = SubmissionFile.objects.bulk_create(
|
||||
[
|
||||
SubmissionFile(
|
||||
submission=submission,
|
||||
file="shot.png",
|
||||
original_filename="shot.png",
|
||||
file_size=1,
|
||||
content_type="image/png",
|
||||
)
|
||||
]
|
||||
)
|
||||
self.crop = ImageCrop.objects.create(
|
||||
submission_file=submission_file, x1=0, y1=0, x2=1, y2=1
|
||||
)
|
||||
|
||||
def test_crop_update_reaches_owner_and_staff(self):
|
||||
with mock.patch("submissions.signals.get_channel_layer") as get_layer:
|
||||
get_layer.return_value.group_send = mock.AsyncMock()
|
||||
self.crop.save()
|
||||
|
||||
groups = [c.args[0] for c in get_layer.return_value.group_send.call_args_list]
|
||||
self.assertEqual(
|
||||
groups, ["submissions_staff", f"submissions_user_{self.player.id}"]
|
||||
)
|
||||
|
||||
def test_crop_delete_reaches_owner_and_staff(self):
|
||||
crop_id = str(self.crop.id)
|
||||
|
||||
with mock.patch("submissions.signals.get_channel_layer") as get_layer:
|
||||
get_layer.return_value.group_send = mock.AsyncMock()
|
||||
self.crop.delete()
|
||||
|
||||
calls = get_layer.return_value.group_send.call_args_list
|
||||
self.assertEqual(
|
||||
[c.args[0] for c in calls],
|
||||
["submissions_staff", f"submissions_user_{self.player.id}"],
|
||||
)
|
||||
self.assertEqual(calls[0].args[1]["type"], "submission.crop.deleted")
|
||||
self.assertEqual(calls[0].args[1]["crop"]["id"], crop_id)
|
||||
|
||||
Reference in New Issue
Block a user