2021-12-15 14:50:55 +00:00
|
|
|
"""
|
|
|
|
Some more test cases for summary tables, involving UNDO.
|
|
|
|
"""
|
2023-07-18 15:20:02 +00:00
|
|
|
import logging
|
2021-12-15 14:50:55 +00:00
|
|
|
import testutil
|
|
|
|
import test_engine
|
|
|
|
|
2023-07-18 15:20:02 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2021-12-15 14:50:55 +00:00
|
|
|
|
|
|
|
class TestSummaryUndo(test_engine.EngineTestCase):
|
|
|
|
sample = testutil.parse_test_sample({
|
|
|
|
"SCHEMA": [
|
|
|
|
[1, "Person", [
|
|
|
|
[1, "state", "Text", False],
|
|
|
|
]]
|
|
|
|
],
|
|
|
|
"DATA": {
|
|
|
|
"Person": [
|
|
|
|
["id", "state", ],
|
|
|
|
[ 1, "NY", ],
|
|
|
|
[ 2, "IL", ],
|
|
|
|
[ 3, "ME", ],
|
|
|
|
[ 4, "NY", ],
|
|
|
|
[ 5, "IL", ],
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
def test_summary_undo1(self):
|
|
|
|
# This tests a particular case of a bug when a summary table wasn't fully updated after UNDO.
|
|
|
|
self.load_sample(self.sample)
|
|
|
|
# Create a summary section, grouped by the "State" column.
|
2022-05-04 09:54:30 +00:00
|
|
|
self.apply_user_action(["CreateViewSection", 1, 0, "record", [1], None])
|
(core) Nice summary table IDs
Summary:
Changes auto-generated summary table IDs from e.g. `GristSummary_6_Table1` to `Table1_summary_A_B` (meaning `Table1` grouped by `A` and `B`). This makes it easier to write formulas involving summary tables, make API requests, understand logs, etc.
Because these don't encode the source table ID as reliably as before, `decode_summary_table_name` now uses the summary table schema info, not just the summary table ID. Specifically, it looks at the type of the `group` column, which is `RefList:<source table id>`.
Renaming a source table renames the summary table as before, and now renaming a groupby column renames the summary table as well.
Conflicting table names are resolved in the usual way by adding a number at the end, e.g. `Table1_summary_A_B2`. These summary tables are not automatically renamed when the disambiguation is no longer needed.
A new migration renames all summary tables to the new scheme, and updates formulas using summary tables with a simple regex.
Test Plan:
Updated many tests to use the new style of name.
Added new Python tests to for resolving conflicts when renaming source tables and groupby columns.
Added a test for the migration, including renames in formulas.
Reviewers: georgegevoian
Reviewed By: georgegevoian
Differential Revision: https://phab.getgrist.com/D3508
2022-07-11 18:00:25 +00:00
|
|
|
self.assertTableData('Person_summary_state', cols="subset", data=[
|
2021-12-15 14:50:55 +00:00
|
|
|
[ "id", "state", "count"],
|
|
|
|
[ 1, "NY", 2],
|
|
|
|
[ 2, "IL", 2],
|
|
|
|
[ 3, "ME", 1],
|
|
|
|
])
|
|
|
|
|
|
|
|
out_actions = self.update_record('Person', 4, state='ME')
|
(core) Nice summary table IDs
Summary:
Changes auto-generated summary table IDs from e.g. `GristSummary_6_Table1` to `Table1_summary_A_B` (meaning `Table1` grouped by `A` and `B`). This makes it easier to write formulas involving summary tables, make API requests, understand logs, etc.
Because these don't encode the source table ID as reliably as before, `decode_summary_table_name` now uses the summary table schema info, not just the summary table ID. Specifically, it looks at the type of the `group` column, which is `RefList:<source table id>`.
Renaming a source table renames the summary table as before, and now renaming a groupby column renames the summary table as well.
Conflicting table names are resolved in the usual way by adding a number at the end, e.g. `Table1_summary_A_B2`. These summary tables are not automatically renamed when the disambiguation is no longer needed.
A new migration renames all summary tables to the new scheme, and updates formulas using summary tables with a simple regex.
Test Plan:
Updated many tests to use the new style of name.
Added new Python tests to for resolving conflicts when renaming source tables and groupby columns.
Added a test for the migration, including renames in formulas.
Reviewers: georgegevoian
Reviewed By: georgegevoian
Differential Revision: https://phab.getgrist.com/D3508
2022-07-11 18:00:25 +00:00
|
|
|
self.assertTableData('Person_summary_state', cols="subset", data=[
|
2021-12-15 14:50:55 +00:00
|
|
|
[ "id", "state", "count"],
|
|
|
|
[ 1, "NY", 1],
|
|
|
|
[ 2, "IL", 2],
|
|
|
|
[ 3, "ME", 2],
|
|
|
|
])
|
|
|
|
|
|
|
|
self.apply_undo_actions(out_actions.undo[0:1])
|
(core) Nice summary table IDs
Summary:
Changes auto-generated summary table IDs from e.g. `GristSummary_6_Table1` to `Table1_summary_A_B` (meaning `Table1` grouped by `A` and `B`). This makes it easier to write formulas involving summary tables, make API requests, understand logs, etc.
Because these don't encode the source table ID as reliably as before, `decode_summary_table_name` now uses the summary table schema info, not just the summary table ID. Specifically, it looks at the type of the `group` column, which is `RefList:<source table id>`.
Renaming a source table renames the summary table as before, and now renaming a groupby column renames the summary table as well.
Conflicting table names are resolved in the usual way by adding a number at the end, e.g. `Table1_summary_A_B2`. These summary tables are not automatically renamed when the disambiguation is no longer needed.
A new migration renames all summary tables to the new scheme, and updates formulas using summary tables with a simple regex.
Test Plan:
Updated many tests to use the new style of name.
Added new Python tests to for resolving conflicts when renaming source tables and groupby columns.
Added a test for the migration, including renames in formulas.
Reviewers: georgegevoian
Reviewed By: georgegevoian
Differential Revision: https://phab.getgrist.com/D3508
2022-07-11 18:00:25 +00:00
|
|
|
self.assertTableData('Person_summary_state', cols="subset", data=[
|
2021-12-15 14:50:55 +00:00
|
|
|
[ "id", "state", "count"],
|
|
|
|
[ 1, "NY", 2],
|
|
|
|
[ 2, "IL", 2],
|
|
|
|
[ 3, "ME", 1],
|
|
|
|
])
|