Beispiel #1
0
def test_user_information_page_displays_if_there_are_failed_login_attempts(
        client, platform_admin_user, mocker):
    mocker.patch('app.user_api_client.get_user',
                 side_effect=[
                     platform_admin_user,
                     User(user_json(name="Apple Bloom", failed_login_count=2))
                 ],
                 autospec=True)

    mocker.patch('app.user_api_client.get_organisations_and_services_for_user',
                 return_value={
                     'organisations': [],
                     'services_without_organisations': [
                         {
                             "id": 1,
                             "name": "Fresh Orchard Juice"
                         },
                         {
                             "id": 2,
                             "name": "Nature Therapy"
                         },
                     ]
                 },
                 autospec=True)
    client.login(platform_admin_user)
    response = client.get(url_for('main.user_information', user_id=345))
    assert response.status_code == 200

    document = html.fromstring(response.get_data(as_text=True))
    assert document.xpath(
        "//p/text()[normalize-space()='2 failed login attempts']")
Beispiel #2
0
def test_user():
    user_data = {'id': 1,
                 'name': 'Test User',
                 'email_address': '*****@*****.**',
                 'mobile_number': '+4412341234',
                 'state': 'pending',
                 'failed_login_count': 0
                 }
    user = User(user_data)

    assert user.id == 1
    assert user.name == 'Test User'
    assert user.email_address == '*****@*****.**'
    assert user.mobile_number == '+4412341234'
    assert user.state == 'pending'

    # user has three failed logins before being locked
    assert user.max_failed_login_count == 3
    assert user.failed_login_count == 0
    assert not user.is_locked()

    # set failed logins to threshold
    user.failed_login_count = 3
    assert user.is_locked()

    with pytest.raises(TypeError):
        user.has_permissions('to_do_bad_things')
Beispiel #3
0
def create_test_api_user(state, permissions={}):
    from app.notify_client.user_api_client import User
    user_data = {'id': 1,
                 'name': 'Test User',
                 'password': '******',
                 'email_address': TEST_USER_EMAIL,
                 'mobile_number': '+441234123412',
                 'state': state,
                 'permissions': permissions
                 }
    user = User(user_data)
    return user
def test_user():
    user_data = {'id': 1,
                 'name': 'Test User',
                 'email_address': '*****@*****.**',
                 'mobile_number': '+4412341234',
                 'state': 'pending',
                 'failed_login_count': 0
                 }
    user = User(user_data)

    assert user.id == 1
    assert user.name == 'Test User'
    assert user.email_address == '*****@*****.**'
    assert user.mobile_number == '+4412341234'
    assert user.state == 'pending'

    # user has three failed logins before being locked
    assert user.max_failed_login_count == 3
    assert user.failed_login_count == 0
    assert not user.is_locked()

    # set failed logins to threshold
    user.failed_login_count = 3
    assert user.is_locked()
def _user_with_permissions():
    from app.notify_client.user_api_client import User

    user_data = {'id': 999,
                 'name': 'Test User',
                 'password': '******',
                 'email_address': '*****@*****.**',
                 'mobile_number': '+4412341234',
                 'state': 'active',
                 'failed_login_count': 0,
                 'permissions': {'': ['manage_users', 'manage_templates', 'manage_settings']},
                 'platform_admin': False
                 }
    user = User(user_data)
    return user
Beispiel #6
0
def test_user_information_page_shows_information_about_user(
        client, platform_admin_user, mocker):
    mocker.patch('app.user_api_client.get_user',
                 side_effect=[
                     platform_admin_user,
                     User(user_json(name="Apple Bloom", services=[1, 2]))
                 ],
                 autospec=True)

    mocker.patch('app.user_api_client.get_organisations_and_services_for_user',
                 return_value={
                     'organisations': [],
                     'services_without_organisations': [
                         {
                             "id": 1,
                             "name": "Fresh Orchard Juice"
                         },
                         {
                             "id": 2,
                             "name": "Nature Therapy"
                         },
                     ]
                 },
                 autospec=True)
    client.login(platform_admin_user)
    response = client.get(url_for('main.user_information', user_id=345))
    assert response.status_code == 200

    document = html.fromstring(response.get_data(as_text=True))

    assert document.xpath("//h1/text()[normalize-space()='Apple Bloom']")
    assert document.xpath("//p/text()[normalize-space()='*****@*****.**']")
    assert document.xpath("//p/text()[normalize-space()='+447700900986']")

    assert document.xpath("//h2/text()[normalize-space()='Services']")
    assert document.xpath(
        "//a/text()[normalize-space()='Fresh Orchard Juice']")
    assert document.xpath("//a/text()[normalize-space()='Nature Therapy']")

    assert document.xpath("//h2/text()[normalize-space()='Last login']")
    assert not document.xpath(
        "//p/text()[normalize-space()='0 failed login attempts']")