Esempio n. 1
0
def test_homepage_directly():
    with flask_app.test_request_context(path='/'):
        r: Response = home_views.index()

    assert r.status_code == 200
    # noinspection PyUnresolvedReferences
    assert len(r.model.get('releases')) > 0
Esempio n. 2
0
def test_glider():
    # This test will break if SG510 is ever permanently retired from the fleet
    from ueaglider.views.glider_views import gliders
    with flask_app.test_request_context(path='/gliders/SG510'):
        resp: Response = gliders(510)
    assert resp.status_code == 200
    assert b'Orca' in resp.data
Esempio n. 3
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'
Esempio n. 4
0
def test_v_register_view_new_user():

    # Arrange
    from views.account_views import register_post

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

    from tests.test_client import flask_app

    target = 'services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)
    target = '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'
Esempio n. 5
0
def test_package_details_success():
    # Arrange
    from pypi_org.views.package_views import package_details
    from pypi_org.data.package import Package
    from pypi_org.data.releases import Release

    test_package = Package()
    test_package.id = 'sqlalchemy'
    test_package.description = "TDB"
    test_package.releases = [
        Release(created_date=datetime.datetime.now(),
                major_ver=1,
                minor_ver=2,
                build_ver=200),
        Release(created_date=datetime.datetime.now() -
                datetime.timedelta(days=10)),
    ]

    # Act
    with unittest.mock.patch(
            'pypi_org.services.package_service.get_package_by_id',
            return_value=test_package):
        with flask_app.test_request_context(path='/project/' +
                                            test_package.id):
            resp: Response = package_details(test_package.id)

    # Assert
    assert b'sqlalchemy 1.2.200' in resp.data
Esempio n. 6
0
def test_homepage_missions():
    # Check that the mission list has at least one item in it
    with flask_app.test_request_context(path='/'):
        r: Response = home_views.index()

    assert r.status_code == 200
    # noinspection PyUnresolvedReferences
    assert len(r.model.get('mission_list')) > 0
Esempio n. 7
0
def test_vm_empty_task_throughs_error():
    # Arrange
    form_data = {"desc": "   "}

    with flask_app.test_request_context(path="/task/create", data=form_data):
        vm = CreateViewModel()

    vm.validate()

    assert vm.error is not None
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
0
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
Esempio n. 11
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
Esempio n. 12
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'
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
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'
Esempio n. 16
0
def test_vm_register_user_doesnt_exist():
    # Arrange
    form_data = {
        "name": "Oliver",
        "email": "*****@*****.**",
        "password": "******" * 6,
    }

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

    # Act
    target = "flask_tasks.services.users_service.does_email_exist"
    with unittest.mock.patch(target, return_value=None):
        vm.validate()

    # Assert
    assert vm.error is None
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
Esempio n. 18
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
Esempio n. 19
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
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
Esempio n. 21
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'
Esempio n. 22
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
Esempio n. 23
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
Esempio n. 24
0
def test_register_view_new_user():
    # Arrange
    from views.account_views import register_post
    form_data = {
        'name': 'Ruchti',
        'email': '*****@*****.**',
        'password': '******'*6
    }

    target = 'services.user_service.find_user_by_email'
    find_user = unittest.mock.patch(target, return_value=None)
    target = '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'
Esempio n. 25
0
def test_v_register_successful_redirects_to_home():
    # Arrange
    form_data = {
        "name": "Oliver",
        "email": "*****@*****.**",
        "password": "******" * 6,
    }

    # Act
    does_email_exist = "flask_tasks.services.users_service.does_email_exist"
    email_not_taken = unittest.mock.patch(does_email_exist, return_value=None)
    add_user = "******"
    user_returned = unittest.mock.patch(add_user, return_value=User())
    register_context = flask_app.test_request_context(path="/register",
                                                      data=form_data)
    with email_not_taken, user_returned, register_context:
        resp: Response = register_post()

    # Assert
    assert resp.location == "/"
Esempio n. 26
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_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_when_valid():
    # 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
    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
Esempio n. 29
0
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
Esempio n. 30
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