示例#1
0
def test_v_register_view_new_user():
    #  3 A's of test: Arrange, Act, then Assert

    #  Arrange, get everything setup
    from pypi_org.views.account_views import register_post
    form_data = {
        'name': 'Rikard',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }

    target = 'pypi_org.services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)

    target = 'pypi_org.services.user_service.create_user'
    create_user = unittest.mock.patch(target, return_value=User())

    request = flask_app.test_request_context('/account/register',
                                             data=form_data)

    with find_user, create_user, request:
        # Act, try to do the actual login
        resp: Response = register_post()

    # Assert
    assert resp.location == '/account'
示例#2
0
def test_register_validation_view_new_user():
    form_data = {
        'name': 'Kat',
        'email': '*****@*****.**',
        'password': '******' * 3
    }

    target_find_user = '******'
    target_create_user = '******'
    find_user = unittest.mock.patch(target_find_user, return_value=None)
    create_user = unittest.mock.patch(target_create_user, return_value=User())
    request = flask_app.test_request_context(path='/account/register',
                                             data=form_data)
    with find_user, create_user, request:
        resp: Response = register_post()

    assert resp.location == '/account'
示例#3
0
def test_v_register_view_new_user():
    form_data = {
        'name': 'mike',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }
    from pypi_org.views.account_views import register_post

    target = 'pypi_org.services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)
    target = 'pypi_org.services.user_service.create_user'
    create_user = unittest.mock.patch(target, return_value=User())
    request = flask_app.test_request_context(path='/account/register', data=form_data)

    with find_user, create_user, request:
        resp: Response = register_post()

    assert resp.location == '/account'
示例#4
0
def test_v_register_view_new_user():
    # Arrange
    from pypi_org.views.account_views import register_post
    form_data = {
        'name': 'marcos',
        'email': '*****@*****.**',
        'password': '******' * 6,
    }

    target = 'pypi_org.services.user_service.find_user_by_email'
    with unittest.mock.patch(target, return_value=None):
        target = 'pypi_org.services.user_service.create_user'
        with unittest.mock.patch(target, return_value=User()):
            with flask_app.test_request_context(path='/account/register',
                                                data=form_data):
                # Act
                resp: Response = register_post()

    # Assert
    assert resp.location == '/account'
def test_register_view_new_user():
    # Arrange
    from pypi_org.views.account_views import register_post
    form_data = {
        'name': 'Jan',
        'email': "*****@*****.**",
        'password': "******" * 7
    }
    # flask_app
    target = "pypi_org.services.user_service.find_user_by_email"
    with mock.patch(target, return_value=None):
        target = "pypi_org.services.user_service.create_user"
        with mock.patch(target, return_value=User()):
            with flask_app.test_request_context(path="/account/register",
                                                data=form_data):
                # Act

                resp: Response = register_post()

    # verify
    assert resp.location == "/account"
def test_register_validation_new_user():
    # 3 A's of test: Arrange, Act, then Assert

    # Arrange
    from pypi_org.views.account_views import register_post
    form_data = {
        'name': "Eddie",
        'email': "*****@*****.**",
        'password': '******' * 6,
    }
    target = 'pypi_org.services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)
    target = 'pypi_org.services.user_service.create_user'
    create_user = unittest.mock.patch(target, return_value=User())
    request = flask_app.test_request_context(path='/account/register',
                                             data=form_data)

    with find_user, create_user, request:
        # Act
        resp: Response = register_post()

    # Assert
    assert resp.location == '/account'  # the redirect set the location header to this value
示例#7
0
def test_v_register_view_new_user():
    # 3 A's of test: Arrange, Act, then Assert

    # Arrange
    from pypi_org.views.account_views import register_post
    form_data = {
        'name': 'Michael',
        'email': '*****@*****.**',
        'password': '******' * 6
    }

    target = 'pypi_org.services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)
    target = 'pypi_org.services.user_service.create_user'
    create_user = unittest.mock.patch(target, return_value=User())
    request = flask_app.test_request_context(path='/account/register', data=form_data)

    with find_user, create_user, request:
        # Act
        resp: Response = register_post()

    # Assert
    assert resp.location == '/account'