Merge pull request #577 from christianlouis/copilot/create-user-auth-workflow

fix(templates): remove orphan `</div>` in google_drive.html breaking HTML accessibility lint
This commit is contained in:
Christian Krakau-Louis
2026-03-10 00:00:39 +01:00
committed by GitHub
16 changed files with 874 additions and 188 deletions
+100
View File
@@ -1,7 +1,12 @@
"""Tests for app/views/dropbox.py module."""
import json
from unittest.mock import patch
import pytest
from app.models import UserIntegration
@pytest.mark.integration
class TestDropboxViews:
@@ -44,3 +49,98 @@ class TestDropboxViews:
assert "oauth_integration_id" in body # The JS code is always present
# But integration_id template var should be empty
assert 'const integrationId = ""' in body
def test_dropbox_setup_user_mode_invalid_json_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is invalid JSON."""
owner_id = "user_invalid_json@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="DROPBOX",
name="My Dropbox (bad cfg)",
config="{INVALID JSON}",
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.dropbox.get_current_owner_id", return_value=owner_id):
response = client.get(f"/dropbox-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors despite the bad config
assert b"user_mode" not in response.content or b"Back to Integrations" in response.content
def test_dropbox_setup_user_mode_none_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is None (no folder path)."""
owner_id = "user_none_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="DROPBOX",
name="My Dropbox (no cfg)",
config=None,
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.dropbox.get_current_owner_id", return_value=owner_id):
response = client.get(f"/dropbox-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors, with empty folder_path
assert b"Back to Integrations" in response.content
def test_dropbox_setup_user_mode_watchfolder_config(self, client, db_session):
"""Test user-mode correctly loads folder_path from WATCH_FOLDER source config."""
owner_id = "user_wf_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="SOURCE",
integration_type="WATCH_FOLDER",
name="My Dropbox Watch",
config=json.dumps({"source_type": "dropbox", "folder_path": "/Inbox"}),
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.dropbox.get_current_owner_id", return_value=owner_id):
response = client.get(f"/dropbox-setup?integration_id={integration.id}")
assert response.status_code == 200
assert b"/Inbox" in response.content
assert b"Back to Integrations" in response.content
def test_dropbox_setup_user_mode_integration_not_found(self, client, db_session):
"""Test user-mode falls back to admin mode when integration not owned by user."""
with patch("app.views.dropbox.get_current_owner_id", return_value="other_user@example.com"):
response = client.get("/dropbox-setup?integration_id=999999")
assert response.status_code == 200
# Falls back to admin mode (no "Back to Integrations" link)
assert b"Dropbox Integration Setup" in response.content
"""Test user-mode correctly loads folder path from integration config."""
owner_id = "user_valid_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="DROPBOX",
name="My Dropbox",
config=json.dumps({"folder": "/Documents/Uploads"}),
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.dropbox.get_current_owner_id", return_value=owner_id):
response = client.get(f"/dropbox-setup?integration_id={integration.id}")
assert response.status_code == 200
assert b"/Documents/Uploads" in response.content
assert b"Back to Integrations" in response.content
+78
View File
@@ -1,10 +1,13 @@
"""Tests for app/views/google_drive.py module."""
import json
import urllib.parse
from unittest.mock import patch
import pytest
from app.models import UserIntegration
@pytest.mark.integration
class TestGoogleDriveViews:
@@ -156,3 +159,78 @@ class TestGoogleDriveViews:
response = client.get("/google-drive-setup")
assert response.status_code == 200
def test_google_drive_setup_user_mode_invalid_json_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is invalid JSON."""
owner_id = "user_gd_invalid_json@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="GOOGLE_DRIVE",
name="My GDrive (bad cfg)",
config="{INVALID JSON}",
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.google_drive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/google-drive-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors despite the bad config
assert b"Back to Integrations" in response.content
def test_google_drive_setup_user_mode_none_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is None (no folder ID)."""
owner_id = "user_gd_none_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="GOOGLE_DRIVE",
name="My GDrive (no cfg)",
config=None,
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.google_drive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/google-drive-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors, with empty folder_id
assert b"Back to Integrations" in response.content
def test_google_drive_setup_user_mode_integration_not_found(self, client, db_session):
"""Test user-mode falls back to admin mode when integration not owned by user."""
with patch("app.views.google_drive.get_current_owner_id", return_value="other_user@example.com"):
response = client.get("/google-drive-setup?integration_id=999999")
assert response.status_code == 200
# Falls back to admin mode (no "Back to Integrations" link)
assert b"Google Drive Integration Setup" in response.content
def test_google_drive_setup_user_mode_valid_config(self, client, db_session):
"""Test user-mode correctly loads folder ID from integration config."""
owner_id = "user_gd_valid_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="GOOGLE_DRIVE",
name="My Google Drive",
config=json.dumps({"folder_id": "1abc2def3ghi"}),
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.google_drive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/google-drive-setup?integration_id={integration.id}")
assert response.status_code == 200
assert b"1abc2def3ghi" in response.content
assert b"Back to Integrations" in response.content
+102
View File
@@ -1,7 +1,12 @@
"""Tests for app/views/onedrive.py module."""
import json
from unittest.mock import patch
import pytest
from app.models import UserIntegration
@pytest.mark.integration
class TestOnedriveViews:
@@ -42,3 +47,100 @@ class TestOnedriveViews:
body = response.text
assert "oauth_integration_id" in body
assert 'const integrationId = ""' in body
def test_onedrive_setup_user_mode_invalid_json_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is invalid JSON."""
owner_id = "user_od_invalid_json@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="ONEDRIVE",
name="My OneDrive (bad cfg)",
config="{INVALID JSON}",
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.onedrive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/onedrive-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors despite the bad config
assert b"Back to Integrations" in response.content
def test_onedrive_setup_user_mode_none_config(self, client, db_session):
"""Test user-mode renders correctly when integration.config is None (no folder path)."""
owner_id = "user_od_none_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="ONEDRIVE",
name="My OneDrive (no cfg)",
config=None,
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.onedrive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/onedrive-setup?integration_id={integration.id}")
assert response.status_code == 200
# Should render user mode without errors, with empty folder_path
assert b"Back to Integrations" in response.content
def test_onedrive_setup_user_mode_watchfolder_config(self, client, db_session):
"""Test user-mode correctly loads folder_path from WATCH_FOLDER source config."""
owner_id = "user_od_wf_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="SOURCE",
integration_type="WATCH_FOLDER",
name="My OneDrive Watch",
config=json.dumps({"source_type": "onedrive", "folder_path": "Work/Inbox"}),
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.onedrive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/onedrive-setup?integration_id={integration.id}")
assert response.status_code == 200
assert b"Work/Inbox" in response.content
assert b"Back to Integrations" in response.content
def test_onedrive_setup_user_mode_integration_not_found(self, client, db_session):
"""Test user-mode falls back to admin mode when integration not owned by user."""
with patch("app.views.onedrive.get_current_owner_id", return_value="other_user@example.com"):
response = client.get("/onedrive-setup?integration_id=999999")
assert response.status_code == 200
# Falls back to admin mode (no "Back to Integrations" link)
assert b"OneDrive Integration Setup" in response.content
def test_onedrive_setup_user_mode_valid_config(self, client, db_session):
"""Test user-mode correctly loads folder path from integration config."""
owner_id = "user_od_valid_cfg@example.com"
integration = UserIntegration(
owner_id=owner_id,
direction="DESTINATION",
integration_type="ONEDRIVE",
name="My OneDrive",
config=json.dumps({"folder_path": "Documents/Archive"}),
is_active=True,
)
db_session.add(integration)
db_session.commit()
db_session.refresh(integration)
with patch("app.views.onedrive.get_current_owner_id", return_value=owner_id):
response = client.get(f"/onedrive-setup?integration_id={integration.id}")
assert response.status_code == 200
assert b"Documents/Archive" in response.content
assert b"Back to Integrations" in response.content