Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-burt-uch committed Jan 22, 2025
1 parent df0a682 commit cda0234
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/dbgap_sync/test_user_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_sync(
"phs000178.c999": ["read", "read-storage"],
"phs000179.c1": ["read", "read-storage"],
"PROJECT-12345": ["read", "read-storage"],
"test_common_exchange_area": ["read-storage", "read"],
},
)
else:
Expand All @@ -154,6 +155,7 @@ def test_sync(
"phs000178.c2": ["read", "read-storage"],
"phs000178.c999": ["read", "read-storage"],
"phs000179.c1": ["read", "read-storage"],
"test_common_exchange_area": ["read", "read-storage"],
},
)

Expand Down Expand Up @@ -490,29 +492,40 @@ def test_sync_with_google_errors(syncer, monkeypatch):
syncer._update_arborist = MagicMock()
syncer._update_authz_in_arborist = MagicMock()

with patch("fence.sync.sync_users.update_google_groups_for_users") as mock_bulk_update:
with patch(
"fence.sync.sync_users.update_google_groups_for_users"
) as mock_bulk_update:
mock_bulk_update.side_effect = GoogleUpdateException("Something's Wrong!")
with pytest.raises(GoogleUpdateException):
syncer.sync()

syncer._update_arborist.assert_called()
syncer._update_authz_in_arborist.assert_called()


@patch("fence.sync.sync_users.paramiko.SSHClient")
@patch("os.makedirs")
@patch("os.path.exists", return_value=False)
@pytest.mark.parametrize("syncer", ["google", "cleversafe"], indirect=True)
def test_sync_with_sftp_connection_errors(mock_path, mock_makedir, mock_ssh_client, syncer, monkeypatch):
def test_sync_with_sftp_connection_errors(
mock_path, mock_makedir, mock_ssh_client, syncer, monkeypatch
):
"""
Verifies that when there is an sftp connection error connection, that the connection is retried the max amount of
tries as configured by DEFAULT_BACKOFF_SETTINGS
"""
monkeypatch.setattr(syncer, "is_sync_from_dbgap_server", True)
mock_ssh_client.return_value.__enter__.return_value.connect.side_effect = Exception("Authentication timed out")
mock_ssh_client.return_value.__enter__.return_value.connect.side_effect = Exception(
"Authentication timed out"
)
# usersync System Exits if any exception is raised during download.
with pytest.raises(SystemExit):
syncer.sync()
assert mock_ssh_client.return_value.__enter__.return_value.connect.call_count == DEFAULT_BACKOFF_SETTINGS['max_tries']
assert (
mock_ssh_client.return_value.__enter__.return_value.connect.call_count
== DEFAULT_BACKOFF_SETTINGS["max_tries"]
)


@pytest.mark.parametrize("syncer", ["google", "cleversafe"], indirect=True)
def test_sync_from_files(syncer, db_session, storage_client):
Expand Down Expand Up @@ -1063,6 +1076,7 @@ def test_revoke_all_policies_no_user(db_session, syncer):
# we only care that this doesn't error
assert True


@pytest.mark.parametrize("syncer", ["cleversafe", "google"], indirect=True)
def test_revoke_all_policies_preserve_mfa(monkeypatch, db_session, syncer):
"""
Expand Down

0 comments on commit cda0234

Please sign in to comment.