Exemple #1
0
def test_register_validation_no_email():
    form_data = {'name': 'Kat', 'email': '', 'password': '******' * 3}

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

    vm.validate()

    assert vm.error is not None
    assert 'email' in vm.error
Exemple #2
0
def test_vm_register_validation_no_email():
    # Arrange
    form_data = {'name': 'Michael', 'email': '', 'password': '******' * 6}

    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 'email' in vm.error
def test_register_validation_when_valid():
    form_data = {
        'name': 'mike',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }

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

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

    assert vm.error is None
Exemple #4
0
def test_vm_register_validation_no_email():
    # 3 A's of test: Arrange, Act, then Assert

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

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

    # Act - Note no unittest.mock in this case as no requests to the database layer required for no email
    vm.validate()

    # Assert
    assert vm.error is not None
    assert 'email' in vm.error
Exemple #5
0
def test_register_validation_when_valid():
    form_data = {
        'name': 'Kat',
        'email': '*****@*****.**',
        'password': '******' * 3
    }

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

    # Avoids database call on register
    target = 'pypi_org.services.user_service.find_user_by_email'
    with unittest.mock.patch(target, return_value=None):
        vm.validate()

    assert vm.error is None
Exemple #6
0
def test_register_validation_for_existing_user():
    form_data = {
        'name': 'Kat',
        'email': '*****@*****.**',
        'password': '******' * 3
    }

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

    # Avoids database call on register
    target = 'pypi_org.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 vm.error is not None
    assert 'already exists' in vm.error
def test_register_validation_no_email():
    # 3 A's of test: Arrange, Act, then Assert

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

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

    # Act
    vm.validate()

    # Assert
    assert 'specify an email' in vm.error
def test_register_validation_when_valid():
    # Arrange
    form_data = {
        'name': 'Jan',
        'email': "*****@*****.**",
        'password': "******" * 7
    }
    # flask_app
    with flask_app.test_request_context(path="/account/register",
                                        data=form_data):
        vm = RegisterViewModel()

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

    # verify
    assert not vm.error
Exemple #9
0
def test_vm_register_validation_when_valid():
    #  3 A's of test: Arrange, Act, then Assert

    #  Arrange, get everything setup
    form_data = {
        'name': 'Rikard',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }

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

    # Act, try to do the actual login
    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
Exemple #10
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 = '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
Exemple #11
0
def test_vm_register_validation_for_existing_user():
    # Arrange
    form_data = {
        'name': 'marcos',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }
    with flask_app.test_request_context(path='/account/register',
                                        data=form_data):
        vm = RegisterViewModel()

    # Act
    target = 'pypi_org.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
def register_post():
    # ViewModel gets name/email/password from flask.request, checks whether they're filled out, and if so tries to
    # register a user.  We just interpret the results here.
    # These are broken into a few calls here, although originally I had it as all in __init__.  This is more clear about
    # what is happening though

    vm = RegisterViewModel()

    vm.validate()
    if vm.error:
        return flask.render_template("/account/register.html", **vm.to_dict())

    vm.create_user()
    if vm.error:
        return flask.render_template("/account/register.html", **vm.to_dict())

    resp = flask.redirect("/account")
    cookie_auth.set_auth(resp, vm.user.id)
    return resp
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
Exemple #14
0
def register_post():
    vm = RegisterViewModel()
    vm.validate()
    if vm.error:
        return vm.to_dict()

    # Create the user (in the DB)
    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()

    # Log in browser as a session
    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)

    return resp
def register_post():
    view_model = RegisterViewModel()
    view_model.validate()

    if view_model.error:
        return view_model.to_dict()

    user = user_service.create_user(view_model.name, view_model.email,
                                    view_model.password)

    if not user:
        return view_model.to_dict()

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)
    return resp
def register_post():
    log.notice(f"Anonymous user is registering for a new account")

    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        log.notice(f"User could not create account, error: {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'
        log.notice(f"User could not create account, error: {vm.error}.")
        return vm.to_dict()

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)

    log.notice(f"User SUCCESSFULLY created account: {user.name} - {user.email}.")
    return resp
def register_get():
    vm = RegisterViewModel()
    return vm.to_dict()
def register_get():
    vm = RegisterViewModel()
    if vm.user_id_logged_in:
        return flask.redirect('/account')
    else:
        return flask.render_template('/account/register.html')