Пример #1
0
    def setUp(self):
        self.client = Client()

        self.user = User.objects.create_user('test_user', '*****@*****.**', 'secret')
        self.user.save()

        self.team = Team(name='team', is_active=True)
        self.team.save()
        self.team.members.add(self.user)
        self.team.save()

        self.user0 = User.objects.create_user('test_user0', '*****@*****.**', 'secret')
        self.user0.save()

        self.team0 = Team(name='team0', is_active=True)
        self.team0.save()
        self.team0.members.add(self.user0)
        self.team0.save()

        self.category = Category(name='category')
        self.category.save()

        self.challenge = Challenge(category=self.category,
                                   name='challenge', key='12345')
        self.challenge.save()
Пример #2
0
    def setUp(self):
        self.now = timezone.now()

        self.client = ValidatingClient()

        self.user = User.objects.create_user('test_user', '*****@*****.**', 'secret')
        self.user.save()
        self.client.login(username='******', password='******')

        self.team = Team(name='team', is_active=True)
        self.team.save()
        self.team.members.add(self.user)
        self.team.save()

        self.user0 = User.objects.create_user('test_user0', '*****@*****.**', 'secret')
        self.user0.save()

        self.team0 = Team(name='team0', is_active=True)
        self.team0.save()
        self.team0.members.add(self.user0)
        self.team0.save()

        self.category = Category(name='category')
        self.category.save()

        self.challenge = Challenge(category=self.category,
                                   name='challenge', key='12345')
        self.challenge.save()

        self.validation = Validation(date=self.now,
                                     user=self.user,
                                     team=self.team,
                                     challenge=self.challenge)
        self.validation.save()

        self.validation0 = Validation(date=self.now,
                                     user=self.user0,
                                     team=self.team0,
                                     challenge=self.challenge)
        self.validation0.save()
Пример #3
0
class CheckLoggedUserPages(TestCase):
    """Check if a logged user can access to private and public pages."""
    def setUp(self):
        self.now = timezone.now()

        self.client = ValidatingClient()

        self.user = User.objects.create_user('test_user', '*****@*****.**', 'secret')
        self.user.save()
        self.client.login(username='******', password='******')

        self.team = Team(name='team', is_active=True)
        self.team.save()
        self.team.members.add(self.user)
        self.team.save()

        self.user0 = User.objects.create_user('test_user0', '*****@*****.**', 'secret')
        self.user0.save()

        self.team0 = Team(name='team0', is_active=True)
        self.team0.save()
        self.team0.members.add(self.user0)
        self.team0.save()

        self.category = Category(name='category')
        self.category.save()

        self.challenge = Challenge(category=self.category,
                                   name='challenge', key='12345')
        self.challenge.save()

        self.validation = Validation(date=self.now,
                                     user=self.user,
                                     team=self.team,
                                     challenge=self.challenge)
        self.validation.save()

        self.validation0 = Validation(date=self.now,
                                     user=self.user0,
                                     team=self.team0,
                                     challenge=self.challenge)
        self.validation0.save()

    def tearDown(self):
        self.validation0.delete()
        self.validation.delete()

        self.team0.delete()
        self.user0.delete()

        self.team.delete()
        self.user.delete()

        self.challenge.delete()
        self.category.delete()

    def test_logged_user_accounts_logout(self):
        response = self.client.get('/accounts/logout/')
        self.assertEqual(response.status_code, 200)

    def test_logged_user_accounts_settings(self):
        response = self.client.get('/accounts/settings/')
        self.assertEqual(response.status_code, 200)

    def test_logged_user_accounts_password(self):
        response = self.client.get('/accounts/password/')
        self.assertEqual(response.status_code, 200)

    def test_logged_user_accounts_delete(self):
        response = self.client.get('/accounts/delete/')
        self.assertEqual(response.status_code, 200)

    def test_logged_user_homepage(self):
        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

    def test_logged_user_team_list(self):
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            self.team.delete()
            response = self.client.get(reverse('team_list'))
            self.assertEqual(response.status_code, 200)
            self.team.save()

        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('team_list'))
            self.assertEqual(response.status_code, 200)

    def test_logged_user_team_create_with_a_team(self):
        response = self.client.get(reverse('team_create'), follow=True)
        self.assertRedirects(response, '/?next=/team/create/',
                             status_code=302, target_status_code=200)

    def test_logged_user_team_quit(self):
        response = self.client.get('/team/quit/1/')
        self.assertEqual(response.status_code, 200)

    def test_logged_user_non_existing_team_quit(self):
        response = self.client.get('/team/quit/10/')
        self.assertEqual(response.status_code, 404)

    def test_logged_user_contestant_list(self):
        response = self.client.get(reverse('contestant_list'))
        self.assertEqual(response.status_code, 200)

    def test_logged_user_challenge_list(self):
        response = self.client.get(reverse('challenges'))
        self.assertEqual(response.status_code, 200)

    def test_logged_user_ranking_list(self):
        response = self.client.get(reverse('ranking'))
        self.assertEqual(response.status_code, 200)

    def test_logged_user_rules(self):
        response = self.client.get(reverse('rules'))
        self.assertEqual(response.status_code, 200)

    def test_logged_user_about(self):
        response = self.client.get(reverse('about'))
        self.assertEqual(response.status_code, 200)
