def test_filter_values_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.filter_values("name"), ["foo"]) 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.filter_values("name"), ["foo", "bar"]) self.assertEqual(cache.applied_filters, ["name"])
def test_url_param_unescaped_default_form_data(self) -> None: with app.test_request_context( query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})} ): cache = ExtraCache(dialect=dialect()) self.assertEqual( cache.url_param("bar", "O'Malley", escape_result=False), "O'Malley" )
def test_url_param_form_data(self) -> None: with app.test_request_context( query_string={ "form_data": json.dumps({"url_params": { "foo": "bar" }}) }): self.assertEquals(ExtraCache().url_param("foo"), "bar")
def test_url_param_unescaped_form_data() -> None: with app.test_request_context( query_string={ "form_data": json.dumps({"url_params": { "foo": "O'Brien" }}) }): cache = ExtraCache(dialect=dialect()) assert cache.url_param("foo", escape_result=False) == "O'Brien"
def test_url_param_escaped_default_form_data() -> None: with app.test_request_context( query_string={ "form_data": json.dumps({"url_params": { "foo": "O'Brien" }}) }): cache = ExtraCache(dialect=dialect()) assert cache.url_param("bar", "O'Malley") == "O''Malley"
def test_url_param_form_data() -> None: with app.test_request_context( query_string={ "form_data": json.dumps({"url_params": { "foo": "bar" }}) }): cache = ExtraCache() assert cache.url_param("foo") == "bar"
def test_url_param_escaped_form_data(self) -> None: with app.test_request_context( query_string={ "form_data": json.dumps({"url_params": { "foo": "O'Brien" }}) }): cache = ExtraCache(dialect=dialect()) self.assertEqual(cache.url_param("foo"), "O''Brien")
def test_filter_values_extra_filters(self) -> None: with app.test_request_context( data={ "form_data": json.dumps( {"extra_filters": [{"col": "name", "op": "in", "val": "foo"}]} ) } ): cache = ExtraCache() self.assertEqual(cache.filter_values("name"), ["foo"])
def test_filter_values_extra_filters(app_context: AppContext) -> None: with app.test_request_context( data={ "form_data": json.dumps( {"extra_filters": [{"col": "name", "op": "in", "val": "foo"}]} ) } ): cache = ExtraCache() assert cache.filter_values("name") == ["foo"] assert 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_filter_values_default(app_context: AppContext) -> None: cache = ExtraCache() assert cache.filter_values("name", "foo") == ["foo"] assert cache.removed_filters == []
def test_url_param_escaped_form_data(app_context: AppContext) -> None: with app.test_request_context( query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})} ): cache = ExtraCache(dialect=dialect()) assert cache.url_param("foo") == "O''Brien"
def test_url_param_query(app_context: AppContext) -> None: with app.test_request_context(query_string={"foo": "bar"}): cache = ExtraCache() assert cache.url_param("foo") == "bar"
def test_url_param_no_default(app_context: AppContext) -> None: with app.test_request_context(): cache = ExtraCache() assert cache.url_param("foo") is None
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_filter_values_no_default(self) -> None: with app.test_request_context(): cache = ExtraCache() self.assertEqual(cache.filter_values("name"), [])
def test_url_param_default() -> None: with app.test_request_context(): cache = ExtraCache() assert cache.url_param("foo", "bar") == "bar"
def test_filter_values_remove_not_present() -> None: cache = ExtraCache() assert cache.filter_values("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())
def test_filter_values_no_default(app_context: AppContext) -> None: cache = ExtraCache() assert cache.filter_values("name") == []
def test_url_param_query(self) -> None: with app.test_request_context(query_string={"foo": "bar"}): cache = ExtraCache() self.assertEqual(cache.url_param("foo"), "bar")
def test_url_param_no_default(self) -> None: with app.test_request_context(): cache = ExtraCache() self.assertEqual(cache.url_param("foo"), None)
def test_filter_values_no_default() -> None: cache = ExtraCache() assert cache.filter_values("name") == []
def test_url_param_default(self) -> None: with app.test_request_context(): self.assertEquals(ExtraCache().url_param("foo", "bar"), "bar")
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_filter_values_default(self) -> None: with app.test_request_context(): cache = ExtraCache() self.assertEqual(cache.filter_values("name", "foo"), ["foo"]) self.assertEqual(cache.removed_filters, list())