| import os |
|
|
| import pytest |
|
|
| from src.server.services.auth_service import AuthService |
| from src.server.services.blog_service import BlogService |
|
|
|
|
| |
| @pytest.mark.skipif( |
| not os.getenv("SUPABASE_URL") or not os.getenv("SUPABASE_SERVICE_KEY"), reason="Requires real Supabase credentials" |
| ) |
| class TestSupabaseIntegration: |
| @pytest.fixture |
| def auth_service(self): |
| return AuthService() |
|
|
| @pytest.fixture |
| def blog_service(self): |
| return BlogService() |
|
|
| def test_auth_service_create_user_syntax(self, auth_service): |
| """ |
| Verifies that the Supabase client syntax for creating users is correct. |
| We don't actually want to spam the auth user database, so we might just |
| test the profile insertion part if possible, or create a dummy user and clean it up. |
| |
| However, the specific error 'SyncQueryRequestBuilder object has no attribute select' |
| happens during the DB query construction/execution. |
| """ |
| |
| |
| |
|
|
| |
| |
| dummy_id = "00000000-0000-0000-0000-000000000000" |
|
|
| try: |
| |
| profile_data = { |
| "id": dummy_id, |
| "email": "integration_test@example.com", |
| "name": "Integration Test", |
| "role": "member", |
| "status": "active", |
| } |
|
|
| |
| |
| response = auth_service.supabase_client.table("profiles").upsert(profile_data).execute() |
|
|
| assert response is not None |
| |
|
|
| except AttributeError as e: |
| pytest.fail(f"Supabase client syntax error: {e}") |
| except Exception as e: |
| |
| print(f"Operational error (expected): {e}") |
|
|
| finally: |
| |
| try: |
| print(f"Cleaning up test profile {dummy_id}") |
| auth_service.supabase_client.table("profiles").delete().eq("id", dummy_id).execute() |
| except Exception as cleanup_error: |
| print(f"Failed to cleanup test data: {cleanup_error}") |
|
|
| def test_blog_service_update_syntax(self, blog_service): |
| """ |
| Verifies the update syntax for blog posts. |
| """ |
| dummy_id = "00000000-0000-0000-0000-000000000000" |
|
|
| try: |
| |
| update_data = {"title": "Updated Title"} |
|
|
| |
| |
| blog_service.supabase_client.table("blog_posts").update(update_data).eq("id", dummy_id).execute() |
|
|
| except AttributeError as e: |
| pytest.fail(f"Supabase client syntax error: {e}") |
| except Exception: |
| |
| pass |
|
|
| |
|
|