Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grouping counts #353

Merged
merged 7 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mathesar/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def paginate_queryset(self, queryset, request, table_id,
filters=filters, order_by=order_by
)
# Convert the tuple keys into strings so it can be converted to JSON
group_count = {','.join(k): v for k, v in group_count.items()}
group_count = [{"columns": list(cols), "count": count}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eito-fis On second thought, I think changing this key to values instead of columns makes more sense, these aren't column names.

for cols, count in group_count.items()]
self.group_count = {
'group_count_by': group_count_by,
'results': group_count,
Expand Down
13 changes: 8 additions & 5 deletions mathesar/tests/views/api/test_record_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ def _test_record_list_group(table, client, group_count_by, expected_groups):
assert 'group_count' in response_data
assert response_data['group_count']['group_count_by'] == group_count_by
assert 'results' in response_data['group_count']
assert 'columns' in response_data['group_count']['results'][0]
assert 'count' in response_data['group_count']['results'][0]

results = response_data['group_count']['results']
returned_groups = {tuple(group["columns"]) for group in results}
for expected_group in expected_groups:
assert expected_group in results
assert expected_group in returned_groups

assert mock_infer.call_args is not None
assert mock_infer.call_args[0][2] == group_count_by
Expand All @@ -151,8 +154,8 @@ def test_record_list_group_single_column(create_table, client):
table = create_table(table_name)
group_count_by = ['Center']
expected_groups = [
'NASA Marshall Space Flight Center',
'NASA Stennis Space Center'
('NASA Marshall Space Flight Center',),
('NASA Stennis Space Center',)
]
_test_record_list_group(table, client, group_count_by, expected_groups)

Expand All @@ -162,8 +165,8 @@ def test_record_list_group_multi_column(create_table, client):
table = create_table(table_name)
group_count_by = ['Center', 'Status']
expected_groups = [
'NASA Marshall Space Flight Center,Issued',
'NASA Stennis Space Center,Issued',
('NASA Marshall Space Flight Center', 'Issued'),
('NASA Stennis Space Center', 'Issued'),
]
_test_record_list_group(table, client, group_count_by, expected_groups)

Expand Down