Skip to content

Commit be65ecc

Browse files
committed
Added comments and teardown for test.
1 parent 993b90b commit be65ecc

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tests/test_s3.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def test_connection_secure():
5656
@staticmethod
5757
@raises(DataJointError)
5858
def test_remove_object_exception():
59-
#https://github.com/datajoint/datajoint-python/issues/952
59+
# https://github.com/datajoint/datajoint-python/issues/952
60+
6061
# Initialize minioClient with an endpoint and access/secret keys.
6162
minio_client = Minio(
6263
'minio:9000',
@@ -65,8 +66,11 @@ def test_remove_object_exception():
6566
secure=False)
6667

6768
minio_admin = minio.MinioAdmin(target = 'myminio')
69+
70+
# Create new user
6871
minio_admin.user_add(access_key = 'jeffjeff', secret_key = 'jeffjeff')
6972

73+
# json for test policy for permissionless user
7074
testpolicy = {
7175
"Version": "2012-10-17",
7276
"Statement": [
@@ -98,22 +102,33 @@ def test_remove_object_exception():
98102
}
99103
]
100104
}
105+
106+
# Write test json to tmp directory so we can use it to create a new user policy
101107
with open('/tmp/policy.json', 'w') as f:
102108
f.write(json.dumps(testpolicy))
109+
110+
# Add the policy and apply it to the user
103111
minio_admin.policy_add(policy_name = 'test', policy_file = '/tmp/policy.json')
104112
minio_admin.policy_set(policy_name = 'test', user = 'jeffjeff')
105113

106-
114+
# Insert some test data and remove it so that the external table is populated
107115
test = [1,[1,2,3]]
108116
SimpleRemote.insert1(test)
109117
SimpleRemote.delete()
110-
118+
119+
# Save the old external table minio client
120+
old_client = schema.external['share'].s3.client
121+
122+
# Apply our new minio client to the external table that has permissions restrictions
111123
schema.external['share'].s3.client = minio_client
124+
112125
# This method returns a list of errors
113126
error_list = schema.external['share'].delete(delete_external_files = True, errors_as_string = False)
114-
raise error_list[0][2]
115-
116-
117127

118-
128+
# Teardown
129+
minio_admin.user_remove(access_key = 'jeffjeff')
130+
minio_admin.policy_remove('test')
131+
schema.external['share'].s3.client = old_client
119132

133+
# Raise the error we want
134+
raise error_list[0][2]

0 commit comments

Comments
 (0)