示例#1
0
def test_add_contact_to_user_already_exists(session):  # pylint: disable=unused-argument
    """Assert that a contact cannot be added to a user that already has a contact."""
    factory_user_model(user_info=TestUserInfo.user_test)

    UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1)

    with pytest.raises(BusinessException) as exception:
        UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact2)
    assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
示例#2
0
def test_add_contact_to_user_already_exists(session):  # pylint: disable=unused-argument
    """Assert that a contact cannot be added to a user that already has a contact."""
    factory_user_model(username='******',
                       roles='{edit,uma_authorization,basic}',
                       keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04')

    UserService.add_contact(TEST_TOKEN, TEST_CONTACT_INFO)

    with pytest.raises(BusinessException) as exception:
        UserService.add_contact(TEST_TOKEN, TEST_UPDATED_CONTACT_INFO)
    assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
示例#3
0
def test_add_contact_to_user_already_exists(session, monkeypatch):  # pylint: disable=unused-argument
    """Assert that a contact cannot be added to a user that already has a contact."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub']
    factory_user_model(user_info=user_with_token)

    patch_token_info(TestJwtClaims.user_test, monkeypatch)
    UserService.add_contact(TestContactInfo.contact1)

    with pytest.raises(BusinessException) as exception:
        UserService.add_contact(TestContactInfo.contact2)
    assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
示例#4
0
def test_add_contact_to_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be added to a user."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub']
    factory_user_model(user_info=user_with_token)

    contact = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1).as_dict()

    assert contact['email'] == TestContactInfo.contact1['email']
    assert contact['phone'] == TestContactInfo.contact1['phone']
    assert contact['phone_extension'] == TestContactInfo.contact1['phoneExtension']
示例#5
0
def test_add_contact_to_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be added to a user."""
    factory_user_model(user_info=TestUserInfo.user_test)

    user = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1)

    assert user is not None
    dictionary = user.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TestContactInfo.contact1['email']
    assert dictionary['contacts'][0]['phone'] == TestContactInfo.contact1['phone']
    assert dictionary['contacts'][0]['phoneExtension'] == TestContactInfo.contact1['phoneExtension']
示例#6
0
def test_update_contact_for_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be updated for a user."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub']
    factory_user_model(user_info=user_with_token)

    contact = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1).as_dict()

    assert contact is not None

    updated_contact = UserService.update_contact(TestJwtClaims.user_test, TestContactInfo.contact2).as_dict()

    assert updated_contact is not None
    assert updated_contact['email'] == TestContactInfo.contact2['email']
示例#7
0
def test_delete_contact_for_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be deleted for a user."""
    factory_user_model(user_info=TestUserInfo.user_test)

    user = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1)

    assert user is not None
    dictionary = user.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1

    updated_user = UserService.delete_contact(TestJwtClaims.user_test)

    assert updated_user is not None
    dictionary = updated_user.as_dict()
    assert dictionary.get('contacts') == []
示例#8
0
def test_delete_contact_for_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be deleted for a user."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub']
    factory_user_model(user_info=user_with_token)

    contact = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1).as_dict()

    assert contact is not None

    deleted_contact = UserService.delete_contact(TestJwtClaims.user_test).as_dict()

    assert deleted_contact is not None

    contacts = UserService.get_contacts(TestJwtClaims.user_test)
    assert contacts.get('contacts') == []
示例#9
0
def test_add_contact_to_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be added to a user."""
    factory_user_model(username='******',
                       roles='{edit,uma_authorization,basic}',
                       keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04')

    user = UserService.add_contact(TEST_TOKEN, TEST_CONTACT_INFO)

    assert user is not None
    dictionary = user.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TEST_CONTACT_INFO['email']
    assert dictionary['contacts'][0]['phone'] == TEST_CONTACT_INFO['phone']
    assert dictionary['contacts'][0]['phoneExtension'] == TEST_CONTACT_INFO[
        'phoneExtension']
示例#10
0
def test_delete_contact_for_user(session):  # pylint: disable=unused-argument
    """Assert that a contact can be deleted for a user."""
    factory_user_model(username='******',
                       roles='{edit,uma_authorization,basic}',
                       keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04')

    user = UserService.add_contact(TEST_TOKEN, TEST_CONTACT_INFO)

    assert user is not None
    dictionary = user.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1

    updated_user = UserService.delete_contact(TEST_TOKEN)

    assert updated_user is not None
    dictionary = updated_user.as_dict()
    assert dictionary.get('contacts') == []
示例#11
0
def test_add_contact_user_no_user(session):  # pylint: disable=unused-argument
    """Assert that a contact cannot be added to a user that does not exist."""
    with pytest.raises(BusinessException) as exception:
        UserService.add_contact(TestJwtClaims.user_test,
                                TestContactInfo.contact1)
    assert exception.value.code == Error.DATA_NOT_FOUND.name
示例#12
0
def test_add_contact_user_no_user(session):  # pylint: disable=unused-argument
    """Assert that a contact cannot be added to a user that does not exist."""
    with pytest.raises(BusinessException) as exception:
        UserService.add_contact(TEST_TOKEN, TEST_CONTACT_INFO)
    assert exception.value.code == Error.DATA_NOT_FOUND.name