def test_list(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, enabled=True, teams_list_visible='PUBLIC') tconf.save() response = self.client.get(reverse('teams_list', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('<li>test_team</li>', response.content) self.assertIn('<li>Test Team1</li>', response.content) self.assertIn('<li>Test Team2</li>', response.content)
def test_list(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, enabled=True, teams_list_visible='PUBLIC') tconf.save() response = self.client.get(reverse('teams_list', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('test_team', response.content) self.assertIn('Test Team1', response.content) self.assertIn('Test Team2', response.content)
def test_list(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, enabled=True, teams_list_visible='PUBLIC') tconf.save() response = self.client.get(reverse('teams_list', kwargs={'contest_id': contest.id}), follow=True) self.assertContains(response, 'test_team') self.assertContains(response, 'Test Team1') self.assertContains(response, 'Test Team2')
def test_permissions(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, modify_begin_date=datetime(2012, 1, 1, 8, tzinfo=utc), modify_end_date=datetime(2012, 1, 1, 12, tzinfo=utc), enabled=True) tconf.save() user = User.objects.get(username='******') factory = RequestFactory() request = factory.request() request.contest = contest request.user = user timestamp = datetime(2012, 1, 1, 10, tzinfo=utc) with fake_time(timestamp): request.timestamp = timestamp self.assertEqual(contest.controller.can_modify_team(request), True) self.assertEqual(can_join_team(request), True) self.assertEqual(can_quit_team(request), False) self.assertEqual(can_delete_team(request), False) self.assertEqual(can_create_team(request), True) team = create_team('test_team', 'Super Team!', contest) tm = TeamMembership(team=team, user=user) tm.save() self.assertEqual(can_join_team(request), False) self.assertEqual(can_quit_team(request), False) self.assertEqual(can_delete_team(request), True) self.assertEqual(can_create_team(request), False) user2 = User.objects.get(username='******') tm = TeamMembership(team=team, user=user2) tm.save() self.assertEqual(can_join_team(request), False) self.assertEqual(can_quit_team(request), True) self.assertEqual(can_delete_team(request), False) self.assertEqual(can_create_team(request), False) self.client.login(username='******') problem_instance = ProblemInstance.objects.get() self.submit_file(contest, problem_instance, user=team.user) self.assertEqual(can_quit_team(request), False)
def test_views(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, modify_begin_date=datetime(2012, 1, 1, 8, tzinfo=utc), modify_end_date=datetime(2012, 1, 1, 12, tzinfo=utc), enabled=True) tconf.save() timestamp = datetime(2012, 1, 1, 10, tzinfo=utc) with fake_time(timestamp): self.client.login(username='******') response = self.client.get(reverse( 'default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Team', response.content) response = self.client.get(reverse( 'team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Create a team', response.content) user = User.objects.get(username='******') team = create_team('test_team', 'Super Team!', contest) tm = TeamMembership(team=team, user=user) tm.save() response = self.client.get(reverse( 'team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Super Team!', response.content) self.assertIn('delete the team', response.content) user2 = User.objects.get(username='******') tm = TeamMembership(team=team, user=user2) tm.save() response = self.client.get(reverse( 'team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Super Team!', response.content) self.assertIn('Leave the team', response.content)
def test_visibility_public(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, enabled=True, teams_list_visible='PUBLIC') tconf.save() response = self.client.get(reverse('default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Teams', response.content) self.client.login(username='******') response = self.client.get(reverse('default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Teams', response.content)
def test_visibility_yes(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, enabled=True, teams_list_visible='YES') tconf.save() response = self.client.get(reverse('default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertNotContains(response, 'Teams') self.assertTrue(self.client.login(username='******')) response = self.client.get(reverse('default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertContains(response, 'Teams')
def test_views(self): contest = Contest.objects.get() tconf = TeamsConfig(contest=contest, modify_begin_date=datetime(2012, 1, 1, 8, tzinfo=utc), modify_end_date=datetime(2012, 1, 1, 12, tzinfo=utc), enabled=True) tconf.save() timestamp = datetime(2012, 1, 1, 10, tzinfo=utc) with fake_time(timestamp): self.client.login(username='******') response = self.client.get(reverse('default_contest_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Team', response.content) response = self.client.get(reverse('team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Create a team', response.content) user = User.objects.get(username='******') team = create_team('test_team', 'Super Team!', contest) tm = TeamMembership(team=team, user=user) tm.save() response = self.client.get(reverse('team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Super Team!', response.content) self.assertIn('delete the team', response.content) user2 = User.objects.get(username='******') tm = TeamMembership(team=team, user=user2) tm.save() response = self.client.get(reverse('team_view', kwargs={'contest_id': contest.id}), follow=True) self.assertIn('Super Team!', response.content) self.assertIn('Leave the team', response.content)