Ejemplo n.º 1
0
def test_change_email_whitespace(app):
    """Test send verification form."""
    mail = app.extensions['mail']

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        data = prefix(
            'profile',
            dict(
                username='******',
                full_name='Test User',
                email=app.config['TEST_USER_EMAIL'],
                email_repeat=app.config['TEST_USER_EMAIL'],
            ))

        with mail.record_messages() as outbox:
            assert len(outbox) == 0
            data['profile-email_repeat'] = data['profile-email'] = '*****@*****.**'
            resp = client.post(profile_url, data=data)
            assert 'Invalid email address' not in resp.get_data(as_text=True)
            # Email was sent for email address confirmation.
            assert len(outbox) == 1
Ejemplo n.º 2
0
def test_profile_view(app):
    """Test the profile view."""
    app.config['USERPROFILES_EMAIL_ENABLED'] = False
    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert 'name="profile_form"' in str(resp.data)

        # Valid submission should work
        resp = client.post(profile_url,
                           data=prefix(
                               'profile',
                               dict(
                                   username=test_usernames['valid'],
                                   full_name='Valid Name',
                               )))

        assert resp.status_code == 200
        data = resp.get_data(as_text=True)
        assert test_usernames['valid'] in data
        assert 'Valid' in data
        assert 'Name' in data

        # Invalid submission should not save data
        resp = client.post(
            profile_url,
            data=prefix(
                'profile',
                dict(
                    username=test_usernames['invalid_characters'],
                    full_name='Valid Name',
                )))

        assert resp.status_code == 200
        assert test_usernames['invalid_characters'] in \
            resp.get_data(as_text=True)

        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert test_usernames['valid'] in resp.get_data(as_text=True)

        # Whitespace should be trimmed
        client.post(profile_url,
                    data=prefix(
                        'profile',
                        dict(
                            username='******'.format(test_usernames['valid']),
                            full_name='Valid Name ',
                        )))
        resp = client.get(profile_url)

        assert resp.status_code == 200
        data = resp.get_data(as_text=True)
        assert test_usernames['valid'] in data
        assert 'Valid Name ' not in data
Ejemplo n.º 3
0
def test_profile_name_exists(app):
    """Test the profile view."""
    app.config['USERPROFILES_EMAIL_ENABLED'] = False

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    # Create an existing user
    email1 = '*****@*****.**'
    password1 = '123456'
    with app.test_client() as client:
        sign_up(app, client, email=email1, password=password1)
        login(app, client, email=email1, password=password1)
        assert client.get(profile_url).status_code == 200
        resp = client.post(profile_url,
                           data=prefix(
                               'profile',
                               dict(
                                   username='******',
                                   full_name='Valid Name',
                               )))
        assert 'has-error' not in resp.get_data(as_text=True)

    # Create another user and try setting username to same as above user.
    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        resp = client.post(profile_url,
                           data=prefix(
                               'profile',
                               dict(
                                   username='******',
                                   full_name='Another name',
                               )))
        assert resp.status_code == 200
        assert 'Username already exists.' in resp.get_data(as_text=True)

        # Now set it to something else and do it twice.
        data = prefix('profile',
                      dict(
                          username='******',
                          full_name='Another name',
                      ))

        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)

        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)
Ejemplo n.º 4
0
def test_change_email(app):
    """Test send verification form."""
    mail = app.extensions['mail']
    error_msg = 'Username already exists.'

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    # Create an existing user
    email1 = '*****@*****.**'
    password1 = '123456'
    with app.test_client() as client:
        sign_up(app, client, email=email1, password=password1)
        login(app, client, email=email1, password=password1)
        assert client.get(profile_url).status_code == 200

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        data = prefix(
            'profile',
            dict(
                username='******',
                full_name='Test User',
                email=app.config['TEST_USER_EMAIL'],
                email_repeat=app.config['TEST_USER_EMAIL'],
            ))

        # Test existing email of another user.
        data['profile-email_repeat'] = data['profile-email'] = email1
        resp = client.post(profile_url, data=data)
        assert '[email protected] is already associated with an account.' \
            in resp.get_data(as_text=True)

        # Test empty email
        data['profile-email_repeat'] = data['profile-email'] = ''
        resp = client.post(profile_url, data=data)
        assert "Email not provided" in resp.get_data(as_text=True)

        # Test not an email
        data['profile-email_repeat'] = data['profile-email'] = 'sadfsdfs'
        resp = client.post(profile_url, data=data)
        assert "Invalid email address" in resp.get_data(as_text=True)

        # Test different emails
        data['profile-email_repeat'] = '*****@*****.**'
        data['profile-email'] = '*****@*****.**'
        resp = client.post(profile_url, data=data)
        assert 'Email addresses do not match.' in resp.get_data(as_text=True)
