def test_to_query_parameters_w_dict_array_param(self): parameters = {"somelist": [10, 20]} query_parameters = _helpers.to_query_parameters(parameters) self.assertEqual(len(query_parameters), 1) param = query_parameters[0] self.assertEqual(param.name, "somelist") self.assertEqual(param.array_type, "INT64") self.assertEqual(param.values, [10, 20])
def test_to_query_parameters_w_list_array_param(self): parameters = [[10, 20]] query_parameters = _helpers.to_query_parameters(parameters) self.assertEqual(len(query_parameters), 1) param = query_parameters[0] self.assertIsNone(param.name) self.assertEqual(param.array_type, "INT64") self.assertEqual(param.values, [10, 20])
def test_to_query_parameters_w_list(self): parameters = [True, u"a-string-value"] query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] for param in query_parameters: query_parameter_tuples.append((param.name, param.type_, param.value)) self.assertSequenceEqual( sorted(query_parameter_tuples), sorted([(None, "BOOL", True), (None, "STRING", u"a-string-value")]), )
def test_to_query_parameters_list_w_types(): from google.cloud import bigquery assert _helpers.to_query_parameters( [1, 1.2, None, []], [None, "numeric", "string", "float64"]) == [ bigquery.ScalarQueryParameter(None, "INT64", 1), bigquery.ScalarQueryParameter(None, "NUMERIC", 1.2), bigquery.ScalarQueryParameter(None, "STRING", None), bigquery.ArrayQueryParameter(None, "FLOAT64", []), ]
def test_to_query_parameters_w_dict(self): parameters = {"somebool": True, "somestring": u"a-string-value"} query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] for param in query_parameters: query_parameter_tuples.append( (param.name, param.type_, param.value)) self.assertSequenceEqual( sorted(query_parameter_tuples), sorted([ ("somebool", "BOOL", True), ("somestring", "STRING", u"a-string-value"), ]), )
def test_to_query_parameters_dict_w_types(): from google.cloud import bigquery assert sorted( _helpers.to_query_parameters( dict(i=1, x=1.2, y=None, z=[]), dict(x="numeric", y="string", z="float64")), key=lambda p: p.name, ) == [ bigquery.ScalarQueryParameter("i", "INT64", 1), bigquery.ScalarQueryParameter("x", "NUMERIC", 1.2), bigquery.ScalarQueryParameter("y", "STRING", None), bigquery.ArrayQueryParameter("z", "FLOAT64", []), ]
def test_to_query_parameters_w_dict(self): parameters = {"somebool": True, "somestring": u"a-string-value"} query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] for param in query_parameters: query_parameter_tuples.append((param.name, param.type_, param.value)) self.assertSequenceEqual( sorted(query_parameter_tuples), sorted( [ ("somebool", "BOOL", True), ("somestring", "STRING", u"a-string-value"), ] ), )
def test_to_query_parameters_w_dict(self): parameters = { 'somebool': True, 'somestring': u'a-string-value', } query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] for param in query_parameters: query_parameter_tuples.append( (param.name, param.type_, param.value)) self.assertSequenceEqual( sorted(query_parameter_tuples), sorted([ ('somebool', 'BOOL', True), ('somestring', 'STRING', u'a-string-value'), ]))
def test_to_query_parameters_none_argument(self): query_parameters = _helpers.to_query_parameters(None) self.assertEqual(query_parameters, [])
def test_to_query_parameters_w_list_dict_param(self): parameters = [{"foo": "bar"}] with self.assertRaises(NotImplementedError): _helpers.to_query_parameters(parameters)
def test_to_query_parameters_w_dict_dict_param(self): parameters = {"my_param": {"foo": "bar"}} with self.assertRaises(NotImplementedError): _helpers.to_query_parameters(parameters, {})