Example #1
0
    def test_reset_password_post_success(self):
        """
            test a post request to the reset password view successfully
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 30)
        post_dict = {'password': '******', 're_password': '******'}

        url = reverse('authentication.views.reset_password')
        resp = self.client.post(url, post_dict, follow=True)
        resp_url = (resp.__dict__.get('redirect_chain')[0])[0]
        parsed_url = urlparse(resp_url)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(parsed_url.path, '/login/')
Example #2
0
    def test_validate_answer_post_timeout(self):
        """
            test a post request to the validate answer view where the cached user id times out
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 0.0000001)
        post_dict = {'secret_answer': 'Test Answer'}

        url = reverse('authentication.views.validate_answer')
        resp = self.client.post(url, post_dict, follow=True)
        resp_url = (resp.__dict__.get('redirect_chain')[0])[0]
        parsed_url = urlparse(resp_url)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(parsed_url.path, '/resetpassword/forgotpassword/')
Example #3
0
    def test_reset_password_get(self):
        """
            test a get request to the reset password view
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 30)

        url = reverse('authentication.views.reset_password')
        resp = self.client.get(url, follow=True)

        self.assertEqual(resp.status_code, 200)
Example #4
0
    def test_reset_password_post_timeout(self):
        """
            test a post request to the reset password view failing bc of timeout
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 0.000001)
        post_dict = {'password': '******', 're_password': '******'}

        url = reverse('authentication.views.reset_password')
        resp = self.client.post(url, post_dict, follow=True)

        self.assertEqual(resp.status_code, 200)
Example #5
0
    def test_validate_answer_post_incorrect(self):
        """
            test a post request to the validate answer view with a incorrect answer
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 30)
        post_dict = {'secret_answer': 'Test Wrong Answer'}

        url = reverse('authentication.views.validate_answer')
        resp = self.client.post(url, post_dict, follow=True)

        self.assertEqual(resp.status_code, 200)
Example #6
0
    def test_forgot_password_post_no_user(self):
        """
            test a post request to the forgot password view for an non existing user
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        post_dict = {'username': '******'}

        url = reverse('authentication.views.forgot_password')
        resp = self.client.post(url, post_dict, follow=True)
        resp_url = (resp.__dict__.get('redirect_chain')[0])[0]
        parsed_url = urlparse(resp_url)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(parsed_url.path, '/forgotpassword/')
Example #7
0
    def test_create_security_answer(self):
        """
            Test creation of a security answer record

        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        security_question = fixtures.create_security_question(question='Test question?')

        security_answer = fixtures.create_secret_answer(
            user_id=user.id, question_id=security_question.id, answer='Test Answer'
        )

        self.assertTrue(isinstance(security_answer, SecurityAnswer))