コード例 #1
0
    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='******')
        f = ContentFile(b'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.assertTrue(self.client.login(username='******'))
        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')
コード例 #2
0
 def test_fields_autogeneration(self):
     contest = Contest()
     contest.save()
     self.assertEqual(contest.id, 'c1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 2')
     problem = Problem()
     problem.save()
     pi = ProblemInstance(round=round, problem=problem)
     pi.save()
     self.assertEqual(pi.contest, contest)