Skip to content

Commit 9df9890

Browse files
Jon Wayne Parrottdpebot
Jon Wayne Parrott
authored andcommitted
* Remove cloud config fixture * Fix client secrets * Fix bigtable instance
1 parent e3e62a6 commit 9df9890

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

samples/samples/quickstart_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
from google.cloud import spanner
1618
import google.cloud.exceptions
1719
import google.cloud.spanner.client
@@ -20,13 +22,15 @@
2022

2123
import quickstart
2224

25+
SPANNER_INSTANCE = os.environ['SPANNER_INSTANCE']
26+
2327

2428
@pytest.fixture
25-
def patch_instance(cloud_config):
29+
def patch_instance():
2630
original_instance = google.cloud.spanner.client.Client.instance
2731

2832
def new_instance(self, unused_instance_name):
29-
return original_instance(self, cloud_config.spanner_instance)
33+
return original_instance(self, SPANNER_INSTANCE)
3034

3135
instance_patch = mock.patch(
3236
'google.cloud.spanner.client.Client.instance',
@@ -38,9 +42,9 @@ def new_instance(self, unused_instance_name):
3842

3943

4044
@pytest.fixture
41-
def example_database(cloud_config):
45+
def example_database():
4246
spanner_client = spanner.Client()
43-
instance = spanner_client.instance(cloud_config.spanner_instance)
47+
instance = spanner_client.instance(SPANNER_INSTANCE)
4448
database = instance.database('my-database-id')
4549

4650
if not database.exists():

samples/samples/snippets_test.py

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import random
1617
import string
1718

@@ -21,144 +22,135 @@
2122

2223
import snippets
2324

25+
SPANNER_INSTANCE = os.environ['SPANNER_INSTANCE']
26+
2427

2528
@pytest.fixture(scope='module')
26-
def spanner_instance(cloud_config):
29+
def spanner_instance():
2730
spanner_client = spanner.Client()
28-
return spanner_client.instance(cloud_config.spanner_instance)
31+
return spanner_client.instance(SPANNER_INSTANCE)
2932

3033

3134
def unique_database_id():
3235
return 'test-db-{}'.format(''.join(random.choice(
3336
string.ascii_lowercase + string.digits) for _ in range(5)))
3437

3538

36-
def test_create_database(cloud_config, spanner_instance):
39+
def test_create_database(spanner_instance):
3740
database_id = unique_database_id()
38-
print(cloud_config.spanner_instance, database_id)
39-
snippets.create_database(
40-
cloud_config.spanner_instance, database_id)
41+
print(SPANNER_INSTANCE, database_id)
42+
snippets.create_database(SPANNER_INSTANCE, database_id)
4143

4244
database = spanner_instance.database(database_id)
4345
database.reload() # Will only succeed if the database exists.
4446
database.drop()
4547

4648

4749
@pytest.fixture(scope='module')
48-
def temporary_database(cloud_config, spanner_instance):
50+
def temporary_database(spanner_instance):
4951
database_id = unique_database_id()
50-
snippets.create_database(cloud_config.spanner_instance, database_id)
51-
snippets.insert_data(
52-
cloud_config.spanner_instance, database_id)
52+
snippets.create_database(SPANNER_INSTANCE, database_id)
53+
snippets.insert_data(SPANNER_INSTANCE, database_id)
5354
database = spanner_instance.database(database_id)
5455
database.reload()
5556
yield database
5657
database.drop()
5758

5859

59-
def test_query_data(cloud_config, temporary_database, capsys):
60-
snippets.query_data(
61-
cloud_config.spanner_instance, temporary_database.database_id)
60+
def test_query_data(temporary_database, capsys):
61+
snippets.query_data(SPANNER_INSTANCE, temporary_database.database_id)
6262

6363
out, _ = capsys.readouterr()
6464

6565
assert 'Total Junk' in out
6666

6767

68-
def test_read_data(cloud_config, temporary_database, capsys):
69-
snippets.read_data(
70-
cloud_config.spanner_instance, temporary_database.database_id)
68+
def test_read_data(temporary_database, capsys):
69+
snippets.read_data(SPANNER_INSTANCE, temporary_database.database_id)
7170

7271
out, _ = capsys.readouterr()
7372

7473
assert 'Total Junk' in out
7574

7675

7776
@pytest.fixture(scope='module')
78-
def temporary_database_with_column(cloud_config, temporary_database):
79-
snippets.add_column(
80-
cloud_config.spanner_instance, temporary_database.database_id)
77+
def temporary_database_with_column(temporary_database):
78+
snippets.add_column(SPANNER_INSTANCE, temporary_database.database_id)
8179
yield temporary_database
8280

8381

84-
def test_update_data(cloud_config, temporary_database_with_column):
82+
def test_update_data(temporary_database_with_column):
8583
snippets.update_data(
86-
cloud_config.spanner_instance,
84+
SPANNER_INSTANCE,
8785
temporary_database_with_column.database_id)
8886

8987

90-
def test_query_data_with_new_column(
91-
cloud_config, temporary_database_with_column, capsys):
88+
def test_query_data_with_new_column(temporary_database_with_column, capsys):
9289
snippets.query_data_with_new_column(
93-
cloud_config.spanner_instance,
90+
SPANNER_INSTANCE,
9491
temporary_database_with_column.database_id)
9592

9693
out, _ = capsys.readouterr()
9794
assert 'MarketingBudget' in out
9895

9996

10097
@pytest.fixture(scope='module')
101-
def temporary_database_with_indexes(
102-
cloud_config, temporary_database_with_column):
98+
def temporary_database_with_indexes(temporary_database_with_column):
10399
snippets.add_index(
104-
cloud_config.spanner_instance,
100+
SPANNER_INSTANCE,
105101
temporary_database_with_column.database_id)
106102
snippets.add_storing_index(
107-
cloud_config.spanner_instance,
103+
SPANNER_INSTANCE,
108104
temporary_database_with_column.database_id)
109105

110106
yield temporary_database_with_column
111107

112108

113109
@pytest.mark.slow
114-
def test_query_data_with_index(
115-
cloud_config, temporary_database_with_indexes, capsys):
110+
def test_query_data_with_index(temporary_database_with_indexes, capsys):
116111
@eventually_consistent.call
117112
def _():
118113
snippets.query_data_with_index(
119-
cloud_config.spanner_instance,
114+
SPANNER_INSTANCE,
120115
temporary_database_with_indexes.database_id)
121116

122117
out, _ = capsys.readouterr()
123118
assert 'Go, Go, Go' in out
124119

125120

126121
@pytest.mark.slow
127-
def test_read_data_with_index(
128-
cloud_config, temporary_database_with_indexes, capsys):
122+
def test_read_data_with_index(temporary_database_with_indexes, capsys):
129123
@eventually_consistent.call
130124
def _():
131125
snippets.read_data_with_index(
132-
cloud_config.spanner_instance,
126+
SPANNER_INSTANCE,
133127
temporary_database_with_indexes.database_id)
134128

135129
out, _ = capsys.readouterr()
136130
assert 'Go, Go, Go' in out
137131

138132

139133
@pytest.mark.slow
140-
def test_read_data_with_storing_index(
141-
cloud_config, temporary_database_with_indexes, capsys):
134+
def test_read_data_with_storing_index(temporary_database_with_indexes, capsys):
142135
@eventually_consistent.call
143136
def _():
144137
snippets.read_data_with_storing_index(
145-
cloud_config.spanner_instance,
138+
SPANNER_INSTANCE,
146139
temporary_database_with_indexes.database_id)
147140

148141
out, _ = capsys.readouterr()
149142
assert 'Go, Go, Go' in out
150143

151144

152145
@pytest.mark.slow
153-
def test_read_write_transaction(
154-
cloud_config, temporary_database_with_column, capsys):
146+
def test_read_write_transaction(temporary_database_with_column, capsys):
155147
@eventually_consistent.call
156148
def _():
157149
snippets.update_data(
158-
cloud_config.spanner_instance,
150+
SPANNER_INSTANCE,
159151
temporary_database_with_column.database_id)
160152
snippets.read_write_transaction(
161-
cloud_config.spanner_instance,
153+
SPANNER_INSTANCE,
162154
temporary_database_with_column.database_id)
163155

164156
out, _ = capsys.readouterr()
@@ -167,12 +159,11 @@ def _():
167159

168160

169161
@pytest.mark.slow
170-
def test_read_only_transaction(
171-
cloud_config, temporary_database, capsys):
162+
def test_read_only_transaction(temporary_database, capsys):
172163
@eventually_consistent.call
173164
def _():
174165
snippets.read_only_transaction(
175-
cloud_config.spanner_instance,
166+
SPANNER_INSTANCE,
176167
temporary_database.database_id)
177168

178169
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)