Ejemplo n.º 5
0
def test_get_current_userprofile(app):
    """Test get_current_userprofile."""
    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        # Logged in user should have userprofile
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert 'name="profile_form"' in resp.get_data(as_text=True)
        assert current_userprofile.is_anonymous is False
        assert current_user.id == current_userprofile.user_id
Ejemplo n.º 6
0
def test_get_current_userprofile(app):
    """Test get_current_userprofile."""
    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        # Logged in user should have userprofile
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert 'name="profile_form"' in resp.get_data(as_text=True)
        assert current_userprofile.is_anonymous is False
        assert current_user.id == current_userprofile.user_id
Ejemplo n.º 7
0
def test_profile_view(app):
    """Test the profile view."""
    app.config['USERPROFILES_EMAIL_ENABLED'] = False
    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert 'name="profile_form"' in str(resp.data)

        # Valid submission should work
        resp = client.post(profile_url, data=prefix('profile', dict(
            username=test_usernames['valid'],
            full_name='Valid Name', )))

        assert resp.status_code == 200
        data = resp.get_data(as_text=True)
        assert test_usernames['valid'] in data
        assert 'Valid' in data
        assert 'Name' in data

        # Invalid submission should not save data
        resp = client.post(profile_url, data=prefix('profile', dict(
            username=test_usernames['invalid_characters'],
            full_name='Valid Name', )))

        assert resp.status_code == 200
        assert test_usernames['invalid_characters'] in \
            resp.get_data(as_text=True)

        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert test_usernames['valid'] in resp.get_data(as_text=True)

        # Whitespace should be trimmed
        client.post(profile_url, data=prefix('profile', dict(
            username='******'.format(test_usernames['valid']),
            full_name='Valid Name ', )))
        resp = client.get(profile_url)

        assert resp.status_code == 200
        data = resp.get_data(as_text=True)
        assert test_usernames['valid'] in data
        assert 'Valid Name ' not in data
Ejemplo n.º 8
0
def test_profile_name_exists(app):
    """Test the profile view."""
    app.config['USERPROFILES_EMAIL_ENABLED'] = False

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    # Create an existing user
    email1 = '*****@*****.**'
    password1 = '123456'
    with app.test_client() as client:
        sign_up(app, client, email=email1, password=password1)
        login(app, client, email=email1, password=password1)
        assert client.get(profile_url).status_code == 200
        resp = client.post(profile_url, data=prefix('profile', dict(
            username='******', full_name='Valid Name',)))
        assert 'has-error' not in resp.get_data(as_text=True)

    # Create another user and try setting username to same as above user.
    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        resp = client.post(profile_url, data=prefix('profile', dict(
            username='******', full_name='Another name',
        )))
        assert resp.status_code == 200
        assert 'Username already exists.' in resp.get_data(as_text=True)

        # Now set it to something else and do it twice.
        data = prefix('profile', dict(
            username='******', full_name='Another name', ))

        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)

        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)
Ejemplo n.º 9
0
def test_profile_case_change(app):
    """Test the profile view."""
    app.config['USERPROFILES_EMAIL_ENABLED'] = False
    error_msg = 'Username already exists.'

    with app.app_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        # Create a user
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        data = prefix('profile',
                      dict(
                          username='******',
                          full_name='Another name',
                      ))

        # Set the name first time
        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert error_msg not in resp.get_data(as_text=True)

        # Set the name second time
        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert error_msg not in resp.get_data(as_text=True)

        # Change case of the username
        data = prefix('profile',
                      dict(
                          username='******',
                          full_name='Another name',
                      ))

        resp = client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert error_msg not in resp.get_data(as_text=True)
