def test_get_filters_adhoc_filters(app_context: AppContext) -> None: with app.test_request_context( data={ "form_data": json.dumps( { "adhoc_filters": [ { "clause": "WHERE", "comparator": "foo", "expressionType": "SIMPLE", "operator": "in", "subject": "name", } ], } ) } ): cache = ExtraCache() assert cache.get_filters("name") == [ {"op": "IN", "col": "name", "val": ["foo"]} ] assert cache.removed_filters == [] assert cache.applied_filters == ["name"] with app.test_request_context( data={ "form_data": json.dumps( { "adhoc_filters": [ { "clause": "WHERE", "comparator": ["foo", "bar"], "expressionType": "SIMPLE", "operator": "in", "subject": "name", } ], } ) } ): cache = ExtraCache() assert cache.get_filters("name") == [ {"op": "IN", "col": "name", "val": ["foo", "bar"]} ] assert cache.removed_filters == [] with app.test_request_context( data={ "form_data": json.dumps( { "adhoc_filters": [ { "clause": "WHERE", "comparator": ["foo", "bar"], "expressionType": "SIMPLE", "operator": "in", "subject": "name", } ], } ) } ): cache = ExtraCache() assert cache.get_filters("name", remove_filter=True) == [ {"op": "IN", "col": "name", "val": ["foo", "bar"]} ] assert cache.removed_filters == ["name"] assert cache.applied_filters == ["name"]
def test_get_filters_adhoc_filters(self) -> None: with app.test_request_context( data={ "form_data": json.dumps({ "adhoc_filters": [{ "clause": "WHERE", "comparator": "foo", "expressionType": "SIMPLE", "operator": "in", "subject": "name", }], }) }): cache = ExtraCache() self.assertEqual(cache.get_filters("name"), [{ "op": "IN", "col": "name", "val": ["foo"] }]) self.assertEqual(cache.removed_filters, list()) self.assertEqual(cache.applied_filters, ["name"]) with app.test_request_context( data={ "form_data": json.dumps({ "adhoc_filters": [{ "clause": "WHERE", "comparator": ["foo", "bar"], "expressionType": "SIMPLE", "operator": "in", "subject": "name", }], }) }): cache = ExtraCache() self.assertEqual( cache.get_filters("name"), [{ "op": "IN", "col": "name", "val": ["foo", "bar"] }], ) self.assertEqual(cache.removed_filters, list()) with app.test_request_context( data={ "form_data": json.dumps({ "adhoc_filters": [{ "clause": "WHERE", "comparator": ["foo", "bar"], "expressionType": "SIMPLE", "operator": "in", "subject": "name", }], }) }): cache = ExtraCache() self.assertEqual( cache.get_filters("name", remove_filter=True), [{ "op": "IN", "col": "name", "val": ["foo", "bar"] }], ) self.assertEqual(cache.removed_filters, ["name"]) self.assertEqual(cache.applied_filters, ["name"])
def test_get_filters_remove_not_present(app_context: AppContext) -> None: cache = ExtraCache() assert cache.get_filters("name", remove_filter=True) == [] assert cache.removed_filters == []
def test_get_filters_remove_not_present(self) -> None: with app.test_request_context(): cache = ExtraCache() self.assertEqual(cache.get_filters("name", remove_filter=True), []) self.assertEqual(cache.removed_filters, list())