def test_none_school(self): user2 = User.objects.get(username='******') contest = Contest.objects.get() contest.controller_name = \ "oioioi.oi.controllers.OIContestController" contest.save() url = reverse('participants_data', kwargs={'contest_id': contest.id}) perm = ContestPermission(user=user2, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user2, '_contest_perms_cache'): delattr(user2, '_contest_perms_cache') self.client.login(username='******') try: self.register(contest) p_data = Participant.objects.get(user=user2).registration_model p_data.school = None p_data.save() response = self.client.get(url) self.assertEqual(response.status_code, 200) finally: self.client.logout()
def test_privilege_manipulation(self): self.assertTrue( self.observer.has_perm('contests.contest_observer', self.contest)) self.assertFalse( self.observer.has_perm('contests.contest_admin', self.contest)) self.assertFalse( self.cadmin.has_perm('contests.contest_observer', self.contest)) self.assertTrue( self.cadmin.has_perm('contests.contest_admin', self.contest)) test_user = User.objects.get(username='******') self.assertFalse( test_user.has_perm('contests.contest_observer', self.contest)) self.assertFalse( test_user.has_perm('contests.contest_admin', self.contest)) ContestPermission(user=test_user, contest=self.contest, permission='contests.contest_observer').save() self.assertTrue( test_user.has_perm('contests.contest_observer', self.contest)) ContestPermission(user=test_user, contest=self.contest, permission='contests.contest_admin').save() self.assertTrue( test_user.has_perm('contests.contest_observer', self.contest))
def test_none_school(self): user2 = User.objects.get(username='******') contest = Contest.objects.get() contest.controller_name = "oioioi.oi.controllers.OIContestController" contest.save() url = reverse('participants_data', kwargs={'contest_id': contest.id}) perm = ContestPermission(user=user2, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user2, '_contest_perms_cache'): delattr(user2, '_contest_perms_cache') self.assertTrue(self.client.login(username='******')) try: self.register(contest) p_data = Participant.objects.get(user=user2).registration_model p_data.school = None p_data.save() response = self.client.get(url) self.assertEqual(response.status_code, 200) finally: self.client.logout()
def test_contest_admin_with_participant(self): self.c2.controller_name = ( 'oioioi.participants.tests.ParticipantsContestController') self.c2.save() ContestPermission(user=self.user, contest=self.c1, permission='contests.contest_admin').save() Participant(user=self.user, contest=self.c2).save() ex_conf1 = ExclusivenessConfig() ex_conf1.contest = self.c1 ex_conf1.start_date = datetime(2012, 1, 1, 8, tzinfo=utc) ex_conf1.end_date = datetime(2012, 1, 1, 12, tzinfo=utc) ex_conf1.save() ex_conf2 = ExclusivenessConfig() ex_conf2.contest = self.c2 ex_conf2.start_date = datetime(2012, 1, 1, 8, tzinfo=utc) ex_conf2.end_date = datetime(2012, 1, 1, 12, tzinfo=utc) ex_conf2.save() self.assertTrue(self.client.login(username='******')) with fake_time(datetime(2012, 1, 1, 10, tzinfo=utc)): self._assertContestVisible('c2') self._assertContestRedirects('c1', '/c/c2')
def make_user_contest_admin(user, contest): cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = contest cp.save() contest.refresh_from_db()
def test_no_email_data_view(self): contest = Contest.objects.get() contest.controller_name = \ 'oioioi.participants.tests.ParticipantsContestController' contest.save() user = User.objects.get(username='******') url = reverse('participants_data', kwargs={'contest_id': contest.id}) perm = ContestPermission(user=user, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user, '_contest_perms_cache'): delattr(user, '_contest_perms_cache') self.assertTrue(self.client.login(username='******')) self.register(contest) response = self.client.get(url) self.assertNotContains(response, '<td>email address</td>')
def test_no_email_data_view(self): contest = Contest.objects.get() contest.controller_name = ( 'oioioi.participants.tests.ParticipantsContestController') contest.save() user = User.objects.get(username='******') url = reverse('participants_data', kwargs={'contest_id': contest.id}) perm = ContestPermission(user=user, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user, '_contest_perms_cache'): delattr(user, '_contest_perms_cache') self.assertTrue(self.client.login(username='******')) self.register(contest) response = self.client.get(url) self.assertNotContains(response, '<td>email address</td>')
def test_data_view(self): contest = Contest.objects.get() contest.controller_name = \ "oioioi.oi.controllers.OIContestController" contest.save() user = User.objects.get(username='******') url = reverse('participants_data', kwargs={'contest_id': contest.id}) self.client.login(username='******') try: response = self.client.get(url) self.assertEqual(response.status_code, 403) self.client.logout() perm = ContestPermission(user=user, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user, '_contest_perms_cache'): delattr(user, '_contest_perms_cache') self.client.login(username='******') response = self.client.get(url) self.assertIn('no participants', response.content) self.register(contest) response = self.client.get(url) self.assertIn('<td>{}</td>'.format(user.id), response.content) self.assertIn('<td>The Castle</td>', response.content) self.assertIn('<td>31-337</td>', response.content) self.assertIn('<td>Camelot</td>', response.content) self.assertIn('<td>000-000-000</td>', response.content) self.assertIn('<td>1975-05-25</td>', response.content) self.assertIn('<td>L</td>', response.content) finally: self.client.logout()
def test_data_view(self): contest = Contest.objects.get() contest.controller_name = \ "oioioi.oi.controllers.OIContestController" contest.save() user = User.objects.get(username='******') url = reverse('participants_data', kwargs={'contest_id': contest.id}) self.assertTrue(self.client.login(username='******')) try: response = self.client.get(url) self.assertEqual(response.status_code, 403) self.client.logout() perm = ContestPermission(user=user, contest=contest, permission='contests.personal_data') perm.save() if hasattr(user, '_contest_perms_cache'): delattr(user, '_contest_perms_cache') self.assertTrue(self.client.login(username='******')) response = self.client.get(url) self.assertContains(response, 'no participants') self.register(contest) response = self.client.get(url) self.assertContains(response, '<td>{}</td>'.format(user.id)) self.assertContains(response, '<td>The Castle</td>') self.assertContains(response, '<td>31-337</td>') self.assertContains(response, '<td>Camelot</td>') self.assertContains(response, '<td>000-000-000</td>') self.assertContains(response, '<td>1975-05-25</td>') self.assertContains(response, '<td>L</td>') finally: self.client.logout()
def change_contest_type(): c = Contest.objects.get(id='c') c.controller_name = \ 'oioioi.teachers.controllers.TeacherContestController' c.save() user = User.objects.get(username='******') cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = c cp.save() return c
def test_admin_permissions(self): url = reverse('oioioiadmin:contests_contest_changelist') self.client.login(username='******') check_not_accessible(self, url) self.client.login(username='******') response = self.client.get(url) self.assertEqual(response.status_code, 200) # without set request.contest url = reverse('oioioiadmin:contests_probleminstance_changelist') self.client.login(username='******') check_not_accessible(self, url) self.client.login(username='******') response = self.client.get(url) self.assertEqual(response.status_code, 403) c = Contest.objects.create( id='test_contest', controller_name='oioioi.programs.controllers.' 'ProgrammingContestController', name='Test contest') # with request.contest url = reverse('oioioiadmin:contests_probleminstance_changelist') self.client.login(username='******') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.client.login(username='******') check_not_accessible(self, url) user = User.objects.get(username='******') ContestPermission(user=user, contest=c, permission='contests.contest_admin').save() response = self.client.get(url) self.assertEqual(response.status_code, 200)
def login(self, get_problems): c = Contest.objects.get(id='c') c.controller_name = 'oioioi.teachers.controllers.TeacherContestController' c.save() user = User.objects.get(username='******') cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = c cp.save() self.assertTrue(self.client.login(username='******')) self.client.get('/c/c/') if get_problems: pi = ProblemInstance.objects.filter(contest=c)[0] p = pi.problem return (pi, p) return c
def test_user_dashboard_full(self): user = User.objects.get(username='******') for i in range(10): c = Contest() c.name = 'tmp' + str(i) c.controller_name = \ 'oioioi.teachers.controllers.TeacherContestController' c.id = 'tmp' + str(i) c.save() cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = c cp.save() self.assertTrue(self.client.login(username='******')) url = reverse('simpleui_user_dashboard') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Show all contests')
def login(self, get_problems): c = Contest.objects.get(id='c') c.controller_name = \ 'oioioi.teachers.controllers.TeacherContestController' c.save() user = User.objects.get(username='******') cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = c cp.save() self.assertTrue(self.client.login(username='******')) self.client.get('/c/c/') if get_problems: pi = ProblemInstance.objects.filter(contest=c)[0] p = pi.problem return (pi, p) return c
def test_teacher_dashboard_full(self): user = User.objects.get(username='******') for i in range(10): c = Contest() c.name = 'tmp' + str(i) c.controller_name = \ 'oioioi.teachers.controllers.TeacherContestController' c.id = 'tmp' + str(i) c.save() cp = ContestPermission() cp.user = user cp.permission = 'contests.contest_admin' cp.contest = c cp.save() self.assertTrue(self.client.login(username='******')) url = reverse('teacher_dashboard') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Show all contests')