Skip to content

Commit f439f4b

Browse files
Jon Wayne Parrottdandhlee
Jon Wayne Parrott
authored andcommitted
Remove cloud config fixture [(#887)](#887)
* Remove cloud config fixture * Fix client secrets * Fix bigtable instance
1 parent 471ac35 commit f439f4b

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

kms/snippets/snippets_test.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515

16+
import os
1617
import random
1718
import string
1819

1920
import googleapiclient.discovery
2021

2122
import snippets
2223

24+
PROJECT = os.environ['GCLOUD_PROJECT']
2325

2426
# Your Google Cloud Platform Key Location
2527
LOCATION = 'global'
@@ -42,25 +44,25 @@
4244
ROLE = 'roles/owner'
4345

4446

45-
def test_create_keyring(capsys, cloud_config):
46-
snippets.create_keyring(cloud_config.project, LOCATION, KEYRING)
47+
def test_create_keyring(capsys):
48+
snippets.create_keyring(PROJECT, LOCATION, KEYRING)
4749
out, _ = capsys.readouterr()
4850
expected = 'Created KeyRing projects/{}/locations/{}/keyRings/{}.'.format(
49-
cloud_config.project, LOCATION, KEYRING)
51+
PROJECT, LOCATION, KEYRING)
5052
assert expected in out
5153

5254

53-
def test_create_cryptokey(capsys, cloud_config):
55+
def test_create_cryptokey(capsys):
5456
snippets.create_cryptokey(
55-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY)
57+
PROJECT, LOCATION, KEYRING, CRYPTOKEY)
5658
out, _ = capsys.readouterr()
5759
expected = (
5860
'Created CryptoKey projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}.'
59-
.format(cloud_config.project, LOCATION, KEYRING, CRYPTOKEY))
61+
.format(PROJECT, LOCATION, KEYRING, CRYPTOKEY))
6062
assert expected in out
6163

6264

63-
def test_encrypt_decrypt(capsys, cloud_config, tmpdir):
65+
def test_encrypt_decrypt(capsys, tmpdir):
6466
# Write to a plaintext file.
6567
tmpdir.join('in.txt').write('SampleText')
6668

@@ -71,10 +73,10 @@ def test_encrypt_decrypt(capsys, cloud_config, tmpdir):
7173

7274
# Encrypt text and then decrypt it.
7375
snippets.encrypt(
74-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY,
76+
PROJECT, LOCATION, KEYRING, CRYPTOKEY,
7577
str(plaintext_file), str(encrypted_file))
7678
snippets.decrypt(
77-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY,
79+
PROJECT, LOCATION, KEYRING, CRYPTOKEY,
7880
str(encrypted_file), str(decrypted_file))
7981

8082
# Make sure the decrypted text matches the original text.
@@ -87,35 +89,35 @@ def test_encrypt_decrypt(capsys, cloud_config, tmpdir):
8789
assert 'Saved decrypted text to {}.'.format(str(decrypted_file)) in out
8890

8991

90-
def test_disable_cryptokey_version(capsys, cloud_config):
92+
def test_disable_cryptokey_version(capsys):
9193
snippets.disable_cryptokey_version(
92-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY, VERSION)
94+
PROJECT, LOCATION, KEYRING, CRYPTOKEY, VERSION)
9395
out, _ = capsys.readouterr()
9496
expected = (
9597
'CryptoKeyVersion projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}/'
9698
'cryptoKeyVersions/{}\'s state has been set to {}.'
9799
.format(
98-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY, VERSION,
100+
PROJECT, LOCATION, KEYRING, CRYPTOKEY, VERSION,
99101
'DISABLED'))
100102
assert expected in out
101103

102104

103-
def test_destroy_cryptokey_version(capsys, cloud_config):
105+
def test_destroy_cryptokey_version(capsys):
104106
snippets.destroy_cryptokey_version(
105-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY, VERSION)
107+
PROJECT, LOCATION, KEYRING, CRYPTOKEY, VERSION)
106108
out, _ = capsys.readouterr()
107109
expected = (
108110
'CryptoKeyVersion projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}/'
109111
'cryptoKeyVersions/{}\'s state has been set to {}.'
110112
.format(
111-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY, VERSION,
113+
PROJECT, LOCATION, KEYRING, CRYPTOKEY, VERSION,
112114
'DESTROY_SCHEDULED'))
113115
assert expected in out
114116

115117

116-
def test_add_member_to_cryptokey_policy(capsys, cloud_config):
118+
def test_add_member_to_cryptokey_policy(capsys):
117119
snippets.add_member_to_cryptokey_policy(
118-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY, MEMBER, ROLE)
120+
PROJECT, LOCATION, KEYRING, CRYPTOKEY, MEMBER, ROLE)
119121
out, _ = capsys.readouterr()
120122
expected = (
121123
'Member {} added with role {} to policy for CryptoKey {} in KeyRing {}'
@@ -124,7 +126,7 @@ def test_add_member_to_cryptokey_policy(capsys, cloud_config):
124126

125127
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')
126128
parent = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format(
127-
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY)
129+
PROJECT, LOCATION, KEYRING, CRYPTOKEY)
128130
cryptokeys = kms_client.projects().locations().keyRings().cryptoKeys()
129131
policy_request = cryptokeys.getIamPolicy(resource=parent)
130132
policy_response = policy_request.execute()
@@ -139,8 +141,8 @@ def test_add_member_to_cryptokey_policy(capsys, cloud_config):
139141
assert found_member_role_pair
140142

141143

142-
def test_get_keyring_policy(capsys, cloud_config):
143-
project_id = cloud_config.project
144+
def test_get_keyring_policy(capsys):
145+
project_id = PROJECT
144146
snippets.get_keyring_policy(project_id, LOCATION, KEYRING)
145147
out, _ = capsys.readouterr()
146148
expected_roles_exist = (

0 commit comments

Comments
 (0)