Skip to content

Commit

Permalink
SIO-1867 Mail submission admin view is not filtered to the current co…
Browse files Browse the repository at this point in the history
…ntest

Change-Id: I56d8743ba030dddc7429be77a8923188e5c3444a
  • Loading branch information
pjkozlowski authored and Gerrit Code Review committed Dec 21, 2016
1 parent e34f423 commit 4d9ce1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions oioioi/mailsubmit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def accept_action(self, request, queryset):
accept_mail_submission(request, mailsubmission)
accept_action.short_description = _("Accept selected submissions")

def queryset(self, request):
queryset = super(MailSubmissionAdmin, self).queryset(request)
def get_queryset(self, request):
queryset = super(MailSubmissionAdmin, self).get_queryset(request)
queryset = queryset.filter(problem_instance__contest=request.contest)
queryset = queryset.order_by('-id')
return queryset
Expand Down
36 changes: 36 additions & 0 deletions oioioi/mailsubmit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from oioioi.mailsubmit.models import MailSubmissionConfig, MailSubmission
from oioioi.mailsubmit.utils import mail_submission_hashes
from oioioi.participants.models import Participant
from oioioi.problems.models import Problem


class MailSubmitFileMixin(object):
Expand Down Expand Up @@ -164,3 +165,38 @@ def test_mailsubmit_permissions(self):
self.assertEqual(200, response.status_code)

self.assertEqual(MailSubmission.objects.count(), 1)

def test_mailsubmissions_list(self):
c1 = Contest(id='contest1', name='Contest1', controller_name=
'oioioi.participants.tests.ParticipantsContestController')
c1.save()
c2 = Contest(id='contest2', name='Contest2', controller_name=
'oioioi.participants.tests.ParticipantsContestController')
c2.save()
p = Problem.objects.get()
pi1 = ProblemInstance(contest=c1, problem=p,
short_name='problem_instance1')
pi1.save()
pi2 = ProblemInstance(contest=c2, problem=p,
short_name='problem_instance2')
pi2.save()
u = User.objects.get(username='test_user')
f = ContentFile('aaa', name='bbbb.cpp')
ms1 = MailSubmission(problem_instance=pi1, user=u)
ms1.source_file.save(f.name, f)
ms1.save()
ms2 = MailSubmission(problem_instance=pi2, user=u)
ms2.source_file.save(f.name, f)
ms2.save()

self.client.login(username='test_admin')
url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
kwargs={'contest_id': 'contest1'})
response = self.client.get(url)
self.assertContains(response, 'problem_instance1')
self.assertNotContains(response, 'problem_instance2')
url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
kwargs={'contest_id': 'contest2'})
response = self.client.get(url)
self.assertContains(response, 'problem_instance2')
self.assertNotContains(response, 'problem_instance1')

0 comments on commit 4d9ce1f

Please sign in to comment.