|
| 1 | +# Copyright (c) 2016 Adobe Systems Incorporated. All rights reserved. |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +# of this software and associated documentation files (the "Software"), to deal |
| 5 | +# in the Software without restriction, including without limitation the rights |
| 6 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +# copies of the Software, and to permit persons to whom the Software is |
| 8 | +# furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included in all |
| 11 | +# copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +# SOFTWARE. |
| 20 | + |
| 21 | +import pytest |
| 22 | + |
| 23 | +from umapi_client import IdentityTypes |
| 24 | +from umapi_client import UserAction |
| 25 | + |
| 26 | + |
| 27 | +def test_user_adobeid(): |
| 28 | + user = UserAction( email="[email protected]") |
| 29 | + assert user. wire_dict() == { "do": [], "user": "[email protected]"} |
| 30 | + |
| 31 | + |
| 32 | +def test_user_enterpriseid(): |
| 33 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 34 | + assert user. wire_dict() == { "do": [], "user": "[email protected]"} |
| 35 | + |
| 36 | + |
| 37 | +def test_user_enterpriseid_username(): |
| 38 | + with pytest.raises(ValueError): |
| 39 | + user = UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net") |
| 40 | + |
| 41 | + |
| 42 | +def test_user_federatedid(): |
| 43 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 44 | + assert user. wire_dict() == { "do": [], "user": "[email protected]"} |
| 45 | + |
| 46 | + |
| 47 | +def test_user_federatedid_username(): |
| 48 | + user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net") |
| 49 | + assert user.wire_dict() == {"do": [], "user": "dbrotsky", "domain": "k.on-the-side.net"} |
| 50 | + |
| 51 | + |
| 52 | +def test_create_user_adobeid(): |
| 53 | + user = UserAction( email="[email protected]") |
| 54 | + user.create() |
| 55 | + assert user. wire_dict() == { "do": [{ "addAdobeID": { "email": "[email protected]"}}], |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +def test_create_user_adobeid_country(): |
| 60 | + user = UserAction( email="[email protected]") |
| 61 | + with pytest.raises(ValueError): |
| 62 | + user.create(country="US") |
| 63 | + |
| 64 | + |
| 65 | +def test_create_user_enterpriseid(): |
| 66 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 67 | + user.create(first_name="Daniel", last_name="Brotsky") |
| 68 | + assert user. wire_dict() == { "do": [{ "createEnterpriseID": { "email": "[email protected]", |
| 69 | + "firstName": "Daniel", "lastName": "Brotsky", |
| 70 | + "country": "UD"}}], |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +def test_create_user_federatedid(): |
| 75 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 76 | + user.create(first_name="Daniel", last_name="Brotsky", country="US") |
| 77 | + assert user. wire_dict() == { "do": [{ "createFederatedID": { "email": "[email protected]", |
| 78 | + "firstName": "Daniel", "lastName": "Brotsky", |
| 79 | + "country": "US"}}], |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +def test_create_user_federatedid_username(): |
| 84 | + user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net") |
| 85 | + user. create( first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]") |
| 86 | + assert user. wire_dict() == { "do": [{ "createFederatedID": { "email": "[email protected]", |
| 87 | + "firstName": "Daniel", "lastName": "Brotsky", |
| 88 | + "country": "US"}}], |
| 89 | + "user": "dbrotsky", "domain": "k.on-the-side.net"} |
| 90 | + |
| 91 | + |
| 92 | +def test_create_user_federatedid_username_mismatch(): |
| 93 | + user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net") |
| 94 | + with pytest.raises(ValueError): |
| 95 | + user. create( first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]") |
| 96 | + |
| 97 | + |
| 98 | +def test_update_user_federatedid(): |
| 99 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 100 | + user.update(first_name="Johnny", last_name="Danger") |
| 101 | + assert user.wire_dict() == {"do": [{"update": {"firstName": "Johnny", "lastName": "Danger"}}], |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +def test_update_user_enterpriseid_username(): |
| 106 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 107 | + with pytest.raises(ValueError): |
| 108 | + user.update(username="dbrotsky1") |
| 109 | + |
| 110 | + |
| 111 | +def test_update_user_federatedid_username(): |
| 112 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 113 | + user.update(username="dbrotsky1") |
| 114 | + assert user.wire_dict() == {"do": [{"update": {"username": "dbrotsky1"}}], |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +def test_add_product_federatedid(): |
| 119 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 120 | + user.add_group(groups=["Photoshop", "Illustrator"]) |
| 121 | + assert user.wire_dict() == {"do": [{"add": {"product": ["Photoshop", "Illustrator"]}}], |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +def test_remove_product_federatedid(): |
| 126 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 127 | + user.remove_group(groups=["Photoshop", "Illustrator"]) |
| 128 | + assert user.wire_dict() == {"do": [{"remove": {"product": ["Photoshop", "Illustrator"]}}], |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +def test_remove_product_federatedid_all(): |
| 133 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 134 | + user.remove_group(all_groups=True) |
| 135 | + assert user.wire_dict() == {"do": [{"remove": "all"}], |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +def test_add_role_enterpriseid(): |
| 140 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 141 | + user.add_role(groups=["Photoshop", "Illustrator"]) |
| 142 | + assert user.wire_dict() == {"do": [{"addRoles": {"admin": ["Photoshop", "Illustrator"]}}], |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +def test_remove_role_enterpriseid(): |
| 147 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 148 | + user.remove_role(groups=["Photoshop", "Illustrator"]) |
| 149 | + assert user.wire_dict() == {"do": [{"removeRoles": {"admin": ["Photoshop", "Illustrator"]}}], |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +def test_remove_from_organization_federatedid(): |
| 154 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 155 | + user.remove_from_organization() |
| 156 | + assert user.wire_dict() == {"do": [{"removeFromOrg": {}}], |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | +def test_remove_from_organization_adobeid(): |
| 161 | + user = UserAction( id_type=IdentityTypes. adobeID, email="[email protected]") |
| 162 | + user.remove_from_organization() |
| 163 | + assert user.wire_dict() == {"do": [{"removeFromOrg": {}}], |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | +def test_remove_from_organization_delete_federatedid(): |
| 168 | + user = UserAction( id_type=IdentityTypes. federatedID, email="[email protected]") |
| 169 | + user.remove_from_organization(delete_account=True) |
| 170 | + assert user.wire_dict() == {"do": [{"removeFromOrg": {"removedDomain": "k.on-the-side.net"}}], |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +def test_remove_from_organization_delete_adobeid(): |
| 175 | + user = UserAction( id_type=IdentityTypes. adobeID, email="[email protected]") |
| 176 | + with pytest.raises(ValueError): |
| 177 | + user.remove_from_organization(delete_account=True) |
| 178 | + |
| 179 | + |
| 180 | +def test_delete_account_enterpriseid(): |
| 181 | + user = UserAction( id_type=IdentityTypes. enterpriseID, email="[email protected]") |
| 182 | + user.delete_account() |
| 183 | + assert user.wire_dict() == {"do": [{"removeFromDomain": {"domain": "o.on-the-side.net"}}], |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | +def test_delete_account_adobeid(): |
| 188 | + user = UserAction( id_type=IdentityTypes. adobeID, email="[email protected]") |
| 189 | + with pytest.raises(ValueError): |
| 190 | + user.delete_account() |
0 commit comments