def test_user_adobeid_unicode_error_unicode_dot_above(): with pytest.raises(ValueError) as excinfo: UserAction(email=u"lwałę[email protected]") assert excinfo.type == ArgumentError if six.PY2: assert excinfo.match(u"lwałę[email protected]".encode('utf8')) with pytest.raises(ValueError) as excinfo: UserAction(email=u"lwałę[email protected]".encode('utf8')) assert excinfo.type == ArgumentError assert excinfo.match(u"lwałę[email protected]".encode('utf8'))
def test_split_role_assignment(): group_prefix = "G" add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 25)] user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_role(groups=add_groups, role_type=RoleTypes.admin) assert user.maybe_split_groups(10) is True assert len(user.commands) == 3
def test_user_adobeid(): user = UserAction(email="*****@*****.**") assert user.wire_dict() == { "do": [], "user": "******", "useAdobeID": True }
def test_create_user_federatedid_email_format_username(): """ Create federated ID with username in email format (with email address) :return: """ user = UserAction(id_type=IdentityTypes.federatedID, username="******", domain="k.on-the-side.net", email="*****@*****.**") user.create(first_name="Daniel", last_name="Brotsky", country="US") assert user.wire_dict() == { "do": [{ "createFederatedID": { "email": "*****@*****.**", "firstname": "Daniel", "lastname": "Brotsky", "country": "US", "option": "ignoreIfAlreadyExists" } }], "user": "******", "domain": "k.on-the-side.net" }
def test_create_user_federatedid_username_unicode(): """ Test federated ID with a username and unicode attributes (non-email format) """ user = UserAction(id_type=IdentityTypes.federatedID, username=u"user", domain="example.com") user.create(first_name=u"Exampłę", last_name="User", country="PL", email=u"*****@*****.**") assert user.wire_dict() == { "do": [{ "createFederatedID": { "email": u"*****@*****.**", "firstname": u"Exampłę", "lastname": "User", "country": "PL", "option": "ignoreIfAlreadyExists" } }], "user": u"user", "domain": "example.com" }
def test_split_add_user(): """ Make sure split doesn't do anything when we have a non-add/remove group action :return: """ user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.create(first_name="Example", last_name="User", country="US", email="*****@*****.**") user.update(first_name="EXAMPLE") assert user.maybe_split_groups(10) is False assert len(user.commands) == 2 assert user.wire_dict() == { 'do': [{ 'createEnterpriseID': { 'country': 'US', 'email': '*****@*****.**', 'firstname': 'Example', 'lastname': 'User', 'option': 'ignoreIfAlreadyExists' } }, { 'update': { 'firstname': 'EXAMPLE' } }], 'user': '******' }
def test_large_group_mix_split(): """ Ensure that group split works on add and remove Each "add" and "remove" group should be split into 2 groups each :return: """ group_prefix = "G" add_groups = [group_prefix + six.text_type(n + 1) for n in range(0, 15)] remove_groups = [ group_prefix + six.text_type(n + 1) for n in range(15, 30) ] user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup) \ .remove_from_groups(groups=remove_groups, group_type=GroupTypes.usergroup) assert user.maybe_split_groups(10) is True assert len(user.commands) == 4 assert user.commands[0]["add"][ GroupTypes.usergroup.name] == add_groups[0:10] assert user.commands[1]["add"][ GroupTypes.usergroup.name] == add_groups[10:] assert user.commands[2]["remove"][ GroupTypes.usergroup.name] == remove_groups[0:10] assert user.commands[3]["remove"][ GroupTypes.usergroup.name] == remove_groups[10:]
def test_split_remove_all(): """ Don't split groups if "remove" is "all" instead of list :return: """ group_prefix = "G" add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 11)] user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.remove_from_groups(all_groups=True) assert user.maybe_split_groups(1) is False assert user.wire_dict() == {'do': [{'remove': 'all'}], 'user': '******'} user.add_to_groups(groups=add_groups) assert user.maybe_split_groups(10) is True assert user.wire_dict() == {'do': [{'remove': 'all'}, {'add': {'product': ['G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'G10']}}, {'add': {'product': ['G11']}}], 'user': '******'}
def test_create_user_adobeid(): user = UserAction(email="*****@*****.**") user.create() assert user.wire_dict() == {"do": [{"addAdobeID": {"email": "*****@*****.**", "option": "ignoreIfAlreadyExists"}}], "user": "******", "useAdobeID": True}
def test_create_user_enterpriseid(): user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.create(first_name="Daniel", last_name="Brotsky") assert user.wire_dict() == {"do": [{"createEnterpriseID": {"email": "*****@*****.**", "firstname": "Daniel", "lastname": "Brotsky", "option": "ignoreIfAlreadyExists"}}], "user": "******"}
def test_user_adobeid_unicode(): user = UserAction(email=u"*****@*****.**") assert user.wire_dict() == { "do": [], "user": u"*****@*****.**", "useAdobeID": True }
def test_create_user_federatedid_username_mismatch(): """ Mismatched email in UserAction constructor vs create() """ user = UserAction(id_type=IdentityTypes.federatedID, username="******", domain="example.com", email="*****@*****.**") with pytest.raises(ValueError): user.create(first_name="Example", last_name="User", country="US", email="*****@*****.**")
def test_different_email_username(): """ Update a user record so the email address is different than email-type username (federated only) """ user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.update(email="*****@*****.**", username="******") assert user.wire_dict() == {"do": [{"update": {"email": "*****@*****.**", "username": "******"}}], "user": "******"}
def test_user_federatedid_username(): user = UserAction(id_type=IdentityTypes.federatedID, username="******", domain="k.on-the-side.net") assert user.wire_dict() == { "do": [], "user": "******", "domain": "k.on-the-side.net" }
def test_delete_account_enterpriseid(): user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.delete_account() assert user.wire_dict() == { "do": [{ "removeFromDomain": {} }], "user": "******" }
def test_remove_from_groups_federatedid_all(): user = UserAction(id_type='federatedID', email="*****@*****.**") user.remove_from_groups(all_groups=True) assert user.wire_dict() == { "do": [{ "remove": "all" }], "user": "******" }
def test_add_to_groups_federatedid_all(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.add_to_groups(all_groups=True) assert user.wire_dict() == { "do": [{ "add": "all" }], "user": "******" }
def test_create_user_federatedid_username_mismatch(): user = UserAction(id_type=IdentityTypes.federatedID, username="******", domain="k.on-the-side.net", email="*****@*****.**") with pytest.raises(ValueError): user.create(first_name="Daniel", last_name="Brotsky", country="US", email="*****@*****.**")
def test_create_user_federatedid_unicode(): """ Test federated ID action with email address and no username and unicode in at least one attribute """ user = UserAction(id_type=IdentityTypes.federatedID, email=u"*****@*****.**") user.create(first_name=u"Exampłę", last_name="User", country="PL") assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"*****@*****.**", "firstname": u"Exampłę", "lastname": "User", "country": "PL", "option": "ignoreIfAlreadyExists"}}], "user": u"*****@*****.**"}
def test_no_group_split(): """ maybe_split should return false if nothing was split :return: """ group_prefix = "G" add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 5)] user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup) assert user.maybe_split_groups(10) is False assert len(user.commands) == 1
def test_large_group_assignment_split_recursive(): """ Test group list large enough to trigger recursive split :return: """ group_prefix = "G" add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 100)] user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup) assert user.maybe_split_groups(10) is True assert len(user.commands) == 10
def test_create_user_federatedid(): """ Test federated ID action with email address and no username """ user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.create(first_name="Example", last_name="User", country="US") assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "*****@*****.**", "firstname": "Example", "lastname": "User", "country": "US", "option": "ignoreIfAlreadyExists"}}], "user": "******"}
def test_remove_from_organization_delete_federatedid(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.remove_from_organization(delete_account=True) assert user.wire_dict() == { "do": [{ "removeFromOrg": { "deleteAccount": True } }], "user": "******" }
def test_update_user_federatedid_username(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.update(username="******") assert user.wire_dict() == { "do": [{ "update": { "username": "******" } }], "user": "******" }
def test_add_org_federatedid(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.add_to_groups() assert user.wire_dict() == { "do": [{ "add": { "group": [] } }], "user": "******" }
def test_add_products_federatedid_unicode(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.add_to_groups(groups=["Photoshop", u"Người vẽ minh hoạ"]) assert user.wire_dict() == { "do": [{ "add": { "group": ["Photoshop", u"Người vẽ minh hoạ"] } }], "user": "******" }
def test_add_role_enterpriseid(): user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_role(groups=["Photoshop", "Illustrator"]) assert user.wire_dict() == { "do": [{ "addRoles": { "admin": ["Photoshop", "Illustrator"] } }], "user": "******" }
def test_add_role_enterpriseid_unicode(): user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**") user.add_role(groups=[u"người quản lý"]) assert user.wire_dict() == { "do": [{ "addRoles": { "admin": [u"người quản lý"] } }], "user": "******" }
def test_remove_from_organization_adobeid(): user = UserAction(id_type='adobeID', email="*****@*****.**") user.remove_from_organization() assert user.wire_dict() == { "do": [{ "removeFromOrg": { "deleteAccount": False } }], "user": "******", "useAdobeID": True }
def test_add_products_federatedid(): user = UserAction(id_type=IdentityTypes.federatedID, email="*****@*****.**") user.add_to_groups(groups=["Photoshop", "Illustrator"]) assert user.wire_dict() == { "do": [{ "add": { "product": ["Photoshop", "Illustrator"] } }], "user": "******" }