Skip to content

Commit

Permalink
fix test_stats_get_tabular_data_invalid_sorting_options
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jun 27, 2024
1 parent 9067534 commit 3215ef9
Show file tree
Hide file tree
Showing 3 changed files with 529 additions and 512 deletions.
2 changes: 1 addition & 1 deletion bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ def to_df_analysis_format(
"Question (Local)": message.get_previous_by_created_at().display_content,
"Answer (Local)": message.display_content,
"Analysis JSON": message.analysis_result,
"Run URL": message.saved_run.get_app_url(),
"Run URL": (message.saved_run and message.saved_run.get_app_url()),
}
rows.append(row)
df = pd.DataFrame.from_records(
Expand Down
25 changes: 19 additions & 6 deletions bots/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from app_users.models import AppUser
from daras_ai_v2.functional import map_parallel
from recipes.VideoBotsStats import get_tabular_data
from .models import (
Message,
Conversation,
Expand Down Expand Up @@ -115,8 +116,12 @@ def test_stats_get_tabular_data_invalid_sorting_options(transactional_db):
msgs = Message.objects.filter(conversation__in=convos)

# valid option but no data
df = page.get_tabular_data(
bi, run_url, convos, msgs, "Answered Successfully", "Name"
df = get_tabular_data(
bi=bi,
conversations=convos,
messages=msgs,
details="Answered Successfully",
sort_by="Name",
)
assert df.shape[0] == 0
assert "Name" in df.columns
Expand All @@ -143,15 +148,23 @@ def test_stats_get_tabular_data_invalid_sorting_options(transactional_db):
convos = Conversation.objects.filter(bot_integration=bi)
msgs = Message.objects.filter(conversation__in=convos)
assert msgs.count() == 2
df = page.get_tabular_data(
bi, run_url, convos, msgs, "Answered Successfully", "Name"
df = get_tabular_data(
bi=bi,
conversations=convos,
messages=msgs,
details="Answered Successfully",
sort_by="Name",
)
assert df.shape[0] == 1
assert "Name" in df.columns

# invalid sort option should be ignored
df = page.get_tabular_data(
bi, run_url, convos, msgs, "Answered Successfully", "Invalid"
df = get_tabular_data(
bi=bi,
conversations=convos,
messages=msgs,
details="Answered Successfully",
sort_by="Invalid",
)
assert df.shape[0] == 1
assert "Name" in df.columns
Loading

0 comments on commit 3215ef9

Please sign in to comment.