def test_data6_2(self, db_cur, queries_file): sql = Queries(queries_file) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} identifiers = {'order_group': 'country'} output = sql.CUSTOMERS_OR_STAFF_IN_COUNTRY_SORT_GROUP( db_cur, kwdata, n=1, identifiers=identifiers) assert output == ('BEN', 'EASTER', 'Russian Federation')
def test_data4(self, db_cur, queries_file, caplog): caplog.set_level(logging.DEBUG) sql = Queries(queries_file) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} output = sql.CUSTOMERS_OR_STAFF_IN_COUNTRY(db_cur, kwdata) assert len(output) == 37 assert "'countires': ['United States']" in caplog.text
def test_data6_1(self, db_cur, queries_file): with pytest.raises(SQLParseException): sql = Queries(queries_file) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} identifiers = 'country' sql.CUSTOMERS_OR_STAFF_IN_COUNTRY_SORT_GROUP( db_cur, kwdata, n=1, identifiers=identifiers)
def test_data2(self, db_cur, queries_file, caplog): caplog.set_level(logging.DEBUG) sql = Queries(queries_file) data = ('Jeff', 'Goldblum') sql.PRE_CLEAR_ACTOR(db_cur, data) output = sql.INSERT_ACTOR(db_cur, data, n=1) assert output == ('Jeff', 'Goldblum') assert "('Jeff', 'Goldblum')" in caplog.text
def test_data4_1(self, db_cur, queries_file): sql = Queries(queries_file) kwdata = { 'countires': ['United States'], 'extra_name': 'BEN', 'unmatched_arg_trigger': True } output = sql.CUSTOMERS_OR_STAFF_IN_COUNTRY(db_cur, kwdata) assert len(output) == 37
def test_data6(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} identifiers = ('country', ) sql.CUSTOMERS_OR_STAFF_IN_COUNTRY_SORT_EXP(db_cur, kwdata, n=1, identifiers=identifiers)
def test_data5_1(self, db_cur, queries_file): exc_msg = r'^Named argument supplied which does not match a SQL clause: .*' with pytest.raises(SQLArgumentException, match=exc_msg): sql = Queries(queries_file, strict_parse=True) kwdata = { 'countires': ['United States'], 'extra_name': 'BEN', 'extra_param': 'I should not be here' } sql.CUSTOMERS_OR_STAFF_IN_COUNTRY(db_cur, kwdata, n=1)
def query_stackoverflow(): client = bigquery.Client() # init bigquery client sql = Queries('queries.sql') # init SQLpy Query object with query file cur = Cursor(client) # init cursor object # execute the query against BigQuery # use the name defined in queries.sql # as the function name, passing cursour results, _ = sql.PYTHON_QUESTION_VIEWS(cur) for row in results: print("- {:<50} : {} [{} views]".format(row.title[:50], row.url, row.view_count))
def test_select_3(self, db_cur, queries_file_glob): sql = Queries(queries_file_glob) output = sql.TEST_SELECT_B(db_cur, n=1) assert output[0] == 1
def test_data3(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file) kwdata = {'country': 'MARS'} sql.INSERT_COUNTRY_EXP(db_cur, kwdata) sql.DELETE_COUNTRY_EXP(db_cur, kwdata)
def test_data5(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file, strict_parse=True) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} sql.CUSTOMERS_OR_STAFF_IN_COUNTRY_EXP(db_cur, kwdata, n=1)
def test_data1_1(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file) data = ('BEN', ) sql.GET_ACTORS_BY_FIRST_NAME_EXP(db_cur, data)
def test_data2(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file) data = ('Jeff', 'Goldblum', 'Jeff', 'Goldblum') sql.INSERT_ACTOR_EXP(db_cur, data)
def test_data8(self, db_cur, queries_file): with pytest.raises(psycopg2.Error): sql = Queries(queries_file) data = (1, 1) sql.INVENTORY_CHECK_EXP(db_cur, data)
def test_data2_1(self, db_cur, queries_file): sql = Queries(queries_file) data = ('Jeff', 'Goldblum') output = sql.INSERT_ACTOR(db_cur, data) assert output == [('Jeff', 'Goldblum')]
def test_logging(self, queries_file, caplog): caplog.set_level(logging.DEBUG) Queries(queries_file) for record in caplog.records: assert record.levelname == 'INFO' assert 'Found and loaded' in caplog.text
def test_select_4(self, db_cur, queries_file_glob): sql = Queries(queries_file_glob, uppercase_name=False) output = sql.test_select_b(db_cur, n=1) assert output[0] == 1
def test_data1(self, db_cur, queries_file): sql = Queries(queries_file) data = ('BEN', ) output = sql.GET_ACTORS_BY_FIRST_NAME(db_cur, data, n=1) assert output[0] == 83
def test_data10(self, db_cur, queries_file): with pytest.raises(SQLpyException): sql = Queries(queries_file) kwdata = (['United States'], 'BEN') output = sql.CUSTOMERS_OR_STAFF_IN_COUNTRY(db_cur, kwdata) assert len(output) == 37
def test_data1_1(self, db_cur, queries_file): sql = Queries(queries_file) data = ('BEN', ) output = sql.GET_ACTORS_BY_FIRST_NAME(db_cur, data) assert len(output) == 2
def test_data3(self, db_cur, queries_file): sql = Queries(queries_file) kwdata = {'country': 'MARS'} output1 = sql.INSERT_COUNTRY(db_cur, kwdata) output2 = sql.DELETE_COUNTRY(db_cur, kwdata) assert output1 and output2
def test_data2_4(self, db_cur, queries_file): sql = Queries(queries_file) data = (('Jeff', 'Goldblum'), ('Jeff', 'Goldblum')) sql.DELETE_ACTORS(db_cur, data[0]) output = sql.INSERT_ACTORS(db_cur, data, many=True, n=2) assert output == [('Jeff', 'Goldblum'), ('Jeff', 'Goldblum')]
def test_select_2(self, db_cur, queries_file): sql = Queries(queries_file) output = sql.TEST_SELECT(db_cur, n=1) assert output[0] == 1
def test_proc1_1(self, db_cur, queries_file): sql = Queries(queries_file) output = sql.INVENTORY_CHECK(db_cur, (1, 1), n=1) assert output == (1, ) or (4, )
def test_data7_2(self, db_cur, queries_file): with pytest.raises(SQLpyException): sql = Queries(queries_file) data = ('BEN', ) sql.GET_ACTORS_BY_FIRST_NAME(db_cur, data, n=-1)
def test_proc1_2(self, db_cur, queries_file): sql = Queries(queries_file) output = sql.INVENTORY_CHECK(db_cur, (1, 1), n=4) assert output == [(1, ), (2, ), (3, ), (4, )] or [(4, ), (3, ), (2, ), (1, )]
def test_data9(self, db_cur, queries_file): with pytest.raises(SQLpyException): sql = Queries(queries_file) data = (('Jeff', 'Goldblum'), ('Jeff', 'Goldblum')) output = sql.INSERT_ACTORS(db_cur, data, many=True, n='2') assert output == [('Jeff', 'Goldblum'), ('Jeff', 'Goldblum')]
def test_data1_3(self, db_cur, queries_file, caplog): caplog.set_level(logging.DEBUG) sql = Queries(queries_file) data = ('BEN', ) sql.GET_ACTORS_BY_FIRST_NAME(db_cur, data, n=1) assert "INFO Arguments: ('BEN',)" in caplog.text
def test_data5_2(self, db_cur, queries_file): sql = Queries(queries_file) kwdata = {'countires': ['United States'], 'extra_name': 'BEN'} output = sql.CUSTOMERS_OR_STAFF_IN_COUNTRY(db_cur, kwdata, n=3) assert len(output) == 3
def test_query_fcn_args(self, queries_file): sql = Queries(queries_file) assert len(sql.TEST_SELECT.args) == 1