API & Client - update username max length
This commit is contained in:
		@@ -93,7 +93,7 @@ class TestUserRegistration(ApiTestCaseMixin):
 | 
			
		||||
            '/api/auth/register',
 | 
			
		||||
            data=json.dumps(
 | 
			
		||||
                dict(
 | 
			
		||||
                    username='t',
 | 
			
		||||
                    username='',
 | 
			
		||||
                    email='test@test.com',
 | 
			
		||||
                    password='12345678',
 | 
			
		||||
                    password_conf='12345678',
 | 
			
		||||
@@ -102,17 +102,25 @@ class TestUserRegistration(ApiTestCaseMixin):
 | 
			
		||||
            content_type='application/json',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assert_400(response, "username: 3 to 12 characters required\n")
 | 
			
		||||
        self.assert_400(
 | 
			
		||||
            response,
 | 
			
		||||
            (
 | 
			
		||||
                'username: 3 to 30 characters required\n'
 | 
			
		||||
                'username: only alphanumeric characters and '
 | 
			
		||||
                'the underscore character "_" allowed\n'
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_username_is_too_long(
 | 
			
		||||
        self, app: Flask
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
        response = client.post(
 | 
			
		||||
            '/api/auth/register',
 | 
			
		||||
            data=json.dumps(
 | 
			
		||||
                dict(
 | 
			
		||||
                    username='testestestestestest',
 | 
			
		||||
                    username='a' * 31,
 | 
			
		||||
                    email='test@test.com',
 | 
			
		||||
                    password='12345678',
 | 
			
		||||
                    password_conf='12345678',
 | 
			
		||||
@@ -121,7 +129,38 @@ class TestUserRegistration(ApiTestCaseMixin):
 | 
			
		||||
            content_type='application/json',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assert_400(response, "username: 3 to 12 characters required\n")
 | 
			
		||||
        self.assert_400(response, "username: 3 to 30 characters required\n")
 | 
			
		||||
 | 
			
		||||
    @pytest.mark.parametrize(
 | 
			
		||||
        'input_description,input_username',
 | 
			
		||||
        [
 | 
			
		||||
            ('account_handle', '@sam@example.com'),
 | 
			
		||||
            ('with special characters', 'sam*'),
 | 
			
		||||
        ],
 | 
			
		||||
    )
 | 
			
		||||
    def test_it_returns_error_if_username_is_invalid(
 | 
			
		||||
        self, app: Flask, input_description: str, input_username: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
        response = client.post(
 | 
			
		||||
            '/api/auth/register',
 | 
			
		||||
            data=json.dumps(
 | 
			
		||||
                dict(
 | 
			
		||||
                    username=input_username,
 | 
			
		||||
                    email='test@test.com',
 | 
			
		||||
                    password='12345678',
 | 
			
		||||
                    password_conf='12345678',
 | 
			
		||||
                )
 | 
			
		||||
            ),
 | 
			
		||||
            content_type='application/json',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assert_400(
 | 
			
		||||
            response,
 | 
			
		||||
            'username: only alphanumeric characters and '
 | 
			
		||||
            'the underscore character "_" allowed\n',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_email_is_invalid(self, app: Flask) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
@@ -261,24 +300,6 @@ class TestUserRegistration(ApiTestCaseMixin):
 | 
			
		||||
 | 
			
		||||
        self.assert_400(response)
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_username_is_invalid(self, app: Flask) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
        response = client.post(
 | 
			
		||||
            '/api/auth/register',
 | 
			
		||||
            data=json.dumps(
 | 
			
		||||
                dict(
 | 
			
		||||
                    username=1,
 | 
			
		||||
                    email='test@test.com',
 | 
			
		||||
                    password='12345678',
 | 
			
		||||
                    password_conf='12345678',
 | 
			
		||||
                )
 | 
			
		||||
            ),
 | 
			
		||||
            content_type='application/json',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assert_500(response)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestUserLogin(ApiTestCaseMixin):
 | 
			
		||||
    @pytest.mark.parametrize(
 | 
			
		||||
 
 | 
			
		||||
@@ -120,7 +120,7 @@ class TestIsUsernameValid:
 | 
			
		||||
        ('input_username_length',),
 | 
			
		||||
        [
 | 
			
		||||
            (2,),
 | 
			
		||||
            (13,),
 | 
			
		||||
            (31,),
 | 
			
		||||
        ],
 | 
			
		||||
    )
 | 
			
		||||
    def test_it_returns_error_message_when_username_length_is_invalid(
 | 
			
		||||
@@ -128,9 +128,9 @@ class TestIsUsernameValid:
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        assert (
 | 
			
		||||
            check_username(
 | 
			
		||||
                username=random_string(input_username_length),
 | 
			
		||||
                username=random_string(31),
 | 
			
		||||
            )
 | 
			
		||||
            == 'username: 3 to 12 characters required\n'
 | 
			
		||||
            == 'username: 3 to 30 characters required\n'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @pytest.mark.parametrize(
 | 
			
		||||
@@ -154,9 +154,9 @@ class TestIsUsernameValid:
 | 
			
		||||
        assert check_username(username=random_string()) == ''
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_multiple_errors(self) -> None:
 | 
			
		||||
        username = random_string(1) + '.'
 | 
			
		||||
        username = random_string(31) + '.'
 | 
			
		||||
        assert check_username(username=username) == (
 | 
			
		||||
            'username: 3 to 12 characters required\n'
 | 
			
		||||
            'username: 3 to 30 characters required\n'
 | 
			
		||||
            'username: only alphanumeric characters and the underscore '
 | 
			
		||||
            'character "_" allowed\n'
 | 
			
		||||
        )
 | 
			
		||||
@@ -201,14 +201,14 @@ class TestRegisterControls:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_multiple_errors_when_inputs_are_invalid(self) -> None:
 | 
			
		||||
        invalid_username = random_string(2)
 | 
			
		||||
        invalid_username = random_string(31)
 | 
			
		||||
        assert register_controls(
 | 
			
		||||
            username=invalid_username,
 | 
			
		||||
            email=invalid_username,
 | 
			
		||||
            password=random_string(8),
 | 
			
		||||
            password_conf=random_string(8),
 | 
			
		||||
        ) == (
 | 
			
		||||
            'username: 3 to 12 characters required\n'
 | 
			
		||||
            'username: 3 to 30 characters required\n'
 | 
			
		||||
            'email: valid email must be provided\n'
 | 
			
		||||
            'password: password and password confirmation do not match\n'
 | 
			
		||||
        )
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user