Files
edx-platform/common/djangoapps/student/tests/test_long_username_email.py
Uman Shahzad cb034d4f2f Implement client-side registration form validation.
Input forms that need validation will have AJAX requests
performed to get validation decisions live.

All but a few important and common form fields perform
generic validation; these will need a back-end handler
in the future in order to have them validated through AJAX requests.

Information is conveyed on focus and blur for both
errors and successes.
2017-08-03 00:22:25 +05:00

61 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
import json
from django.core.urlresolvers import reverse
from django.test import TestCase
from openedx.core.djangoapps.user_api.accounts import USERNAME_BAD_LENGTH_MSG
class TestLongUsernameEmail(TestCase):
def setUp(self):
super(TestLongUsernameEmail, self).setUp()
self.url = reverse('create_account')
self.url_params = {
'username': 'username',
'email': 'foo_bar' + '@bar.com',
'name': 'foo bar',
'password': '123',
'terms_of_service': 'true',
'honor_code': 'true',
}
def test_long_username(self):
"""
Test username cannot be more than 30 characters long.
"""
self.url_params['username'] = 'username' * 4
response = self.client.post(self.url, self.url_params)
# Status code should be 400.
self.assertEqual(response.status_code, 400)
obj = json.loads(response.content)
self.assertEqual(
obj['value'],
USERNAME_BAD_LENGTH_MSG,
)
def test_long_email(self):
"""
Test email cannot be more than 254 characters long.
"""
self.url_params['email'] = '{email}@bar.com'.format(email='foo_bar' * 36)
response = self.client.post(self.url, self.url_params)
# Assert that we get error when email has more than 254 characters.
self.assertGreater(len(self.url_params['email']), 254)
# Status code should be 400.
self.assertEqual(response.status_code, 400)
obj = json.loads(response.content)
self.assertEqual(
obj['value'],
"Email cannot be more than 254 characters long",
)