def test_get_query_spec_wrong_keys_list(self): def query_args_func(self): return "" self.assertEqual({}, get_query_spec(query_args_func, [])) self.assertEqual({}, get_query_spec(query_args_func, ())) self.assertEqual({}, get_query_spec(query_args_func, ""))
def test_get_query_spec_with_tuple(self, mock_types): valid_keys = ["a", "b", "d"] mock_types.get = mock.Mock() mock_types.get.side_effect = [None, "int", "int"] def query_args_func(key): args = {"a": ["a"], "b": ["0", "1", "2"], "d": ["1"]} return args.get(key, []) expected = {"a": "a", "b": {"$in": [0, 1, 2]}, "d": 1} self.assertDictEqual(expected, get_query_spec(query_args_func, valid_keys))
def test_get_query_spec(self): valid_keys = ["a", "b", "c", "d"] def query_args_func(key): args = { "a": [0, 1, 2], "b": [None, 3, None], "c": [None, None, ""], "d": [False] } return args.get(key, []) expected = {"a": {"$in": [0, 1, 2]}, "b": 3, "d": False} self.assertDictEqual(expected, get_query_spec(query_args_func, valid_keys))
def test_get_query_spec_with_tuple_invalid(self, mock_types): valid_keys = ["a", "b", "c", "d"] mock_types.get = mock.Mock() mock_types.get.side_effect = [None, "int", "int", "int"] def query_args_func(key): args = { "a": ["a"], "b": ["a", "1", "c"], "d": ["1", "2", "3", "bar"], "c": ["foo"] } return args.get(key, []) expected = {"a": "a"} self.assertDictEqual(expected, get_query_spec(query_args_func, valid_keys))