Ejemplo n.º 1
0
    def test_attachments(self):
        contest = Contest.objects.get()
        problem = Problem.objects.get()
        ca = ContestAttachment(contest=contest,
                description='contest-attachment',
                content=ContentFile('content-of-conatt', name='conatt.txt'))
        ca.save()
        pa = ProblemAttachment(problem=problem,
                description='problem-attachment',
                content=ContentFile('content-of-probatt', name='probatt.txt'))
        pa.save()

        self.client.login(username='******')
        response = self.client.get(reverse('contest_files',
            kwargs={'contest_id': contest.id}))
        self.assertEqual(response.status_code, 200)
        for part in ['contest-attachment', 'conatt.txt', 'problem-attachment',
                'probatt.txt']:
            self.assertIn(part, response.content)
        response = self.client.get(reverse('contest_attachment',
            kwargs={'contest_id': contest.id, 'attachment_id': ca.id}))
        self.assertEqual(response.content, 'content-of-conatt')
        response = self.client.get(reverse('problem_attachment',
            kwargs={'contest_id': contest.id, 'attachment_id': pa.id}))
        self.assertEqual(response.content, 'content-of-probatt')
Ejemplo n.º 2
0
    def test_attachments(self):
        contest = Contest.objects.get()
        problem = Problem.objects.get()
        ca = ContestAttachment(contest=contest,
                description='contest-attachment',
                content=ContentFile('content-of-conatt', name='conatt.txt'))
        ca.save()
        pa = ProblemAttachment(problem=problem,
                description='problem-attachment',
                content=ContentFile('content-of-probatt', name='probatt.txt'))
        pa.save()
        round = Round.objects.get(pk=1)
        ra = ContestAttachment(contest=contest, description='round-attachment',
                content=ContentFile('content-of-roundatt', name='roundatt.txt'),
                round=round)
        ra.save()

        self.client.login(username='******')
        response = self.client.get(reverse('contest_files',
            kwargs={'contest_id': contest.id}))
        self.assertEqual(response.status_code, 200)
        for part in ['contest-attachment', 'conatt.txt', 'problem-attachment',
                     'probatt.txt', 'round-attachment', 'roundatt.txt']:
            self.assertIn(part, response.content)
        response = self.client.get(reverse('contest_attachment',
            kwargs={'contest_id': contest.id, 'attachment_id': ca.id}))
        self.assertStreamingEqual(response, 'content-of-conatt')
        response = self.client.get(reverse('problem_attachment',
            kwargs={'contest_id': contest.id, 'attachment_id': pa.id}))
        self.assertStreamingEqual(response, 'content-of-probatt')
        response = self.client.get(reverse('contest_attachment',
            kwargs={'contest_id': contest.id, 'attachment_id': ra.id}))
        self.assertStreamingEqual(response, 'content-of-roundatt')

        with fake_time(datetime(2011, 7, 10, tzinfo=utc)):
            response = self.client.get(reverse('contest_files',
                kwargs={'contest_id': contest.id}))
            self.assertEqual(response.status_code, 200)
            for part in ['contest-attachment', 'conatt.txt']:
                self.assertIn(part, response.content)
            for part in ['problem-attachment', 'probatt.txt',
                         'round-attachment', 'roundatt.txt']:
                self.assertNotIn(part, response.content)
            response = self.client.get(reverse('contest_attachment',
                kwargs={'contest_id': contest.id, 'attachment_id': ca.id}))
            self.assertStreamingEqual(response, 'content-of-conatt')
            check_not_accessible(self, 'problem_attachment',
                 kwargs={'contest_id': contest.id, 'attachment_id': pa.id})
            check_not_accessible(self, 'contest_attachment',
                 kwargs={'contest_id': contest.id, 'attachment_id': ra.id})
Ejemplo n.º 3
0
    def test_attachments(self):
        contest = Contest.objects.get()
        problem = Problem.objects.get()
        ca = ContestAttachment(contest=contest,
                               description='contest-attachment',
                               content=ContentFile('content-of-conatt',
                                                   name='conatt.txt'))
        ca.save()
        pa = ProblemAttachment(problem=problem,
                               description='problem-attachment',
                               content=ContentFile('content-of-probatt',
                                                   name='probatt.txt'))
        pa.save()
        round = Round.objects.get(pk=1)
        ra = ContestAttachment(contest=contest,
                               description='round-attachment',
                               content=ContentFile('content-of-roundatt',
                                                   name='roundatt.txt'),
                               round=round)
        ra.save()

        self.client.login(username='******')
        response = self.client.get(
            reverse('contest_files', kwargs={'contest_id': contest.id}))
        self.assertEqual(response.status_code, 200)
        for part in [
                'contest-attachment', 'conatt.txt', 'problem-attachment',
                'probatt.txt', 'round-attachment', 'roundatt.txt'
        ]:
            self.assertIn(part, response.content)
        response = self.client.get(
            reverse('contest_attachment',
                    kwargs={
                        'contest_id': contest.id,
                        'attachment_id': ca.id
                    }))
        self.assertStreamingEqual(response, 'content-of-conatt')
        response = self.client.get(
            reverse('problem_attachment',
                    kwargs={
                        'contest_id': contest.id,
                        'attachment_id': pa.id
                    }))
        self.assertStreamingEqual(response, 'content-of-probatt')
        response = self.client.get(
            reverse('contest_attachment',
                    kwargs={
                        'contest_id': contest.id,
                        'attachment_id': ra.id
                    }))
        self.assertStreamingEqual(response, 'content-of-roundatt')

        with fake_time(datetime(2011, 7, 10, tzinfo=utc)):
            response = self.client.get(
                reverse('contest_files', kwargs={'contest_id': contest.id}))
            self.assertEqual(response.status_code, 200)
            for part in ['contest-attachment', 'conatt.txt']:
                self.assertIn(part, response.content)
            for part in [
                    'problem-attachment', 'probatt.txt', 'round-attachment',
                    'roundatt.txt'
            ]:
                self.assertNotIn(part, response.content)
            response = self.client.get(
                reverse('contest_attachment',
                        kwargs={
                            'contest_id': contest.id,
                            'attachment_id': ca.id
                        }))
            self.assertStreamingEqual(response, 'content-of-conatt')
            check_not_accessible(self,
                                 'problem_attachment',
                                 kwargs={
                                     'contest_id': contest.id,
                                     'attachment_id': pa.id
                                 })
            check_not_accessible(self,
                                 'contest_attachment',
                                 kwargs={
                                     'contest_id': contest.id,
                                     'attachment_id': ra.id
                                 })