style: apply ruff auto-fix
- Auto-formatted code with ruff format - Applied ruff linting fixes with --fix Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -249,9 +249,7 @@ class TestTestDropboxToken:
|
||||
mock_settings.dropbox_app_secret = "app-secret"
|
||||
mock_settings.http_request_timeout = 30
|
||||
|
||||
mock_post.side_effect = requests.exceptions.ConnectionError(
|
||||
"Connection refused"
|
||||
)
|
||||
mock_post.side_effect = requests.exceptions.ConnectionError("Connection refused")
|
||||
|
||||
response = client.get("/api/dropbox/test-token")
|
||||
|
||||
@@ -312,9 +310,7 @@ class TestSaveDropboxSettings:
|
||||
assert "new-token" in content
|
||||
|
||||
@patch("app.api.dropbox.settings")
|
||||
def test_save_settings_with_all_optional_fields(
|
||||
self, mock_settings, client, tmp_path
|
||||
):
|
||||
def test_save_settings_with_all_optional_fields(self, mock_settings, client, tmp_path):
|
||||
"""Test saving all Dropbox settings including optional fields."""
|
||||
mock_settings.dropbox_refresh_token = ""
|
||||
mock_settings.dropbox_app_key = ""
|
||||
|
||||
@@ -72,9 +72,7 @@ class TestExchangeOneDriveToken:
|
||||
@patch("app.api.onedrive.exchange_oauth_token")
|
||||
def test_exchange_token_error(self, mock_exchange, client: TestClient):
|
||||
"""Test token exchange with error from OAuth provider."""
|
||||
mock_exchange.side_effect = HTTPException(
|
||||
status_code=400, detail="Invalid authorization code"
|
||||
)
|
||||
mock_exchange.side_effect = HTTPException(status_code=400, detail="Invalid authorization code")
|
||||
|
||||
response = client.post(
|
||||
"/api/onedrive/exchange-token",
|
||||
@@ -109,9 +107,7 @@ class TestTestOneDriveToken:
|
||||
@patch("requests.post")
|
||||
@patch("requests.get")
|
||||
@patch("app.config.settings")
|
||||
def test_test_token_success(
|
||||
self, mock_settings, mock_get, mock_post, client: TestClient
|
||||
):
|
||||
def test_test_token_success(self, mock_settings, mock_get, mock_post, client: TestClient):
|
||||
"""Test successful token validation with properly mocked responses."""
|
||||
# Configure settings with property mocking
|
||||
type(mock_settings).onedrive_refresh_token = "test_refresh_token"
|
||||
@@ -162,9 +158,7 @@ class TestTestOneDriveToken:
|
||||
|
||||
@patch("requests.post")
|
||||
@patch("app.config.settings")
|
||||
def test_test_token_refresh_failed(
|
||||
self, mock_settings, mock_post, client: TestClient
|
||||
):
|
||||
def test_test_token_refresh_failed(self, mock_settings, mock_post, client: TestClient):
|
||||
"""Test when token refresh fails."""
|
||||
type(mock_settings).onedrive_refresh_token = "invalid_token"
|
||||
type(mock_settings).onedrive_client_id = "test_client_id"
|
||||
@@ -189,9 +183,7 @@ class TestTestOneDriveToken:
|
||||
@patch("requests.post")
|
||||
@patch("requests.get")
|
||||
@patch("app.config.settings")
|
||||
def test_test_token_new_refresh_token_issued(
|
||||
self, mock_settings, mock_get, mock_post, client: TestClient
|
||||
):
|
||||
def test_test_token_new_refresh_token_issued(self, mock_settings, mock_get, mock_post, client: TestClient):
|
||||
"""Test when Microsoft issues a new refresh token."""
|
||||
type(mock_settings).onedrive_refresh_token = "old_refresh_token"
|
||||
type(mock_settings).onedrive_client_id = "test_client_id"
|
||||
@@ -278,9 +270,7 @@ class TestTestOneDriveToken:
|
||||
@patch("requests.post")
|
||||
@patch("requests.get")
|
||||
@patch("app.config.settings")
|
||||
def test_test_token_user_info_failed(
|
||||
self, mock_settings, mock_get, mock_post, client: TestClient
|
||||
):
|
||||
def test_test_token_user_info_failed(self, mock_settings, mock_get, mock_post, client: TestClient):
|
||||
"""Test when user info request fails."""
|
||||
mock_settings.onedrive_refresh_token = "test_token"
|
||||
mock_settings.onedrive_client_id = "test_client_id"
|
||||
@@ -356,9 +346,7 @@ class TestSaveOneDriveSettings:
|
||||
@patch("os.path.exists")
|
||||
@patch("os.path.dirname")
|
||||
@patch("app.config.settings")
|
||||
def test_save_settings_success(
|
||||
self, mock_settings, mock_dirname, mock_exists, mock_file, client: TestClient
|
||||
):
|
||||
def test_save_settings_success(self, mock_settings, mock_dirname, mock_exists, mock_file, client: TestClient):
|
||||
"""Test successful save to .env file."""
|
||||
mock_exists.return_value = True
|
||||
mock_dirname.return_value = "/app"
|
||||
@@ -380,9 +368,7 @@ class TestSaveOneDriveSettings:
|
||||
|
||||
@patch("os.path.exists")
|
||||
@patch("os.path.dirname")
|
||||
def test_save_settings_env_file_not_found(
|
||||
self, mock_dirname, mock_exists, client: TestClient
|
||||
):
|
||||
def test_save_settings_env_file_not_found(self, mock_dirname, mock_exists, client: TestClient):
|
||||
"""Test that missing .env file is non-fatal — DB write still succeeds."""
|
||||
mock_exists.return_value = False
|
||||
mock_dirname.return_value = "/app"
|
||||
@@ -468,17 +454,13 @@ class TestSaveOneDriveSettings:
|
||||
|
||||
def test_save_settings_missing_required_field(self, client: TestClient):
|
||||
"""Test save without required refresh_token."""
|
||||
response = client.post(
|
||||
"/api/onedrive/save-settings", data={"tenant_id": "common"}
|
||||
)
|
||||
response = client.post("/api/onedrive/save-settings", data={"tenant_id": "common"})
|
||||
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
@patch("os.path.exists")
|
||||
@patch("os.path.dirname")
|
||||
def test_save_settings_exception_handling(
|
||||
self, mock_dirname, mock_exists, client: TestClient
|
||||
):
|
||||
def test_save_settings_exception_handling(self, mock_dirname, mock_exists, client: TestClient):
|
||||
"""Test that exceptions in .env write are non-fatal — DB write still succeeds."""
|
||||
mock_exists.side_effect = Exception("Unexpected error")
|
||||
|
||||
@@ -498,9 +480,7 @@ class TestUpdateOneDriveSettings:
|
||||
|
||||
@patch("app.tasks.upload_to_onedrive.get_onedrive_token")
|
||||
@patch("app.config.settings")
|
||||
def test_update_settings_success(
|
||||
self, mock_settings, mock_get_token, client: TestClient
|
||||
):
|
||||
def test_update_settings_success(self, mock_settings, mock_get_token, client: TestClient):
|
||||
"""Test successful settings update in memory."""
|
||||
mock_get_token.return_value = "test_token"
|
||||
|
||||
@@ -521,9 +501,7 @@ class TestUpdateOneDriveSettings:
|
||||
|
||||
@patch("app.tasks.upload_to_onedrive.get_onedrive_token")
|
||||
@patch("app.config.settings")
|
||||
def test_update_settings_minimal(
|
||||
self, mock_settings, mock_get_token, client: TestClient
|
||||
):
|
||||
def test_update_settings_minimal(self, mock_settings, mock_get_token, client: TestClient):
|
||||
"""Test update with only required fields."""
|
||||
mock_get_token.return_value = "test_token"
|
||||
|
||||
@@ -536,9 +514,7 @@ class TestUpdateOneDriveSettings:
|
||||
|
||||
@patch("app.tasks.upload_to_onedrive.get_onedrive_token")
|
||||
@patch("app.config.settings")
|
||||
def test_update_settings_token_test_fails(
|
||||
self, mock_settings, mock_get_token, client: TestClient
|
||||
):
|
||||
def test_update_settings_token_test_fails(self, mock_settings, mock_get_token, client: TestClient):
|
||||
"""Test update when token test fails."""
|
||||
mock_get_token.side_effect = Exception("Token invalid")
|
||||
|
||||
@@ -554,16 +530,12 @@ class TestUpdateOneDriveSettings:
|
||||
|
||||
def test_update_settings_missing_required_field(self, client: TestClient):
|
||||
"""Test update without required refresh_token."""
|
||||
response = client.post(
|
||||
"/api/onedrive/update-settings", data={"tenant_id": "common"}
|
||||
)
|
||||
response = client.post("/api/onedrive/update-settings", data={"tenant_id": "common"})
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
@patch("app.config.settings")
|
||||
def test_update_settings_exception_handling(
|
||||
self, mock_settings, client: TestClient
|
||||
):
|
||||
def test_update_settings_exception_handling(self, mock_settings, client: TestClient):
|
||||
"""Test exception handling in update settings."""
|
||||
mock_settings.onedrive_refresh_token = None
|
||||
|
||||
@@ -619,9 +591,7 @@ class TestGetOneDriveFullConfig:
|
||||
assert "status" in data
|
||||
|
||||
@patch("app.config.settings")
|
||||
def test_get_full_config_exception_handling(
|
||||
self, mock_settings, client: TestClient
|
||||
):
|
||||
def test_get_full_config_exception_handling(self, mock_settings, client: TestClient):
|
||||
"""Test exception handling in get full config."""
|
||||
# Even with exception, endpoint catches it
|
||||
response = client.get("/api/onedrive/get-full-config")
|
||||
@@ -676,9 +646,7 @@ class TestOneDriveIntegration:
|
||||
@patch("requests.post")
|
||||
@patch("requests.get")
|
||||
@patch("app.config.settings")
|
||||
def test_token_refresh_rotation(
|
||||
self, mock_settings, mock_get, mock_post, client: TestClient
|
||||
):
|
||||
def test_token_refresh_rotation(self, mock_settings, mock_get, mock_post, client: TestClient):
|
||||
"""Test token refresh with automatic rotation."""
|
||||
type(mock_settings).onedrive_refresh_token = "old_token"
|
||||
type(mock_settings).onedrive_client_id = "test_client_id"
|
||||
|
||||
@@ -45,9 +45,7 @@ class TestAuditLogOnSave:
|
||||
def test_save_creates_audit_entry(self, db_session):
|
||||
from app.utils.settings_service import save_setting_to_db
|
||||
|
||||
result = save_setting_to_db(
|
||||
db_session, "workdir", "/new/path", changed_by="alice"
|
||||
)
|
||||
result = save_setting_to_db(db_session, "workdir", "/new/path", changed_by="alice")
|
||||
|
||||
assert result is True
|
||||
entry = db_session.query(SettingsAuditLog).filter_by(key="workdir").first()
|
||||
@@ -73,18 +71,13 @@ class TestAuditLogOnSave:
|
||||
assert update_entry.new_value == "/new/path"
|
||||
|
||||
def test_delete_creates_audit_entry(self, db_session):
|
||||
from app.utils.settings_service import (delete_setting_from_db,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import delete_setting_from_db, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/some/path", changed_by="admin")
|
||||
result = delete_setting_from_db(db_session, "workdir", changed_by="carol")
|
||||
|
||||
assert result is True
|
||||
delete_entry = (
|
||||
db_session.query(SettingsAuditLog)
|
||||
.filter_by(key="workdir", action="delete")
|
||||
.first()
|
||||
)
|
||||
delete_entry = db_session.query(SettingsAuditLog).filter_by(key="workdir", action="delete").first()
|
||||
assert delete_entry is not None
|
||||
assert delete_entry.old_value == "/some/path"
|
||||
assert delete_entry.new_value is None
|
||||
@@ -93,9 +86,7 @@ class TestAuditLogOnSave:
|
||||
def test_delete_nonexistent_returns_false_no_entry(self, db_session):
|
||||
from app.utils.settings_service import delete_setting_from_db
|
||||
|
||||
result = delete_setting_from_db(
|
||||
db_session, "nonexistent_key", changed_by="admin"
|
||||
)
|
||||
result = delete_setting_from_db(db_session, "nonexistent_key", changed_by="admin")
|
||||
|
||||
assert result is False
|
||||
assert db_session.query(SettingsAuditLog).count() == 0
|
||||
@@ -119,8 +110,7 @@ class TestGetAuditLog:
|
||||
"""get_audit_log returns entries, masks sensitive values."""
|
||||
|
||||
def test_returns_all_entries_most_recent_first(self, db_session):
|
||||
from app.utils.settings_service import (get_audit_log,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_audit_log, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/first", changed_by="u1")
|
||||
save_setting_to_db(db_session, "workdir", "/second", changed_by="u2")
|
||||
@@ -133,12 +123,9 @@ class TestGetAuditLog:
|
||||
assert log[1]["new_value"] == "/first"
|
||||
|
||||
def test_sensitive_values_are_masked(self, db_session):
|
||||
from app.utils.settings_service import (get_audit_log,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_audit_log, save_setting_to_db
|
||||
|
||||
save_setting_to_db(
|
||||
db_session, "openai_api_key", "sk-secret123", changed_by="admin"
|
||||
)
|
||||
save_setting_to_db(db_session, "openai_api_key", "sk-secret123", changed_by="admin")
|
||||
|
||||
log = get_audit_log(db_session)
|
||||
|
||||
@@ -146,8 +133,7 @@ class TestGetAuditLog:
|
||||
assert entry["new_value"] == "[REDACTED]"
|
||||
|
||||
def test_required_fields_present(self, db_session):
|
||||
from app.utils.settings_service import (get_audit_log,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_audit_log, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/path", changed_by="alice")
|
||||
|
||||
@@ -167,8 +153,7 @@ class TestGetAuditLog:
|
||||
assert field in entry
|
||||
|
||||
def test_limit_and_offset(self, db_session):
|
||||
from app.utils.settings_service import (get_audit_log,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_audit_log, save_setting_to_db
|
||||
|
||||
for i in range(5):
|
||||
save_setting_to_db(db_session, "workdir", f"/path{i}", changed_by="admin")
|
||||
@@ -190,8 +175,7 @@ class TestGetSettingHistory:
|
||||
"""get_setting_history returns only entries for the requested key."""
|
||||
|
||||
def test_returns_only_matching_key(self, db_session):
|
||||
from app.utils.settings_service import (get_setting_history,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_setting_history, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/wdir", changed_by="admin")
|
||||
save_setting_to_db(db_session, "debug", "true", changed_by="admin")
|
||||
@@ -219,32 +203,21 @@ class TestRollbackSetting:
|
||||
"""rollback_setting reinstates the value from a given audit log entry."""
|
||||
|
||||
def test_rollback_to_previous_value(self, db_session):
|
||||
from app.utils.settings_service import (get_setting_from_db,
|
||||
rollback_setting,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import get_setting_from_db, rollback_setting, save_setting_to_db
|
||||
|
||||
save_setting_to_db(
|
||||
db_session, "workdir", "/v1", changed_by="admin"
|
||||
) # entry id 1
|
||||
save_setting_to_db(
|
||||
db_session, "workdir", "/v2", changed_by="admin"
|
||||
) # entry id 2
|
||||
save_setting_to_db(db_session, "workdir", "/v1", changed_by="admin") # entry id 1
|
||||
save_setting_to_db(db_session, "workdir", "/v2", changed_by="admin") # entry id 2
|
||||
|
||||
first_entry = (
|
||||
db_session.query(SettingsAuditLog).filter_by(key="workdir").first()
|
||||
)
|
||||
first_entry = db_session.query(SettingsAuditLog).filter_by(key="workdir").first()
|
||||
# first entry has new_value="/v1"
|
||||
success = rollback_setting(
|
||||
db_session, "workdir", first_entry.id, changed_by="rollbacker"
|
||||
)
|
||||
success = rollback_setting(db_session, "workdir", first_entry.id, changed_by="rollbacker")
|
||||
|
||||
assert success is True
|
||||
current = get_setting_from_db(db_session, "workdir")
|
||||
assert current == "/v1"
|
||||
|
||||
def test_rollback_creates_new_audit_entry(self, db_session):
|
||||
from app.utils.settings_service import (rollback_setting,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import rollback_setting, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/v1", changed_by="admin")
|
||||
entry = db_session.query(SettingsAuditLog).filter_by(key="workdir").first()
|
||||
@@ -255,8 +228,7 @@ class TestRollbackSetting:
|
||||
assert db_session.query(SettingsAuditLog).count() == initial_count + 1
|
||||
|
||||
def test_rollback_wrong_history_id_returns_false(self, db_session):
|
||||
from app.utils.settings_service import (rollback_setting,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import rollback_setting, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/v1", changed_by="admin")
|
||||
|
||||
@@ -265,8 +237,7 @@ class TestRollbackSetting:
|
||||
assert result is False
|
||||
|
||||
def test_rollback_wrong_key_returns_false(self, db_session):
|
||||
from app.utils.settings_service import (rollback_setting,
|
||||
save_setting_to_db)
|
||||
from app.utils.settings_service import rollback_setting, save_setting_to_db
|
||||
|
||||
save_setting_to_db(db_session, "workdir", "/v1", changed_by="admin")
|
||||
entry = db_session.query(SettingsAuditLog).filter_by(key="workdir").first()
|
||||
@@ -287,8 +258,7 @@ class TestNotifySettingsUpdated:
|
||||
"""notify_settings_updated publishes the settings version key to Redis."""
|
||||
|
||||
def test_sets_redis_key(self):
|
||||
from app.utils.settings_sync import (SETTINGS_VERSION_KEY,
|
||||
notify_settings_updated)
|
||||
from app.utils.settings_sync import SETTINGS_VERSION_KEY, notify_settings_updated
|
||||
|
||||
mock_redis = MagicMock()
|
||||
mock_redis_instance = MagicMock()
|
||||
@@ -394,9 +364,7 @@ class TestHistoryEndpoint:
|
||||
mock_db = MagicMock()
|
||||
mock_admin = {"is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
get_key_history("workdir", mock_request, mock_db, mock_admin)
|
||||
)
|
||||
result = asyncio.run(get_key_history("workdir", mock_request, mock_db, mock_admin))
|
||||
|
||||
assert result["key"] == "workdir"
|
||||
assert len(result["history"]) == 1
|
||||
@@ -421,9 +389,7 @@ class TestRollbackEndpoint:
|
||||
mock_db = MagicMock()
|
||||
mock_admin = {"is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
rollback_setting_to_history("workdir", 1, mock_request, mock_db, mock_admin)
|
||||
)
|
||||
result = asyncio.run(rollback_setting_to_history("workdir", 1, mock_request, mock_db, mock_admin))
|
||||
|
||||
assert result["success"] is True
|
||||
mock_notify.assert_called_once()
|
||||
@@ -443,10 +409,6 @@ class TestRollbackEndpoint:
|
||||
mock_admin = {"is_admin": True}
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
asyncio.run(
|
||||
rollback_setting_to_history(
|
||||
"workdir", 9999, mock_request, mock_db, mock_admin
|
||||
)
|
||||
)
|
||||
asyncio.run(rollback_setting_to_history("workdir", 9999, mock_request, mock_db, mock_admin))
|
||||
|
||||
assert exc_info.value.status_code == 404
|
||||
|
||||
@@ -48,9 +48,7 @@ class TestSetupWizardDbPersist:
|
||||
|
||||
@patch("app.views.wizard.notify_settings_updated")
|
||||
@patch("app.views.wizard.save_setting_to_db")
|
||||
def test_notify_not_called_when_no_settings_saved(
|
||||
self, mock_save, mock_notify, client
|
||||
):
|
||||
def test_notify_not_called_when_no_settings_saved(self, mock_save, mock_notify, client):
|
||||
"""Test that notify_settings_updated is NOT called when saved_count == 0."""
|
||||
mock_save.return_value = False
|
||||
|
||||
@@ -65,9 +63,7 @@ class TestSetupWizardDbPersist:
|
||||
@patch("app.views.wizard.notify_settings_updated")
|
||||
@patch("app.views.wizard.secrets.token_hex")
|
||||
@patch("app.views.wizard.save_setting_to_db")
|
||||
def test_auto_generate_session_secret(
|
||||
self, mock_save, mock_token, mock_notify, client
|
||||
):
|
||||
def test_auto_generate_session_secret(self, mock_save, mock_token, mock_notify, client):
|
||||
"""Test that session_secret auto-generate path produces a real token."""
|
||||
mock_save.return_value = True
|
||||
mock_token.return_value = "deadbeef" * 8
|
||||
@@ -136,9 +132,7 @@ class TestDropboxSaveSettingsDbPersist:
|
||||
@patch("app.api.dropbox.settings")
|
||||
@patch("app.api.dropbox.notify_settings_updated")
|
||||
@patch("app.api.dropbox.save_setting_to_db")
|
||||
def test_db_written_even_when_env_missing(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_db_written_even_when_env_missing(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that DB is written even when .env doesn't exist (no exception)."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -157,9 +151,7 @@ class TestDropboxSaveSettingsDbPersist:
|
||||
@patch("app.api.dropbox.settings")
|
||||
@patch("app.api.dropbox.notify_settings_updated")
|
||||
@patch("app.api.dropbox.save_setting_to_db")
|
||||
def test_notify_settings_updated_called(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_notify_settings_updated_called(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that notify_settings_updated is called."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -175,9 +167,7 @@ class TestDropboxSaveSettingsDbPersist:
|
||||
@patch("app.api.dropbox.settings")
|
||||
@patch("app.api.dropbox.notify_settings_updated")
|
||||
@patch("app.api.dropbox.save_setting_to_db")
|
||||
def test_all_provided_values_persisted(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_all_provided_values_persisted(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that all provided values are persisted to DB."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -212,9 +202,7 @@ class TestGoogleDriveUpdateSettingsDbPersist:
|
||||
@patch("app.api.google_drive.settings")
|
||||
@patch("app.api.google_drive.notify_settings_updated")
|
||||
@patch("app.api.google_drive.save_setting_to_db")
|
||||
def test_db_written_for_each_provided_field(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_db_written_for_each_provided_field(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that DB is written for each provided field."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -241,9 +229,7 @@ class TestGoogleDriveUpdateSettingsDbPersist:
|
||||
@patch("app.api.google_drive.settings")
|
||||
@patch("app.api.google_drive.notify_settings_updated")
|
||||
@patch("app.api.google_drive.save_setting_to_db")
|
||||
def test_use_oauth_saved_as_lowercase_string(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_use_oauth_saved_as_lowercase_string(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that use_oauth is saved as 'true' or 'false' string."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -253,11 +239,7 @@ class TestGoogleDriveUpdateSettingsDbPersist:
|
||||
follow_redirects=False,
|
||||
)
|
||||
|
||||
use_oauth_calls = [
|
||||
call
|
||||
for call in mock_save.call_args_list
|
||||
if call[0][1] == "google_drive_use_oauth"
|
||||
]
|
||||
use_oauth_calls = [call for call in mock_save.call_args_list if call[0][1] == "google_drive_use_oauth"]
|
||||
assert len(use_oauth_calls) == 1
|
||||
assert use_oauth_calls[0][0][2] in ("true", "false")
|
||||
|
||||
@@ -289,9 +271,7 @@ class TestOneDriveSaveSettingsDbPersist:
|
||||
@patch("app.api.onedrive.settings")
|
||||
@patch("app.api.onedrive.notify_settings_updated")
|
||||
@patch("app.api.onedrive.save_setting_to_db")
|
||||
def test_db_written_even_without_env_file(
|
||||
self, mock_save, mock_notify, mock_settings, client
|
||||
):
|
||||
def test_db_written_even_without_env_file(self, mock_save, mock_notify, mock_settings, client):
|
||||
"""Test that DB is written even when .env file does not exist."""
|
||||
mock_save.return_value = True
|
||||
|
||||
@@ -435,9 +415,7 @@ class TestExportEnvEndpoint:
|
||||
mock_request = MagicMock()
|
||||
mock_admin = {"id": "admin", "is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
export_env_settings(mock_request, db_session, mock_admin, source="db")
|
||||
)
|
||||
result = asyncio.run(export_env_settings(mock_request, db_session, mock_admin, source="db"))
|
||||
assert result.media_type == "text/plain"
|
||||
|
||||
def test_content_disposition_header(self, db_session):
|
||||
@@ -449,9 +427,7 @@ class TestExportEnvEndpoint:
|
||||
mock_request = MagicMock()
|
||||
mock_admin = {"id": "admin", "is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
export_env_settings(mock_request, db_session, mock_admin, source="db")
|
||||
)
|
||||
result = asyncio.run(export_env_settings(mock_request, db_session, mock_admin, source="db"))
|
||||
cd = result.headers.get("content-disposition", "")
|
||||
assert "attachment" in cd
|
||||
assert ".env" in cd
|
||||
@@ -468,11 +444,7 @@ class TestExportEnvEndpoint:
|
||||
mock_admin = {"id": "admin", "is_admin": True}
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
asyncio.run(
|
||||
export_env_settings(
|
||||
mock_request, db_session, mock_admin, source="invalid"
|
||||
)
|
||||
)
|
||||
asyncio.run(export_env_settings(mock_request, db_session, mock_admin, source="invalid"))
|
||||
assert exc_info.value.status_code == 400
|
||||
|
||||
def test_default_source_is_db(self, db_session):
|
||||
@@ -497,11 +469,7 @@ class TestExportEnvEndpoint:
|
||||
mock_request = MagicMock()
|
||||
mock_admin = {"id": "admin", "is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
export_env_settings(
|
||||
mock_request, db_session, mock_admin, source="effective"
|
||||
)
|
||||
)
|
||||
result = asyncio.run(export_env_settings(mock_request, db_session, mock_admin, source="effective"))
|
||||
assert result.media_type == "text/plain"
|
||||
|
||||
def test_output_contains_docuelevate_header(self, db_session):
|
||||
@@ -513,7 +481,5 @@ class TestExportEnvEndpoint:
|
||||
mock_request = MagicMock()
|
||||
mock_admin = {"id": "admin", "is_admin": True}
|
||||
|
||||
result = asyncio.run(
|
||||
export_env_settings(mock_request, db_session, mock_admin, source="db")
|
||||
)
|
||||
result = asyncio.run(export_env_settings(mock_request, db_session, mock_admin, source="db"))
|
||||
assert b"DocuElevate" in result.body
|
||||
|
||||
Reference in New Issue
Block a user