Ejemplo n.º 10
0
def test_send_verification_form(app):
    """Test send verification form."""
    mail = app.extensions['mail']

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert 'You have not yet verified your email address' in \
            resp.get_data(as_text=True)

        with mail.record_messages() as outbox:
            assert len(outbox) == 0
            resp = client.post(profile_url, data=prefix('verification', dict(
                send_verification_email='Title'
            )))
            assert len(outbox) == 1
Ejemplo n.º 11
0
def test_send_verification_form(app):
    """Test send verification form."""
    mail = app.extensions['mail']

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200
        assert 'You have not yet verified your email address' in \
            resp.get_data(as_text=True)

        with mail.record_messages() as outbox:
            assert len(outbox) == 0
            resp = client.post(profile_url, data=prefix('verification', dict(
                send_verification_email='Title'
            )))
            assert len(outbox) == 1
Ejemplo n.º 12
0
def test_change_email(app):
    """Test send verification form."""
    mail = app.extensions['mail']

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    # Create an existing user
    email1 = '*****@*****.**'
    password1 = '123456'
    with app.test_client() as client:
        sign_up(app, client, email=email1, password=password1)
        login(app, client, email=email1, password=password1)
        assert client.get(profile_url).status_code == 200

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        data = prefix(
            'profile',
            dict(
                username='******',
                full_name='Test User',
                email=app.config['TEST_USER_EMAIL'],
                email_repeat=app.config['TEST_USER_EMAIL'],
            ))

        # Test that current_user stops validation of email
        client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)

        # Test existing email of another user.
        data['profile-email_repeat'] = data['profile-email'] = email1
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test empty email
        data['profile-email_repeat'] = data['profile-email'] = ''
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test not an email
        data['profile-email_repeat'] = data['profile-email'] = 'sadfsdfs'
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test different emails
        data['profile-email_repeat'] = '*****@*****.**'
        data['profile-email'] = '*****@*****.**'
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test whitespace
        with mail.record_messages() as outbox:
            assert len(outbox) == 0
            data['profile-email_repeat'] = data['profile-email'] = '*****@*****.**'
            resp = client.post(profile_url, data=data)
            assert 'has-error' not in resp.get_data(as_text=True)
            # Email was sent for email address confirmation.
            assert len(outbox) == 1
Ejemplo n.º 13
0
def test_change_email(app):
    """Test send verification form."""
    mail = app.extensions['mail']

    with app.test_request_context():
        profile_url = url_for('invenio_userprofiles.profile')

    # Create an existing user
    email1 = '*****@*****.**'
    password1 = '123456'
    with app.test_client() as client:
        sign_up(app, client, email=email1, password=password1)
        login(app, client, email=email1, password=password1)
        assert client.get(profile_url).status_code == 200

    with app.test_client() as client:
        sign_up(app, client)
        login(app, client)
        resp = client.get(profile_url)
        assert resp.status_code == 200

        data = prefix('profile', dict(
            username='******',
            full_name='Test User',
            email=app.config['TEST_USER_EMAIL'],
            email_repeat=app.config['TEST_USER_EMAIL'],
        ))

        # Test that current_user stops validation of email
        client.post(profile_url, data=data)
        assert resp.status_code == 200
        assert 'has-error' not in resp.get_data(as_text=True)

        # Test existing email of another user.
        data['profile-email_repeat'] = data['profile-email'] = email1
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test empty email
        data['profile-email_repeat'] = data['profile-email'] = ''
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test not an email
        data['profile-email_repeat'] = data['profile-email'] = 'sadfsdfs'
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test different emails
        data['profile-email_repeat'] = '*****@*****.**'
        data['profile-email'] = '*****@*****.**'
        resp = client.post(profile_url, data=data)
        assert 'has-error' in resp.get_data(as_text=True)

        # Test whitespace
        with mail.record_messages() as outbox:
            assert len(outbox) == 0
            data['profile-email_repeat'] = data['profile-email'] = '*****@*****.**'
            resp = client.post(profile_url, data=data)
            assert 'has-error' not in resp.get_data(as_text=True)
            # Email was sent for email address confirmation.
            assert len(outbox) == 1