|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Shared fixtures for firestore_client tests. |
| 4 | +
|
| 5 | +This module provides fixtures specific to the firestore_client test suite, |
| 6 | +building upon the global fixtures from the parent conftest.py. |
| 7 | +""" |
| 8 | + |
| 9 | +import pytest |
| 10 | +import os |
| 11 | +from datetime import datetime, timedelta |
| 12 | +from dotenv import load_dotenv |
| 13 | + |
| 14 | +# Load environment variables |
| 15 | +load_dotenv(os.path.join(os.path.dirname(__file__), '../../.env')) |
| 16 | + |
| 17 | +@pytest.fixture(scope="session") |
| 18 | +def firestore_client(): |
| 19 | + """ |
| 20 | + Shared SpendeeFirestore client for firestore_client tests. |
| 21 | + |
| 22 | + This fixture creates a single authenticated client that can be reused |
| 23 | + across all firestore_client test modules. |
| 24 | + """ |
| 25 | + from spendee import SpendeeFirestore |
| 26 | + |
| 27 | + email = os.getenv('EMAIL') |
| 28 | + password = os.getenv('PASSWORD') |
| 29 | + |
| 30 | + if not email or not password: |
| 31 | + pytest.fail("EMAIL and PASSWORD environment variables required") |
| 32 | + else: |
| 33 | + client = SpendeeFirestore(email, password) |
| 34 | + return client |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture(scope="session") |
| 38 | +def sample_wallet_id(firestore_client): |
| 39 | + """ |
| 40 | + Get a sample wallet ID for testing. |
| 41 | + |
| 42 | + Returns a specific wallet ID that's known to exist in the test environment. |
| 43 | + """ |
| 44 | + wallets = firestore_client.list_wallets() |
| 45 | + if not wallets: |
| 46 | + pytest.skip("No wallets available for testing") |
| 47 | + |
| 48 | + # Try to find a specific wallet ID, or use the first one |
| 49 | + target_wallet_id = 'b368c5c2-68fe-4f98-9d4f-08e0cdca57a7' |
| 50 | + for wallet in wallets: |
| 51 | + if wallet['id'] == target_wallet_id: |
| 52 | + return target_wallet_id |
| 53 | + pytest.fail(f"Target wallet ID {target_wallet_id} not found in available wallets") |
| 54 | + |
| 55 | + |
| 56 | +@pytest.fixture(scope="session") |
| 57 | +def sample_transaction_id(firestore_client, sample_wallet_id): |
| 58 | + """ |
| 59 | + Get a sample transaction ID for testing. |
| 60 | + |
| 61 | + Returns a transaction ID from the sample wallet. |
| 62 | + """ |
| 63 | + transactions = firestore_client.list_transactions( |
| 64 | + sample_wallet_id, |
| 65 | + fields=['id'], |
| 66 | + start=(datetime.now() - timedelta(days=60)).isoformat(), |
| 67 | + limit=1 |
| 68 | + ) |
| 69 | + |
| 70 | + if not transactions: |
| 71 | + pytest.skip("No transactions available for testing") |
| 72 | + |
| 73 | + return transactions[0]['id'] |
| 74 | + |
| 75 | +@pytest.fixture(scope="session") |
| 76 | +def editable_transaction_id_with_wallet(firestore_client): |
| 77 | + """ |
| 78 | + Get a wallet ID and transaction ID pair for testing edit operations. |
| 79 | + |
| 80 | + Returns a tuple of (wallet_id, transaction_id) that can be used for editing. |
| 81 | + """ |
| 82 | + # Specific known editable transaction |
| 83 | + transaction_id = 'd2b4caa7-12eb-4c04-a744-d2bf7e02bdd2' |
| 84 | + wallet_id = 'b368c5c2-68fe-4f98-9d4f-08e0cdca57a7' |
| 85 | + |
| 86 | + # Verify the transaction exists |
| 87 | + try: |
| 88 | + firestore_client.get_transaction(wallet_id, transaction_id) |
| 89 | + return wallet_id, transaction_id |
| 90 | + except Exception: |
| 91 | + pytest.skip("Editable transaction not available for testing") |
| 92 | + |
| 93 | +@pytest.fixture(scope="session") |
| 94 | +def test_categories(firestore_client): |
| 95 | + """ |
| 96 | + Get all categories for testing. |
| 97 | + |
| 98 | + Returns the list of all available categories. |
| 99 | + """ |
| 100 | + return firestore_client.list_categories() |
| 101 | + |
| 102 | +@pytest.fixture(scope="session") |
| 103 | +def test_labels(firestore_client): |
| 104 | + """ |
| 105 | + Get all labels for testing. |
| 106 | + |
| 107 | + Returns the list of all available labels. |
| 108 | + """ |
| 109 | + return firestore_client.list_labels() |
| 110 | + |
| 111 | +@pytest.fixture |
| 112 | +def sample_date_range(): |
| 113 | + """ |
| 114 | + Sample date range for testing. |
| 115 | + |
| 116 | + Returns a tuple of (start_date, end_date) in ISO format. |
| 117 | + """ |
| 118 | + end_date = datetime.now() |
| 119 | + start_date = end_date - timedelta(days=30) |
| 120 | + |
| 121 | + return start_date.isoformat(), end_date.isoformat() |
| 122 | + |
| 123 | +@pytest.fixture |
| 124 | +def invalid_uuid(): |
| 125 | + """ |
| 126 | + Invalid UUID for testing error cases. |
| 127 | + |
| 128 | + Returns a string that is not a valid UUID. |
| 129 | + """ |
| 130 | + return 'invalid-uuid' |
| 131 | + |
| 132 | +@pytest.fixture |
| 133 | +def invalid_date_format(): |
| 134 | + """ |
| 135 | + Invalid date format for testing error cases. |
| 136 | + |
| 137 | + Returns a string that is not a valid date format. |
| 138 | + """ |
| 139 | + return 'bad-date' |
0 commit comments