@@ -45,6 +45,64 @@ def test_ctor(self):
4545 self .assertIs (client ._connection .credentials , creds )
4646 self .assertIs (client ._connection .http , http )
4747
48+ def test_get_job_miss_w_explicit_project_and_timeout (self ):
49+ from google .cloud .exceptions import NotFound
50+
51+ project = 'PROJECT'
52+ creds = _make_credentials ()
53+ client = self ._make_one (project , creds )
54+ conn = client ._connection = _Connection ()
55+
56+ with self .assertRaises (NotFound ):
57+ client .get_query_results (
58+ 'nothere' , project = 'other-project' , timeout_ms = 500 )
59+
60+ self .assertEqual (len (conn ._requested ), 1 )
61+ req = conn ._requested [0 ]
62+ self .assertEqual (req ['method' ], 'GET' )
63+ self .assertEqual (
64+ req ['path' ], '/projects/other-project/queries/nothere' )
65+ self .assertEqual (
66+ req ['query_params' ], {'maxResults' : 0 , 'timeoutMs' : 500 })
67+
68+ def test_get_query_results_hit (self ):
69+ project = 'PROJECT'
70+ job_id = 'query_job'
71+ data = {
72+ 'kind' : 'bigquery#getQueryResultsResponse' ,
73+ 'etag' : 'some-tag' ,
74+ 'schema' : {
75+ 'fields' : [
76+ {
77+ 'name' : 'title' ,
78+ 'type' : 'STRING' ,
79+ 'mode' : 'NULLABLE'
80+ },
81+ {
82+ 'name' : 'unique_words' ,
83+ 'type' : 'INTEGER' ,
84+ 'mode' : 'NULLABLE'
85+ }
86+ ]
87+ },
88+ 'jobReference' : {
89+ 'projectId' : project ,
90+ 'jobId' : job_id ,
91+ },
92+ 'totalRows' : '10' ,
93+ 'totalBytesProcessed' : '2464625' ,
94+ 'jobComplete' : True ,
95+ 'cacheHit' : False ,
96+ }
97+
98+ creds = _make_credentials ()
99+ client = self ._make_one (project , creds )
100+ client ._connection = _Connection (data )
101+ query_results = client .get_query_results (job_id )
102+
103+ self .assertEqual (query_results .total_rows , 10 )
104+ self .assertTrue (query_results .complete )
105+
48106 def test_list_projects_defaults (self ):
49107 import six
50108 from google .cloud .bigquery .client import Project
@@ -607,6 +665,11 @@ def __init__(self, *responses):
607665 self ._requested = []
608666
609667 def api_request (self , ** kw ):
668+ from google .cloud .exceptions import NotFound
610669 self ._requested .append (kw )
670+
671+ if len (self ._responses ) == 0 :
672+ raise NotFound ('miss' )
673+
611674 response , self ._responses = self ._responses [0 ], self ._responses [1 :]
612675 return response
0 commit comments