@@ -35,7 +35,7 @@ def test_read_gbq_missing_parts(missing_parts_table_id):
3535 "not_found_table_id" ,
3636 [("unknown.dataset.table" ), ("project.unknown.table" ), ("project.dataset.unknown" )],
3737)
38- def test_read_gdb_not_found_tables (not_found_table_id ):
38+ def test_read_gbq_not_found_tables (not_found_table_id ):
3939 bqclient = mock .create_autospec (google .cloud .bigquery .Client , instance = True )
4040 bqclient .project = "test-project"
4141 bqclient .get_table .side_effect = google .api_core .exceptions .NotFound (
@@ -47,6 +47,34 @@ def test_read_gdb_not_found_tables(not_found_table_id):
4747 session .read_gbq (not_found_table_id )
4848
4949
50+ @pytest .mark .parametrize (
51+ ("api_name" , "query_or_table" ),
52+ [
53+ ("read_gbq" , "project.dataset.table" ),
54+ ("read_gbq_table" , "project.dataset.table" ),
55+ ("read_gbq" , "SELECT * FROM project.dataset.table" ),
56+ ("read_gbq_query" , "SELECT * FROM project.dataset.table" ),
57+ ],
58+ ids = [
59+ "read_gbq_on_table" ,
60+ "read_gbq_table" ,
61+ "read_gbq_on_query" ,
62+ "read_gbq_query" ,
63+ ],
64+ )
65+ def test_read_gbq_external_table_no_drive_access (api_name , query_or_table ):
66+ bqclient = mock .create_autospec (google .cloud .bigquery .Client , instance = True )
67+ bqclient .project = "test-project"
68+ bqclient .get_table .side_effect = google .api_core .exceptions .Forbidden (
69+ "Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials."
70+ )
71+ session = resources .create_bigquery_session (bqclient = bqclient )
72+
73+ api = getattr (session , api_name )
74+ with pytest .raises (google .api_core .exceptions .Forbidden ):
75+ api (query_or_table )
76+
77+
5078@mock .patch .dict (os .environ , {}, clear = True )
5179def test_session_init_fails_with_no_project ():
5280 with pytest .raises (
0 commit comments