Пример #4
0
class CheckValidatingChallenge(TestCase):
    def setUp(self):
        self.client = Client()

        self.user = User.objects.create_user('test_user', '*****@*****.**', 'secret')
        self.user.save()

        self.team = Team(name='team', is_active=True)
        self.team.save()
        self.team.members.add(self.user)
        self.team.save()

        self.user0 = User.objects.create_user('test_user0', '*****@*****.**', 'secret')
        self.user0.save()

        self.team0 = Team(name='team0', is_active=True)
        self.team0.save()
        self.team0.members.add(self.user0)
        self.team0.save()

        self.category = Category(name='category')
        self.category.save()

        self.challenge = Challenge(category=self.category,
                                   name='challenge', key='12345')
        self.challenge.save()

    def tearDown(self):
        self.challenge.delete()
        self.category.delete()
        self.team.delete()
        self.user.delete()
        self.team0.delete()
        self.user0.delete()

    def test_unlogged_attempt_challenge(self):
        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, '/accounts/login/?next=/validate/1/',
                                 status_code=302, target_status_code=200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, '/accounts/login/?next=/validate/1/',
                                 status_code=302, target_status_code=200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, '/accounts/login/?next=/validate/1/',
                                 status_code=302, target_status_code=200)

    def test_invalid_get_challenge(self):
        self.client.login(username='******', password='******')

        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get('/validate/1/')
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

    def test_invalid_challenge(self):
        self.client.login(username='******', password='******')

        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.post('/validate/1/', {'key' : '1'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.post('/validate/1/', {'key' : '1'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.post('/validate/1/', {'key' : '1'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

    def test_validate_breakthrought_challenge(self):
        self.client.login(username='******', password='******')

        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

    def test_validate_normal_challenge(self):
        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            # First validation (breakthrough)
            self.client.login(username='******', password='******')

            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)
            self.client.logout()
            # Second validation (normal)
            self.client.login(username='******', password='******')

            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)

            # Re-validation (normal)
            self.client.login(username='******', password='******')

            response = self.client.post('/validate/1/', {'key' : '12345'})
            self.assertRedirects(response, reverse('challenges'),
                                 status_code=302, target_status_code=200)
Пример #5
0
class CheckPublicPages(TestCase):
    """Check if all public pages are accessible to anonymous users."""
    def setUp(self):
        self.now = timezone.now()

        self.client = ValidatingClient()
        self.user = User.objects.create_user('test_user', '*****@*****.**', 'secret')
        self.user.save()

        self.team = Team(name='team', is_active=True)
        self.team.save()
        self.team.members.add(self.user)
        self.team.save()

        self.category = Category(name='category')
        self.category.save()

        self.challenge = Challenge(category=self.category,
                                   name='challenge', key='12345')
        self.challenge.save()

        self.validation = Validation(date=timezone.now(),
                                     user=self.user,
                                     team=self.team,
                                     challenge=self.challenge)
        self.validation.save()

    def tearDown(self):
        self.validation.delete()

        self.team.delete()
        self.user.delete()

        self.challenge.delete()
        self.category.delete()

    def test_public_homepage(self):
        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.get(reverse('home'))
            self.assertEqual(response.status_code, 200)

    def test_public_team_list_empty(self):
        self.team.delete()

        response = self.client.get(reverse('team_list'))
        self.assertEqual(response.status_code, 200)

        self.team.save()

    def test_public_team_list(self):
        response = self.client.get(reverse('team_list'))
        self.assertEqual(response.status_code, 200)

    def test_public_team_1(self):
        response = self.client.get('/team/1/')
        self.assertEqual(response.status_code, 200)

    def test_public_contestant_list_empty(self):
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            self.user.delete()

            response = self.client.get(reverse('contestant_list'))
            self.assertEqual(response.status_code, 200)

        self.user.save()

    def test_public_contestant_list(self):
        response = self.client.get(reverse('contestant_list'))
        self.assertEqual(response.status_code, 200)

    def test_public_contestant_1(self):
        response = self.client.get('/contestant/1/')
        self.assertEqual(response.status_code, 200)

    def test_public_challenge_list_empty(self):
        self.challenge.delete()

        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

        self.challenge.save()

    def test_public_challenge_list(self):
        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.get(reverse('challenges'))
            self.assertEqual(response.status_code, 200)

    def test_public_ranking_list_empty(self):
        self.validation.delete()
        self.team.is_active = False
        self.team.save()

        response = self.client.get(reverse('ranking'))
        self.assertEqual(response.status_code, 200)

        self.team.is_active = True
        self.team.save()
        self.validation.save()

    def test_public_ranking_list(self):
        # Before contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_after(),
                           CONTEST_END_DATE=two_days_after()):
            response = self.client.get(reverse('ranking'))
            self.assertEqual(response.status_code, 200)

        # During contest
        with self.settings(CONTEST_BEGIN_DATE=one_day_before(),
                           CONTEST_END_DATE=one_day_after()):
            response = self.client.get(reverse('ranking'))
            self.assertEqual(response.status_code, 200)

        # After contest
        with self.settings(CONTEST_BEGIN_DATE=two_days_before(),
                           CONTEST_END_DATE=one_day_before()):
            response = self.client.get(reverse('ranking'))
            self.assertEqual(response.status_code, 200)

    def test_public_rules(self):
        response = self.client.get(reverse('rules'))
        self.assertEqual(response.status_code, 200)

    def test_public_about(self):
        response = self.client.get(reverse('about'))
        self.assertEqual(response.status_code, 200)

    def test_public_login(self):
        response = self.client.get('/accounts/login/')
        self.assertEqual(response.status_code, 200)

    def test_public_account_signup(self):
        response = self.client.get('/accounts/signup/')
        self.assertEqual(response.status_code, 200)