def test_in_comparator(self): """Ensure that render conditions can handle "IN" condition.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([ { 'field': 'foobar', 'type': 'STRING', 'comparators': [ {'condition': 'IN', 'negate': False, 'value': ['a', 'b']}, {'condition': 'IN', 'negate': False, 'value': {'c', 'd'}}, {'condition': 'IN', 'negate': False, 'value': ('e', 'f')}, {'condition': 'IN', 'negate': False, 'value': 'g'}, {'condition': 'IN', 'negate': True, 'value': ['h', 'i']}, {'condition': 'IN', 'negate': True, 'value': {'j', 'k'}}, {'condition': 'IN', 'negate': True, 'value': ('l', 'm')}, {'condition': 'IN', 'negate': True, 'value': 'n'}, ] } ]) six.assertCountEqual(self, result[len('WHERE '):].split(' AND '), "WHERE ((foobar IN (STRING('a'), STRING('b'))" " AND foobar IN (STRING('c'), STRING('d')) " "AND foobar IN (STRING('e'), STRING('f')) AND" " foobar IN (STRING('g'))) AND (NOT foobar IN" " (STRING('h'), STRING('i')) AND NOT foobar " "IN (STRING('j'), STRING('k')) AND NOT foobar" " IN (STRING('l'), STRING('m')) AND NOT " "foobar IN (STRING('n'))))" [len('WHERE '):] .split(' AND '))
def test_boolean_field_type(self): """Ensure that render conditions can handle a boolean field.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([ { 'field': 'foobar', 'type': 'BOOLEAN', 'comparators': [ {'condition': '==', 'negate': False, 'value': True}, {'condition': '!=', 'negate': False, 'value': False}, {'condition': '==', 'negate': False, 'value': 'a'}, {'condition': '!=', 'negate': False, 'value': ''}, {'condition': '==', 'negate': True, 'value': 100}, {'condition': '!=', 'negate': True, 'value': 0}, ] } ]) self.assertEqual(result, "WHERE ((foobar == BOOLEAN(1) AND " "foobar != BOOLEAN(0) AND foobar == " "BOOLEAN(1) AND foobar != BOOLEAN(0)) AND " "(NOT foobar == BOOLEAN(1) AND NOT " "foobar != BOOLEAN(0)))")
def test_multiple_comparators(self): """Ensure that render conditions can handle a multiple comparators.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([ { 'field': 'foobar', 'type': 'STRING', 'comparators': [ {'condition': '>=', 'negate': False, 'value': 'a'}, {'condition': '==', 'negate': False, 'value': 'b'}, {'condition': '<=', 'negate': False, 'value': 'c'}, {'condition': '>=', 'negate': True, 'value': 'd'}, {'condition': '==', 'negate': True, 'value': 'e'}, {'condition': '<=', 'negate': True, 'value': 'f'} ] } ]) self.assertEqual(result, "WHERE ((foobar >= STRING('a') AND " "foobar == STRING('b') AND foobar <= " "STRING('c')) AND (NOT foobar >= " "STRING('d') AND NOT foobar == STRING('e') " "AND NOT foobar <= STRING('f')))")
def test_multiple_conditions(self): """Ensure that render conditions can handle multiple conditions.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([ { 'field': 'a', 'type': 'STRING', 'comparators': [ {'condition': '>=', 'negate': False, 'value': 'foobar'} ] }, { 'field': 'b', 'type': 'INTEGER', 'comparators': [ {'condition': '==', 'negate': True, 'value': '1'} ] }, { 'field': 'c', 'type': 'STRING', 'comparators': [ {'condition': '!=', 'negate': False, 'value': 'Shark Week'} ] }, ]) self.assertEqual(result, "WHERE (a >= STRING('foobar')) AND " "(NOT b == INTEGER('1')) AND " "(c != STRING('Shark Week'))")
def test_between_comparator(self): """Ensure that render conditions can handle "BETWEEN" condition.""" result = _render_conditions([ { 'field': 'foobar', 'type': 'STRING', 'comparators': [ {'condition': 'BETWEEN', 'negate': False, 'value': ['a', 'b']}, {'condition': 'BETWEEN', 'negate': False, 'value': {'c', 'd'}}, {'condition': 'BETWEEN', 'negate': False, 'value': ('e', 'f')}, {'condition': 'BETWEEN', 'negate': True, 'value': ['h', 'i']}, {'condition': 'BETWEEN', 'negate': True, 'value': {'j', 'k'}}, {'condition': 'BETWEEN', 'negate': True, 'value': ('l', 'm')} ] } ]) six.assertCountEqual(self, result[len('WHERE '):].split(' AND '), "WHERE ((foobar BETWEEN STRING('a') AND " "STRING('b') AND foobar BETWEEN STRING('c') " "AND STRING('d') AND foobar BETWEEN " "STRING('e') AND STRING('f')) AND (NOT foobar " "BETWEEN STRING('h') AND STRING('i') AND NOT " "foobar BETWEEN STRING('j') AND STRING('k') " "AND NOT foobar BETWEEN STRING('l') AND " "STRING('m')))" [len('WHERE '):] .split(' AND '))
def test_single_condition(self): """Ensure that render conditions can handle a single condition.""" result = _render_conditions([ { 'field': 'bar', 'type': 'STRING', 'comparators': [ {'condition': '>=', 'negate': False, 'value': '1'} ] } ]) self.assertEqual(result, "WHERE (bar >= STRING('1'))")
def test_boolean_field_type(self): """Ensure that render conditions can handle a boolean field.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([{ 'field': 'foobar', 'type': 'BOOLEAN', 'comparators': [ { 'condition': '==', 'negate': False, 'value': True }, { 'condition': '!=', 'negate': False, 'value': False }, { 'condition': '==', 'negate': False, 'value': 'a' }, { 'condition': '!=', 'negate': False, 'value': '' }, { 'condition': '==', 'negate': True, 'value': 100 }, { 'condition': '!=', 'negate': True, 'value': 0 }, ] }]) self.assertEqual( result, "WHERE ((foobar == BOOLEAN(1) AND " "foobar != BOOLEAN(0) AND foobar == " "BOOLEAN(1) AND foobar != BOOLEAN(0)) AND " "(NOT foobar == BOOLEAN(1) AND NOT " "foobar != BOOLEAN(0)))")
def test_single_condition(self): """Ensure that render conditions can handle a single condition.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([{ 'field': 'bar', 'type': 'STRING', 'comparators': [{ 'condition': '>=', 'negate': False, 'value': '1' }] }]) self.assertEqual(result, "WHERE (bar >= STRING('1'))")
def test_multiple_comparators(self): """Ensure that render conditions can handle a multiple comparators.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([{ 'field': 'foobar', 'type': 'STRING', 'comparators': [{ 'condition': '>=', 'negate': False, 'value': 'a' }, { 'condition': '==', 'negate': False, 'value': 'b' }, { 'condition': '<=', 'negate': False, 'value': 'c' }, { 'condition': '>=', 'negate': True, 'value': 'd' }, { 'condition': '==', 'negate': True, 'value': 'e' }, { 'condition': '<=', 'negate': True, 'value': 'f' }] }]) self.assertEqual( result, "WHERE ((foobar >= STRING('a') AND " "foobar == STRING('b') AND foobar <= " "STRING('c')) AND (NOT foobar >= " "STRING('d') AND NOT foobar == STRING('e') " "AND NOT foobar <= STRING('f')))")
def test_multiple_conditions(self): """Ensure that render conditions can handle multiple conditions.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([ { 'field': 'a', 'type': 'STRING', 'comparators': [{ 'condition': '>=', 'negate': False, 'value': 'foobar' }] }, { 'field': 'b', 'type': 'INTEGER', 'comparators': [{ 'condition': '==', 'negate': True, 'value': '1' }] }, { 'field': 'c', 'type': 'STRING', 'comparators': [{ 'condition': '!=', 'negate': False, 'value': 'Shark Week' }] }, ]) self.assertEqual( result, "WHERE (a >= STRING('foobar')) AND " "(NOT b == INTEGER('1')) AND " "(c != STRING('Shark Week'))")
def test_in_comparator(self): """Ensure that render conditions can handle "IN" condition.""" from bigquery.query_builder \ import _render_conditions result = _render_conditions([{ 'field': 'foobar', 'type': 'STRING', 'comparators': [ { 'condition': 'IN', 'negate': False, 'value': ['a', 'b'] }, { 'condition': 'IN', 'negate': False, 'value': {'c', 'd'} }, { 'condition': 'IN', 'negate': False, 'value': ('e', 'f') }, { 'condition': 'IN', 'negate': False, 'value': 'g' }, { 'condition': 'IN', 'negate': True, 'value': ['h', 'i'] }, { 'condition': 'IN', 'negate': True, 'value': {'j', 'k'} }, { 'condition': 'IN', 'negate': True, 'value': ('l', 'm') }, { 'condition': 'IN', 'negate': True, 'value': 'n' }, ] }]) self.assertEqual( result, "WHERE ((foobar IN (STRING('a'), STRING('b'))" " AND foobar IN (STRING('c'), STRING('d')) " "AND foobar IN (STRING('e'), STRING('f')) AND" " foobar IN (STRING('g'))) AND (NOT foobar IN" " (STRING('h'), STRING('i')) AND NOT foobar " "IN (STRING('k'), STRING('j')) AND NOT foobar" " IN (STRING('l'), STRING('m')) AND NOT " "foobar IN (STRING('n'))))")