Skip to content

Commit 2578e54

Browse files
committed
Moves make_connection to helpers.py and adds unit test for no connection in context.
1 parent 46a6f43 commit 2578e54

File tree

4 files changed

+199
-131
lines changed

4 files changed

+199
-131
lines changed

bigquery/tests/unit/helpers.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def make_connection(*responses):
17+
import google.cloud.bigquery._http
18+
import mock
19+
from google.cloud.exceptions import NotFound
20+
21+
mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)
22+
mock_conn.user_agent = "testing 1.2.3"
23+
mock_conn.api_request.side_effect = list(responses) + [NotFound("miss")]
24+
return mock_conn

bigquery/tests/unit/test__helpers.py

-11
Original file line numberDiff line numberDiff line change
@@ -782,17 +782,6 @@ def _make_field(field_type, mode="NULLABLE", name="testing", fields=()):
782782
return SchemaField(name=name, field_type=field_type, mode=mode, fields=fields)
783783

784784

785-
def _make_connection(*responses):
786-
import google.cloud.bigquery._http
787-
import mock
788-
from google.cloud.exceptions import NotFound
789-
790-
mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)
791-
mock_conn.user_agent = "testing 1.2.3"
792-
mock_conn.api_request.side_effect = list(responses) + [NotFound("miss")]
793-
return mock_conn
794-
795-
796785
class Test_scalar_field_to_json(unittest.TestCase):
797786
def _call_fut(self, field, value):
798787
from google.cloud.bigquery._helpers import _scalar_field_to_json

0 commit comments

Comments
 (0)