-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from CodethinkLabs/bobclough/suitecrm_disable…
…_users target_suitecrm: add functionality to disable accounts instead of delete
- Loading branch information
Showing
3 changed files
with
178 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"pytest-cov", | ||
"pytest-mock", | ||
"pytest-pylint", | ||
"black", | ||
], | ||
}, | ||
python_requires=">=3.7", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,30 @@ | |
|
||
|
||
@pytest.fixture(name="basic_config") | ||
def fixture_config(): | ||
def fixture_basic_config(): | ||
"""Create a config""" | ||
config = { | ||
"url": "127.0.0.1:8080", | ||
"api_username": "user", | ||
"api_password": "bitnami", | ||
"api_client_id": "asd", | ||
"api_client_secret": "secret", | ||
"excluded_usernames": ["excluded"], | ||
} | ||
return config | ||
|
||
|
||
@pytest.fixture(name="users_disable_config") | ||
def fixture_users_disable_config(): | ||
"""Create a config""" | ||
config = { | ||
"url": "127.0.0.1:8080", | ||
"api_username": "user", | ||
"api_password": "bitnami", | ||
"api_client_id": "asd", | ||
"api_client_secret": "secret", | ||
"delete_absent_users": False, | ||
"excluded_usernames": ["excluded"], | ||
} | ||
return config | ||
|
||
|
@@ -376,26 +392,123 @@ def test_user_delete(basic_target, suitecrm_server): | |
"status": "Active", | ||
} | ||
) | ||
server.create_user( | ||
{ | ||
"user_name": "excluded", | ||
"first_name": "Ernie", | ||
"last_name": "Excluded", | ||
"email1": "[email protected]", | ||
"status": "Active", | ||
} | ||
) | ||
|
||
remaining_user = User( | ||
"adalice", forename="Ad", surname="Alice", email=("[email protected]",) | ||
) | ||
deleted_user = User( | ||
"basicuser", forename="Basic", surname="Bob", email=("[email protected]",) | ||
) | ||
excluded_user = User( | ||
"excluded", | ||
forename="Ernie", | ||
surname="Excluded", | ||
email=("[email protected]",), | ||
) | ||
|
||
diff = ModelDifference( | ||
source_users={ | ||
"adAlice": remaining_user, | ||
"basicuser": deleted_user, | ||
"excluded": excluded_user, | ||
}, | ||
target_users={"adAlice": remaining_user}, | ||
added_users={}, | ||
changed_users={}, | ||
unchanged_users={"adAlice": remaining_user}, | ||
removed_users={"basicuser": deleted_user, "excluded": excluded_user}, | ||
) | ||
|
||
basic_target.users_cleanup(diff) | ||
users = server.search_by_type("User") | ||
assert any(user["attributes"]["first_name"] == "Ad" for user in users) | ||
assert any(user["attributes"]["first_name"] == "Ernie" for user in users) | ||
|
||
|
||
def test_users_disable(users_disable_target, suitecrm_server): | ||
"""Delete a user and check it's been deleted""" | ||
server = suitecrm_server([]) | ||
server.create_user( | ||
{ | ||
"user_name": "adalice", | ||
"first_name": "Ad", | ||
"last_name": "Alice", | ||
"email1": "[email protected]", | ||
"status": "Active", | ||
} | ||
) | ||
server.create_user( | ||
{ | ||
"user_name": "basicuser", | ||
"first_name": "Basic", | ||
"last_name": "Bob", | ||
"full_name": "Basic Bob", | ||
"email1": "[email protected]", | ||
"status": "Active", | ||
} | ||
) | ||
server.create_user( | ||
{ | ||
"user_name": "excluded", | ||
"first_name": "Ernie", | ||
"last_name": "Excluded", | ||
"email1": "[email protected]", | ||
"status": "Active", | ||
} | ||
) | ||
|
||
remaining_user = User( | ||
"adalice", forename="Ad", surname="Alice", email=("[email protected]",) | ||
) | ||
deleted_user = User( | ||
"basicuser", forename="Basic", surname="Bob", email=("[email protected]",) | ||
) | ||
excluded_user = User( | ||
"excluded", | ||
forename="Ernie", | ||
surname="Excluded", | ||
email=("[email protected]",), | ||
) | ||
|
||
diff = ModelDifference( | ||
source_users={"basicuser": deleted_user, "adAlice": remaining_user}, | ||
source_users={ | ||
"adAlice": remaining_user, | ||
"basicuser": deleted_user, | ||
"excluded": excluded_user, | ||
}, | ||
target_users={"adAlice": remaining_user}, | ||
added_users={}, | ||
changed_users={}, | ||
unchanged_users={"adAlice": remaining_user}, | ||
removed_users={"basicuser": deleted_user}, | ||
removed_users={"basicuser": deleted_user, "excluded": excluded_user}, | ||
) | ||
|
||
basic_target.users_cleanup(diff) | ||
users_disable_target.users_cleanup(diff) | ||
users = server.search_by_type("User") | ||
assert users[0]["attributes"]["first_name"] == "Ad" | ||
assert any( | ||
user["attributes"]["first_name"] == "Ad" | ||
and user["attributes"]["status"] == "Active" | ||
for user in users | ||
) | ||
assert any( | ||
user["attributes"]["first_name"] == "Basic" | ||
and user["attributes"]["status"] == "Inactive" | ||
for user in users | ||
) | ||
assert any( | ||
user["attributes"]["first_name"] == "Ernie" | ||
and user["attributes"]["status"] == "Active" | ||
for user in users | ||
) | ||
|
||
|
||
def test_groups_emails_sync_no_changes(basic_config, suitecrm_server): | ||
|
@@ -595,3 +708,10 @@ def fixture_basic_target(basic_config): | |
"""Create a TargetSuiteCRM with default config""" | ||
target = TargetSuiteCRM(basic_config, None) | ||
return target | ||
|
||
|
||
@pytest.fixture(name="users_disable_target") | ||
def fixture_users_disable_target(users_disable_config): | ||
"""Create a TargetSuiteCRM with config set up to disable users instead of deleting them""" | ||
target = TargetSuiteCRM(users_disable_config, None) | ||
return target |