File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 21
21
import os
22
22
23
23
from google .cloud import storage
24
+ import google .api_core .exceptions
24
25
import pytest
25
26
26
27
import storage_activate_hmac_key
36
37
STORAGE_CLIENT = storage .Client (project = PROJECT_ID )
37
38
38
39
39
- @pytest .fixture
40
+ @pytest .fixture ( scope = "module" )
40
41
def new_hmac_key ():
41
42
"""
42
43
Fixture to create a new HMAC key, and to guarantee all keys are deleted at
43
- the end of each test.
44
+ the end of the module.
45
+
46
+ NOTE: Due to the module scope, test order in this file is significant
44
47
"""
45
48
hmac_key , secret = STORAGE_CLIENT .create_hmac_key (
46
49
service_account_email = SERVICE_ACCOUNT_EMAIL , project_id = PROJECT_ID
@@ -100,7 +103,13 @@ def test_deactivate_key(capsys, new_hmac_key):
100
103
101
104
102
105
def test_delete_key (capsys , new_hmac_key ):
103
- new_hmac_key .state = "INACTIVE"
104
- new_hmac_key .update ()
106
+ # Due to reuse of the HMAC key for each test function, the previous
107
+ # test has deactivated the key already.
108
+ try :
109
+ new_hmac_key .state = "INACTIVE"
110
+ new_hmac_key .update ()
111
+ except google .api_core .exceptions .BadRequest :
112
+ pass
113
+
105
114
storage_delete_hmac_key .delete_key (new_hmac_key .access_id , PROJECT_ID )
106
115
assert "The key is deleted" in capsys .readouterr ().out
You can’t perform that action at this time.
0 commit comments