Esempio n. 1
0
    def list(self, request, *args, **kwargs):
        challenge_pk = kwargs.get('challenge_pk', '')
        try:
            Challenge.objects.get(pk=challenge_pk)
        except Challenge.DoesNotExist:
            return Response(
                data={'error': f'Invalid challenge id {challenge_pk}!'},
                status=400)

        top_submissions = Submission.fetch_top_submissions_for_challenge(
            challenge_id=challenge_pk)

        return Response(
            data=LimitedSubmissionSerializer(top_submissions, many=True).data)
Esempio n. 2
0
    def test_fetch_top_submissions(self):
        """
        The method should return the top submissions for a given challenge,
            selecting the top submission for each user
        """
        """ Arrange """
        f_submission = SubmissionFactory(author=self.auth_user, challenge=self.challenge, result_score=50)
        # Second user with submissions
        s_user = UserFactory()
        SubmissionFactory(author=s_user, challenge=self.challenge)  # should get ignored
        top_submission = SubmissionFactory(author=s_user, challenge=self.challenge, result_score=51)
        # Third user with equal to first submission
        t_user = UserFactory()
        tr_sub = SubmissionFactory(challenge=self.challenge, author=t_user, result_score=50)

        expected_submissions = [top_submission, f_submission, tr_sub]  # ordered by score, then by date (oldest first)

        received_submissions = list(Submission.fetch_top_submissions_for_challenge(self.challenge.id))
        self.assertEqual(expected_submissions, received_submissions)
Esempio n. 3
0
 def test_fetch_top_submissions_no_submissions_should_be_empty(self):
     received_submissions = list(Submission.fetch_top_submissions_for_challenge(self.challenge.id))
     self.assertEqual([], received_submissions)