Skip to content

Commit 254bb5c

Browse files
committed
Merge branch 'main' of github.com:codeforpdx/tenantfirstaid into feat/chat-refactor
2 parents b22b2c1 + 9268462 commit 254bb5c

File tree

8 files changed

+259
-209
lines changed

8 files changed

+259
-209
lines changed

.github/workflows/pr-check.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ name: PR Checks
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened, closed]
5+
types: [opened, synchronize, reopened]
6+
7+
push:
8+
branches:
9+
- main
10+
- 'releases/*'
611

712
jobs:
813
backend-test:
9-
# skip this check for closed PRs that are not merged
10-
if: ${{ github.event.action != 'closed' || github.event.pull_request.merged == true }}
1114
runs-on: ubuntu-latest
1215
defaults:
1316
run:
@@ -22,7 +25,7 @@ jobs:
2225
enable-cache: true
2326
cache-dependency-glob: "backend/uv.lock"
2427
# Install a specific version of uv.
25-
version: "0.7.12"
28+
version: "0.7.13"
2629

2730
- name: Set up Python
2831
run: uv python install
@@ -46,8 +49,6 @@ jobs:
4649
run: uv run pytest -v -s
4750

4851
frontend-build:
49-
# skip this check for closed PRs that are not merged
50-
if: ${{ github.event.action != 'closed' || github.event.pull_request.merged == true }}
5152
runs-on: ubuntu-latest
5253
defaults:
5354
run:

backend/pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ dependencies = [
66
"flask",
77
"valkey",
88
"gunicorn",
9-
"openai",
9+
"openai==1.89",
1010
"jsonlines",
1111
"simplejson",
12-
"ipdb>=0.13.13",
1312
"python-dotenv",
1413
"pandas>=2.3.0",
1514
]
@@ -24,11 +23,12 @@ build-backend = "setuptools.build_meta"
2423

2524
[dependency-groups]
2625
dev = [
27-
"pytest>=8.3.5",
26+
"ipdb>=0.13.13",
27+
"pytest>=8.4.0",
2828
"pytest-cov>=6.1.1",
2929
"pytest-mock>=3.14.1",
30-
"ruff>=0.11.13",
31-
"ty>=0.0.1a8",
30+
"ruff>=0.12.0",
31+
"ty>=0.0.1a11",
3232
"types-Flask>=1.1.6",
3333
]
3434

backend/tests/test_session.py

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ def mock_valkey_ping_nop(mocker):
1515

1616
@pytest.fixture
1717
def mock_valkey(mock_valkey_ping_nop, mocker):
18-
# mock_valkey_dbcon_client = mocker.Mock()
19-
# mocker.patch("tenantfirstaid.session.Valkey", mock_valkey_dbcon_client)
20-
21-
_data: Dict[str, Any] = {}
18+
_data: Dict[str, str] = {}
2219

2320
mock_valkey_ping_nop.set = mocker.Mock(
2421
side_effect=lambda key, value: _data.update({key: value})
2522
)
2623

27-
mock_valkey_ping_nop.get = mocker.Mock(
28-
return_value=lambda key: _data.get(key, None)
29-
)
24+
mock_valkey_ping_nop.get = mocker.Mock(side_effect=lambda key: _data[key])
3025

3126
return mock_valkey_ping_nop
3227

@@ -81,10 +76,7 @@ def test_session_init_ping_exception(mocker, capsys):
8176

8277

8378
def test_session_get_unknown_session_id(mocker, mock_environ):
84-
test_data = {
85-
"city": "Test City",
86-
"state": "Test State",
87-
}
79+
test_data = {"city": "Test City", "state": "Test State", "messages": []}
8880

8981
mock_valkey_client = mocker.Mock()
9082
mocker.patch("tenantfirstaid.session.Valkey", return_value=mock_valkey_client)
@@ -111,30 +103,62 @@ def test_session_get_unknown_session_id(mocker, mock_environ):
111103
}
112104

113105

114-
# def test_session_set_and_get(mocker, mock_environ, mock_valkey):
115-
# test_data: Dict[str, Any] = {
116-
# "city": "Test City",
117-
# "state": "Test State",
118-
# "messages": ["this is message 1", "this is message 2"],
119-
# }
120-
121-
# mock_valkey_client = mocker.Mock()
122-
# mocker.patch("tenantfirstaid.session.Valkey", return_value=mock_valkey_client)
123-
# mock_valkey_client.ping = mocker.Mock()
124-
125-
# tenant_session = TenantSession()
126-
# app = Flask(__name__)
127-
# app.add_url_rule(
128-
# "/api/init",
129-
# view_func=InitSessionView.as_view("init", tenant_session),
130-
# methods=["POST"],
131-
# )
132-
# app.secret_key = "test_secret_key" # Set a secret key for session management
133-
134-
# with app.test_request_context("/api/init", method="POST", json=test_data):
135-
# response = app.full_dispatch_request()
136-
# assert response.status_code == 200 # Ensure the response is successful
137-
# session_id = response.json["session_id"]
138-
139-
# tenant_session.set(session_id, test_data)
140-
# assert tenant_session.get() == test_data
106+
def test_session_set_and_get(mocker, mock_environ, mock_valkey):
107+
test_data_obj: Dict[str, Any] = {
108+
"city": "Test City",
109+
"state": "Test State",
110+
"messages": ["this is message 1", "this is message 2"],
111+
}
112+
113+
tenant_session = TenantSession()
114+
app = Flask(__name__)
115+
app.add_url_rule(
116+
"/api/init",
117+
view_func=InitSessionView.as_view("init", tenant_session),
118+
methods=["POST"],
119+
)
120+
app.secret_key = "test_secret_key" # Set a secret key for session management
121+
122+
with app.test_request_context("/api/init", method="POST", json=test_data_obj):
123+
response = app.full_dispatch_request()
124+
assert response.status_code == 200 # Ensure the response is successful
125+
session_id = response.json["session_id"]
126+
assert session_id is not None # Ensure session_id is set
127+
assert isinstance(session_id, str) # Ensure session_id is a string
128+
129+
tenant_session.set(session_id, test_data_obj)
130+
assert tenant_session.get() == test_data_obj
131+
132+
133+
def test_session_set_some_and_get_none(mocker, mock_environ, mock_valkey):
134+
test_data_obj: Dict[str, Any] = {
135+
"city": "Test City",
136+
"state": "Test State",
137+
"messages": ["this is message 1", "this is message 2"],
138+
}
139+
140+
tenant_session = TenantSession()
141+
app = Flask(__name__)
142+
app.add_url_rule(
143+
"/api/init",
144+
view_func=InitSessionView.as_view("init", tenant_session),
145+
methods=["POST"],
146+
)
147+
app.secret_key = "test_secret_key" # Set a secret key for session management
148+
149+
# Simulate no data for the session (i.e. network error or similar)
150+
mock_valkey.get.side_effect = lambda key: None
151+
152+
with app.test_request_context("/api/init", method="POST", json=test_data_obj):
153+
response = app.full_dispatch_request()
154+
assert response.status_code == 200 # Ensure the response is successful
155+
session_id = response.json["session_id"]
156+
assert session_id is not None # Ensure session_id is set
157+
assert isinstance(session_id, str) # Ensure session_id is a string
158+
159+
tenant_session.set(session_id, test_data_obj)
160+
assert tenant_session.get() == {
161+
"city": "",
162+
"state": "",
163+
"messages": [],
164+
}

0 commit comments

Comments
 (0)