示例#1
0
def register_post():
    vm = RegisterViewModel()
    vm.validate()

    # for the beta:
    if vm.admin != True:
        vm.error = "Account creation is limited during the closed beta."

    if vm.error:
        return vm.to_dict()

    security_class = security_service.find_default_security_class()
    user = user_service.create_user(vm.name, vm.email, vm.password,
                                    security_class)
    if not user:
        vm.error = "The account could not be created"
        return vm.to_dict()

    success = user_service.send_activation_email(user)
    if success != True:
        vm.error = "The activation email failed to send. Please contact the site administrator for help."
        return vm.to_dict()

    resp = flask.redirect("/")

    return resp
示例#2
0
def index_post():
    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        return vm.to_dict()

    user = user_service.create_user(vm.name, vm.email)

    if not user:
        vm.error = 'The account could not be created.'
        return vm.to_dict()

    return flask.redirect('/users')
示例#3
0
def register_post():
    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        return vm.to_dict()

    user = user_service.create_user(vm.name, vm.email, vm.password)
    if not user:
        vm.error = 'The account could not be created'
        return vm.to_dict()

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)
    return resp
示例#4
0
def test_register_validation_when_valid():
    # Arrange
    form_data = {
        'name': 'Ruchti',
        'email': '*****@*****.**',
        'password': '******'*6
    }

    with flask_app.test_request_context(path='/account/register', data=form_data):
        vm = RegisterViewModel()
    # Act
    target = 'services.user_service.find_user_by_email'
    with unittest.mock.patch(target, return_value=None):
        vm.validate()

    # Assert
    assert vm.error is None
def register_post():

    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        return render_template("account/register.html",
                               name=vm.name,
                               username=vm.username,
                               email=vm.email,
                               error=vm.error)

    user = user_service.create_user(vm.name, vm.username, vm.email,
                                    vm.password)
    if not user:
        vm.error = "The account could not be created."
        return render_template("account/register.html", error=vm.error)

    return redirect("/account/login")
示例#6
0
def test_register_validation_for_existing_user():
    # Arrange
    form_data = {
        'name': 'Ruchti',
        'email': '*****@*****.**',
        'password': '******'*6
    }

    with flask_app.test_request_context(path='/account/register', data=form_data):
        vm = RegisterViewModel()
    # Act
    target = 'services.user_service.find_user_by_email'
    test_user = User(email=form_data.get('email'))
    with unittest.mock.patch(target, return_value=test_user):
        vm.validate()

    # Assert
    assert vm.error is not None
    assert 'already exists' in vm.error
示例#7
0
def test_vm_register_validation_when_valid():
    # 3 A's of test: Arrange, Act, then Assert

    # Arrange
    form_data = {
        'name': 'Michael',
        'email': '*****@*****.**',
        'password': '******' * 6
    }

    with flask_app.test_request_context(path='/account/register', data=form_data):
        vm = RegisterViewModel()

    # Act
    target = 'services.user_service.find_user_by_email'
    with unittest.mock.patch(target=target, return_value=None):
        vm.validate()

    # Assert
    assert vm.error is None
示例#8
0
def test_v_register_validation_for_no_email():

    # Arrange
    form_data = {
        'name': 'Michael',
        'email': '',
        'password': '******' * 6,
    }

    from tests.test_client import flask_app

    with flask_app.test_request_context(path='/account/register',
                                        data=form_data):
        vm = RegisterViewModel()

    # Act
    vm.validate()

    # Assert
    assert vm.error is not None
    assert 'specify an email' in vm.error
def test_register_validation_when_valid():
    # 3 A's of testing: Arrange, Assert, and Act

    # Arrange
    form_data = {
        'name': 'John',
        'email_address': '*****@*****.**',
        'password': '******'
    }

    with flask_app.test_request_context(path='/account/register', data=form_data):
        vm = RegisterViewModel()

    # Act
    # To avoid touching the database, we mock the function that would reach out to the database and make a fake one
    # instead that just returns None (which would be the 'no user to see here!' response)
    target = 'pypi_org.services.user_service.find_user_by_email'
    with unittest.mock.patch(target, return_value=None):
        vm.validate()

    # Assert
    assert vm.error is None
示例#10
0
def test_vm_register_validation_for_existing_user():
    # 3 A's of test: Arrange, Act, then Assert

    # Arrange
    form_data = {
        'name': 'Michael',
        'email': '*****@*****.**',
        'password': '******' * 6
    }

    with flask_app.test_request_context(path='/account/register', data=form_data):
        vm = RegisterViewModel()

    # Act
    target = 'services.user_service.find_user_by_email'
    test_user = User(email=form_data.get('email'))
    with unittest.mock.patch(target=target, return_value=test_user):
        vm.validate()

    # Assert
    assert vm.error is not None
    assert 'already exists' in vm.error