12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import os
15
16
import random
16
17
import string
17
18
21
22
22
23
import snippets
23
24
25
+ SPANNER_INSTANCE = os .environ ['SPANNER_INSTANCE' ]
26
+
24
27
25
28
@pytest .fixture (scope = 'module' )
26
- def spanner_instance (cloud_config ):
29
+ def spanner_instance ():
27
30
spanner_client = spanner .Client ()
28
- return spanner_client .instance (cloud_config . spanner_instance )
31
+ return spanner_client .instance (SPANNER_INSTANCE )
29
32
30
33
31
34
def unique_database_id ():
32
35
return 'test-db-{}' .format ('' .join (random .choice (
33
36
string .ascii_lowercase + string .digits ) for _ in range (5 )))
34
37
35
38
36
- def test_create_database (cloud_config , spanner_instance ):
39
+ def test_create_database (spanner_instance ):
37
40
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 )
41
43
42
44
database = spanner_instance .database (database_id )
43
45
database .reload () # Will only succeed if the database exists.
44
46
database .drop ()
45
47
46
48
47
49
@pytest .fixture (scope = 'module' )
48
- def temporary_database (cloud_config , spanner_instance ):
50
+ def temporary_database (spanner_instance ):
49
51
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 )
53
54
database = spanner_instance .database (database_id )
54
55
database .reload ()
55
56
yield database
56
57
database .drop ()
57
58
58
59
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 )
62
62
63
63
out , _ = capsys .readouterr ()
64
64
65
65
assert 'Total Junk' in out
66
66
67
67
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 )
71
70
72
71
out , _ = capsys .readouterr ()
73
72
74
73
assert 'Total Junk' in out
75
74
76
75
77
76
@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 )
81
79
yield temporary_database
82
80
83
81
84
- def test_update_data (cloud_config , temporary_database_with_column ):
82
+ def test_update_data (temporary_database_with_column ):
85
83
snippets .update_data (
86
- cloud_config . spanner_instance ,
84
+ SPANNER_INSTANCE ,
87
85
temporary_database_with_column .database_id )
88
86
89
87
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 ):
92
89
snippets .query_data_with_new_column (
93
- cloud_config . spanner_instance ,
90
+ SPANNER_INSTANCE ,
94
91
temporary_database_with_column .database_id )
95
92
96
93
out , _ = capsys .readouterr ()
97
94
assert 'MarketingBudget' in out
98
95
99
96
100
97
@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 ):
103
99
snippets .add_index (
104
- cloud_config . spanner_instance ,
100
+ SPANNER_INSTANCE ,
105
101
temporary_database_with_column .database_id )
106
102
snippets .add_storing_index (
107
- cloud_config . spanner_instance ,
103
+ SPANNER_INSTANCE ,
108
104
temporary_database_with_column .database_id )
109
105
110
106
yield temporary_database_with_column
111
107
112
108
113
109
@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 ):
116
111
@eventually_consistent .call
117
112
def _ ():
118
113
snippets .query_data_with_index (
119
- cloud_config . spanner_instance ,
114
+ SPANNER_INSTANCE ,
120
115
temporary_database_with_indexes .database_id )
121
116
122
117
out , _ = capsys .readouterr ()
123
118
assert 'Go, Go, Go' in out
124
119
125
120
126
121
@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 ):
129
123
@eventually_consistent .call
130
124
def _ ():
131
125
snippets .read_data_with_index (
132
- cloud_config . spanner_instance ,
126
+ SPANNER_INSTANCE ,
133
127
temporary_database_with_indexes .database_id )
134
128
135
129
out , _ = capsys .readouterr ()
136
130
assert 'Go, Go, Go' in out
137
131
138
132
139
133
@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 ):
142
135
@eventually_consistent .call
143
136
def _ ():
144
137
snippets .read_data_with_storing_index (
145
- cloud_config . spanner_instance ,
138
+ SPANNER_INSTANCE ,
146
139
temporary_database_with_indexes .database_id )
147
140
148
141
out , _ = capsys .readouterr ()
149
142
assert 'Go, Go, Go' in out
150
143
151
144
152
145
@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 ):
155
147
@eventually_consistent .call
156
148
def _ ():
157
149
snippets .update_data (
158
- cloud_config . spanner_instance ,
150
+ SPANNER_INSTANCE ,
159
151
temporary_database_with_column .database_id )
160
152
snippets .read_write_transaction (
161
- cloud_config . spanner_instance ,
153
+ SPANNER_INSTANCE ,
162
154
temporary_database_with_column .database_id )
163
155
164
156
out , _ = capsys .readouterr ()
@@ -167,12 +159,11 @@ def _():
167
159
168
160
169
161
@pytest .mark .slow
170
- def test_read_only_transaction (
171
- cloud_config , temporary_database , capsys ):
162
+ def test_read_only_transaction (temporary_database , capsys ):
172
163
@eventually_consistent .call
173
164
def _ ():
174
165
snippets .read_only_transaction (
175
- cloud_config . spanner_instance ,
166
+ SPANNER_INSTANCE ,
176
167
temporary_database .database_id )
177
168
178
169
out , _ = capsys .readouterr ()
0 commit comments