Skip to content

Commit bde3bec

Browse files
fix(tests): Adapt tests to new test account
- Updated wallet IDs, transaction dates, and expected values in the test suite to match the new test account. - Fixed an authentication issue by updating the JWT field name from `user_id` to `user_uuid`. - Corrected an async test by adding a missing `await`. - Improved the test runner script to activate the Python virtual environment. - Removed a debug logging statement from the production code.
1 parent a2acb1b commit bde3bec

9 files changed

Lines changed: 42 additions & 37 deletions

File tree

agents.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This document provides AI coding assistants with essential context for working with the spendee-python-client project.
55

66
## Development Environment Setup
7-
This project uses [mise](https://mise.jdx.dev/) to manage the development environment and leverages python virtual environment by relying on the [requirements.txt](requirements.txt) file. For details how the environment set up works, look into the [setup.sh](setup.sh) file.
7+
This project uses [mise](https://mise.jdx.dev/) to manage the development environment and leverages python virtual environment by relying on the [requirements.txt](requirements.txt) file. For details how the environment set up works, look into the [setup.sh](setup.sh) file. Even after the setup with mise, you need to activate the python virtual environment as well.
88

99
## Secrets Management
1010
We use Bitwarden for managing secrets. To access secrets, you will need the `BWS_ACCESS_TOKEN` environment variable set. You can then use the `bws` CLI to fetch secrets.
@@ -42,3 +42,16 @@ Each agent file starts with a "Read the overview" links block to the relevant `d
4242
Each relevant `docs/**` page gets a small footer: "For implementation details, see `<path>/agents.md`".
4343

4444
Reduce code/text duplication as much as possible across twin docs and agents files.
45+
46+
## Guidance on development
47+
48+
### spendee_api.py is deprecated
49+
50+
It is left there if anytime a function would be needed from it, but all development happens on the firebase implementation, just as the core spendee developers did.
51+
52+
### Do not modify login flow or authentication
53+
54+
The authentication in the firebase_client.py is not intuitive, you may used to have more seamless firebase authentication, but THIS WORKS, DO NOT MODIFY. I was not able to make it work using the google.oauth2.credentials, do not try re-implementing that. Maybe because web page flow was only enabled by original authors and service owners, and python SDK based auth flow differs. Maybe because that library is intended for admin API access, not user-client access, I am not an expert in this, but did considerable trial-and-error on that front.
55+
56+
57+
If you face authorization problems, troubleshoot what identities and wallets are used, or you may experiment with new firebase centric functions, but the authentication steps in the login flow should be only modified if user approved or explicitly asked.

run_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ if [ ! -f .env ]; then
1010
exit 1
1111
fi
1212

13+
# Activate the python virtual environment
14+
source .venv/bin/activate
15+
1316
# Run pytest with appropriate options
1417
python -m pytest tests/ -v --tb=short
1518

setup.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,16 @@ else
3030
SHELL_TYPE="sh"
3131
fi
3232

33-
# Debug
3433
if [[ $- == *i* ]]; then
3534
#Shell is interactive
3635
eval "$(~/.local/bin/mise activate "$SHELL_TYPE")"
3736
else
3837
echo "Shell is not interactive, mise env setup may not fully function, see https://mise.jdx.dev/dev-tools/shims.html#shims-vs-path"
3938
eval "$(~/.local/bin/mise activate --shims)"
4039
fi
41-
# Fallback preparation
42-
#mise_installs="${HOME}/.local/share/mise/installs"
43-
#export PATH="${HOME}/.local/bin:${mise_installs}/python/latest/bin:${mise_installs}/jq/latest:${mise_installs}/bitwarden-secrets-manager/latest:${PATH}"
4440

4541
mise install
4642

47-
which bws
48-
4943

5044
# --- Bitwarden credential setup ---
5145
if [ ! -f ".env" ]; then
@@ -76,4 +70,6 @@ echo "Activate the python virtual environment"
7670
source .venv/bin/activate
7771

7872
echo "Install dependencies"
79-
pip install -r requirements.txt
73+
pip install -r requirements.txt
74+
75+
echo "Setup completed!"

spendee/spendee_firestore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def __init__(self, email: str, password: str, base_url: str = 'https://api.spend
7777
self.credentials = CustomFirebaseCredentials(self)
7878
self.client = firestore.Client(project="spendee-app", credentials=self.credentials)
7979
access_token_data = self._jwt_instance.decode(self.access_token, do_verify=False)
80-
self.user_id = access_token_data.get('user_id', None)
80+
self.user_id = access_token_data.get('user_uuid', None)
8181
self.email = access_token_data.get('email', None)
8282
self.user_name = access_token_data.get('name', None)
83-
83+
8484
# Initialize mappings
8585
self.wallet_name_map = { x['name']: x['id'] for x in self.list_wallets()}
8686
categories = self.list_categories()

tests/firestore_client/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def sample_wallet_id(firestore_client):
4646
pytest.skip("No wallets available for testing")
4747

4848
# Try to find a specific wallet ID, or use the first one
49-
target_wallet_id = 'b368c5c2-68fe-4f98-9d4f-08e0cdca57a7'
49+
target_wallet_id = '5668018f-2c8d-41b0-9ef9-fbaa6518891d'
5050
for wallet in wallets:
5151
if wallet['id'] == target_wallet_id:
5252
return target_wallet_id
@@ -80,8 +80,8 @@ def editable_transaction_id_with_wallet(firestore_client):
8080
Returns a tuple of (wallet_id, transaction_id) that can be used for editing.
8181
"""
8282
# Specific known editable transaction
83-
transaction_id = 'd2b4caa7-12eb-4c04-a744-d2bf7e02bdd2'
84-
wallet_id = 'b368c5c2-68fe-4f98-9d4f-08e0cdca57a7'
83+
transaction_id = 'fa08917b-9181-48df-a183-23635730bbbe'
84+
wallet_id = '5668018f-2c8d-41b0-9ef9-fbaa6518891d'
8585

8686
# Verify the transaction exists
8787
try:

tests/firestore_client/test_aggregation.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,32 @@
22

33

44
def test_aggregate_transactions_category_filter_runs(firestore_client, sample_wallet_id):
5-
"""Aggregate by category (matches the `run.py` example for "Étkezés").
5+
"""Aggregate by category.
66
77
Verifies the call completes and returns a float value.
88
"""
99
total = firestore_client.aggregate_transactions(
1010
wallet_id=sample_wallet_id,
11-
start='2025-08-01T00:00:00Z',
12-
end='2025-08-31T23:59:59Z',
13-
#filters=[{"field": "category", "op": "=", "value": "Étkezés"}],
14-
#filters=[TransactionFilter(field="category", op="=", value="Étkezés")],
15-
filters={"category__eq": "Étkezés"},
11+
start='2025-11-17T00:00:00Z',
12+
end='2025-11-17T23:59:59Z',
13+
filters={"category__eq": "Groceries"},
1614
)
1715

1816
assert isinstance(total, float)
19-
assert total > -180000
20-
assert total < -3000
17+
assert total == -4.0
2118

2219

2320
def test_aggregate_transactions_label_filter_runs(firestore_client, sample_wallet_id):
24-
"""Aggregate by label (matches the `run.py` example for label `szigetspicc`).
21+
"""Aggregate by label.
2522
2623
Verifies the call completes and returns a float value.
2724
"""
2825
total = firestore_client.aggregate_transactions(
2926
wallet_id=sample_wallet_id,
30-
start='2025-08-01T00:00:00Z',
31-
end='2025-08-31T23:59:59Z',
32-
#filters=[{"field": "labels", "op": "array-contains", "value": "szigetspicc"}],
33-
#filters=[TransactionFilter(field="labels", op="array-contains", value="szigetspicc")],
34-
filters={"labels__contains": "szigetspicc"},
27+
start='2025-11-17T00:00:00Z',
28+
end='2025-11-17T23:59:59Z',
29+
filters={"labels__contains": "Coffee ☕"},
3530
)
3631

3732
assert isinstance(total, float)
38-
assert total > -80000
39-
assert total < -5000
33+
assert total == -4.0

tests/firestore_client/test_wallets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def test_get_wallet_balance_invalid_date_format_raises(firestore_client, sample_
1818

1919

2020
def test_get_wallet_balance_runs_with_dates(firestore_client, sample_wallet_id):
21-
assert 10000 < firestore_client.get_wallet_balance(sample_wallet_id, date="2025-08-26T23:59:59Z")
21+
assert firestore_client.get_wallet_balance(sample_wallet_id, date="2025-11-17T23:59:59Z") == 88.0

tests/spendee_mcp/test_mcp_filters.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ async def test_mcp_transaction_list(spendee_mcp_server):
66
async with Client(spendee_mcp_server) as client:
77
result = await client.call_tool("aggregate_transactions", \
88
{
9-
"wallet_id": "b368c5c2-68fe-4f98-9d4f-08e0cdca57a7", \
10-
"start": "2025-08-01T00:00:00Z", \
11-
"end": '2025-08-31T23:59:59Z', \
12-
"filters": {"labels__contains": "szigetspicc"}, \
9+
"wallet_id": "5668018f-2c8d-41b0-9ef9-fbaa6518891d", \
10+
"start": "2025-11-17T00:00:00Z", \
11+
"end": '2025-11-17T23:59:59Z', \
12+
"filters": {"labels__contains": "Coffee ☕"}, \
1313
}
1414
)
1515

1616
assert not result.is_error
1717
total = result.data
1818
assert isinstance(total, float)
19-
assert total > -80000
20-
assert total < -5000
19+
assert total == -4.0

tests/spendee_mcp/test_mcp_tool_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ async def test_mcp_tool_list(spendee_mcp_server):
77
Test that the MCP server has the expected tools registered.
88
"""
99
async with Client(spendee_mcp_server) as client:
10-
assert len(client.list_tools()) > 0
10+
assert len(await client.list_tools()) > 0

0 commit comments

Comments
 (0)